The runtests script was improved so that the Java and Ruby test cases don't
[external/ragel.git] / test / langtrans_java.sh
1 #!/bin/bash
2 #
3
4 file=$1
5
6 [ -f $file ] || exit 1
7 root=${file%.rl}
8 class=${root}_java
9
10 # Make a temporary version of the test case using the Java language translations.
11 sed -n '/\/\*/,/\*\//d;p' $file | txl -q stdin langtrans_java.txl - $class > $file.pr
12
13 # Begin writing out the test case.
14 cat << EOF
15 /*
16  * @LANG: java
17  * @GENERATED: yes
18  */
19
20 class $class
21 {
22 EOF
23
24 # Write the data declarations
25 sed -n '/^%%$/q;{s/^/\t/;p}' $file.pr
26
27 # Write out the machine specification.
28 sed -n '/^%%{$/,/^}%%/{s/^/\t/;p}' $file.pr
29
30 # Write out the init and execute routines.
31 cat << EOF
32
33         int cs;
34         %% write data;
35
36         void init()
37         {
38 EOF
39
40 sed -n '0,/^%%$/d; /^%%{$/q; {s/^/\t\t/;p}' $file.pr
41
42 cat << EOF
43                 %% write init;
44         }
45
46         void exec( char data[], int len )
47         {
48                 int p = 0;
49                 int pe = len;
50                 %% write exec;
51         }
52
53         void finish( )
54         {
55                 %% write eof;
56                 if ( cs >= ${class}_first_final )
57                         System.out.println( "ACCEPT" );
58                 else
59                         System.out.println( "FAIL" );
60         }
61
62 EOF
63
64 # Write out the test data.
65 sed -n '0,/\/\* _____INPUT_____/d; /_____INPUT_____ \*\//q; p;' $file | awk '
66 BEGIN {
67         print " static final String inp[] = {"
68 }
69 {
70         print "         " $0 ","
71 }
72 END {
73         print " };"
74         print ""
75         print " static final int inplen = " NR ";"
76 }'
77
78
79 # Write out the main routine.
80 cat << EOF
81
82         public static void main (String[] args)
83         {
84                 $class machine = new $class();
85                 for ( int i = 0; i < inplen; i++ ) {
86                         machine.init();
87                         machine.exec( inp[i].toCharArray(), inp[i].length() );
88                         machine.finish();
89                 }
90         }
91 }
92
93 EOF
94
95 # Write out the expected output.
96 sed -n '/\/\* _____OUTPUT_____/,/_____OUTPUT_____ \*\//p;' $file
97
98 # Don't need this language-specific file anymore.
99 rm $file.pr