<?xml version='1.0' encoding='ISO-8859-1' ?>

<!--

Copyright (c) 2007, Paul Cager
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.

-->

<project name="test-javafiles" default="test-javafile-contents" basedir=".">

  <condition property="is-windows" value="true">
      <os family="windows" />
  </condition>

  <!--
  https://github.com/javacc/javacc/issues/116
  JavaCC puts "OriginalChecksum" for some reason into the generated files,
  so the test does not work on Windows (because expected files have LF-based checksums).
  -->

  <target name="test-javafile-contents" depends="" description="run boiler-plate test cases" unless="${is-windows}">
    <antcall target="test-static" />
    <antcall target="test-non-static" />
    <antcall target="test-no-keep-line" />
    <antcall target="test-not-public" />
    <antcall target="test-generator" />
  </target>

  <target name="test-static">

    <echo>Static Parser</echo>

    <antcall target="reset" />
    <java failonerror="true" fork="true" classname="javacc" classpath="../../target/javacc.jar">
      <arg line="-STATIC" />
      <arg line="Parser.jj" />
    </java>

    <fail message="Static ParseException">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/ParseException.java" file2="expected/static/ParseException.java" /> </not>
     </condition>
    </fail>

    <fail message="Static ParserTokenManager">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/ParserTokenManager.java" file2="expected/static/ParserTokenManager.java" /> </not>
     </condition>
    </fail>

    <fail message="Static SimpleCharStream">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/SimpleCharStream.java" file2="expected/static/SimpleCharStream.java" /> </not>
     </condition>
    </fail>

    <fail message="Static Token">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/Token.java" file2="expected/static/Token.java" /> </not>
     </condition>
    </fail>

    <fail message="Static TokenMgrError">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/TokenMgrError.java" file2="expected/static/TokenMgrError.java" /> </not>
     </condition>
    </fail>
  </target>

  <target name="test-non-static">

    <echo>Non-static Parser</echo>

    <antcall target="reset" />
    <java failonerror="true" fork="true" classname="javacc" classpath="../../target/javacc.jar">
      <arg line="-NOSTATIC" />
      <arg line="Parser.jj" />
    </java>

    <fail message="Non-Static ParseException">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/ParseException.java" file2="expected/non-static/ParseException.java" /> </not>
     </condition>
    </fail>

    <fail message="Non-Static ParserTokenManager">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/ParserTokenManager.java" file2="expected/non-static/ParserTokenManager.java" /> </not>
     </condition>
    </fail>

    <fail message="Non-Static SimpleCharStream">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/SimpleCharStream.java" file2="expected/non-static/SimpleCharStream.java" /> </not>
     </condition>
    </fail>

    <fail message="Non-Static Token">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/Token.java" file2="expected/non-static/Token.java" /> </not>
     </condition>
    </fail>

    <fail message="Non-Static TokenMgrError">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/TokenMgrError.java" file2="expected/non-static/TokenMgrError.java" /> </not>
     </condition>
    </fail>
  </target>


  <target name="test-no-keep-line">

    <echo>No-Keep-Line Parser</echo>

    <antcall target="reset" />
    <java failonerror="true" fork="true" classname="javacc" classpath="../../target/javacc.jar">
      <arg line="-NOKEEP_LINE_COLUMN" />
      <arg line="Parser.jj" />
    </java>

    <fail message="No-Keep_line ParseException">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/ParseException.java" file2="expected/no-keep-line/ParseException.java" /> </not>
     </condition>
    </fail>

    <fail message="No-Keep_line ParserTokenManager">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/ParserTokenManager.java" file2="expected/no-keep-line/ParserTokenManager.java" /> </not>
     </condition>
    </fail>

    <fail message="No-Keep_line SimpleCharStream">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/SimpleCharStream.java" file2="expected/no-keep-line/SimpleCharStream.java" /> </not>
     </condition>
    </fail>

    <fail message="No-Keep_line Token">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/Token.java" file2="expected/no-keep-line/Token.java" /> </not>
     </condition>
    </fail>

    <fail message="No-Keep_line TokenMgrError">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/TokenMgrError.java" file2="expected/no-keep-line/TokenMgrError.java" /> </not>
     </condition>
    </fail>
  </target>

  <target name="test-not-public">

    <echo>Not Public</echo>

    <antcall target="reset" />
    <java failonerror="true" fork="true" classname="javacc" classpath="../../target/javacc.jar">
      <arg line="-SUPPORT_CLASS_VISIBILITY_PUBLIC=false" />
      <arg line="Parser.jj" />
    </java>

    <fail message="Not-Public ParseException">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/ParseException.java" file2="expected/not-public/ParseException.java" /> </not>
     </condition>
    </fail>

    <fail message="Not-Public ParserTokenManager">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/ParserTokenManager.java" file2="expected/not-public/ParserTokenManager.java" /> </not>
     </condition>
    </fail>

    <fail message="Not-Public SimpleCharStream">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/SimpleCharStream.java" file2="expected/not-public/SimpleCharStream.java" /> </not>
     </condition>
    </fail>

    <fail message="Not-Public Token">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/Token.java" file2="expected/not-public/Token.java" /> </not>
     </condition>
    </fail>

    <fail message="Not-Public TokenMgrError">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/TokenMgrError.java" file2="expected/not-public/TokenMgrError.java" /> </not>
     </condition>
    </fail>
  </target>

  <target name="test-generator">
    <echo>test-generator</echo>

    <antcall target="reset" />
    <java failonerror="true" fork="true" classname="org.javacc.utils.OutputFileGenerator" classpath=".:../../target/javacc.jar">
      <arg line="/template.txt" />
      <arg line="out-dir/generated.txt" />
    </java>

    <fail message="test-generator">
     <condition>
        <not> <filesmatch textfile="true" file1="out-dir/generated.txt" file2="expected/generated.txt" /> </not>
     </condition>
    </fail>

  </target>

  <target name="reset">
    <delete dir="out-dir" />
    <mkdir dir="out-dir" />
  </target>

  <target name="clean">
    <delete dir="out-dir" />
  </target>

</project>
