// ConvertTest.java

package ed.js.engine;

import java.io.*;

import ed.*;
import ed.js.*;
import ed.js.func.*;
import ed.io.*;

public class ConvertTest {

    public static class FileTest extends TestCase {
        FileTest( File f ){
            super( f.toString() );
            _file = f;
        }

        public void test()
            throws IOException {
            Convert c = new Convert( _file );

            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            final PrintStream out = new PrintStream( bout );
            
            JSFunction f = c.get();

            JSFunction myout = new JSFunctionCalls1(){
                    public Object call( Scope scope ,Object o , Object extra[] ){
                        out.println( o );
                        return null;
                    }
                };
            
            Scope scope = Scope.GLOBAL.child();
            scope.put( "print" , myout , true );
            scope.put( "SYSOUT" , myout , true );

            f.call( scope );


            String outString = _clean( bout.toString() );
            
            File correct = new File( _file.toString().replaceAll( ".js$" , ".out" ) );
            if ( ! correct.exists() ){
                assertTrue( correct.exists() );
            }
            String correctOut = _clean( StreamUtil.readFully( correct ) );
            
            try {
                assertClose( correctOut , outString );
            }
            catch ( MyAssert a ){
                System.out.println();
                System.out.println( correctOut.replaceAll( "[\r\n ]+" , " " ) );
                System.out.println( outString.replaceAll( "[\r\n ]+" , " " ) );
                throw a;
            }
        }
        
        final File _file;
    }

    static String _clean( String s ){
        s = s.replaceAll( "tempFunc_\\d+_" , "tempFunc_" );
        return s;
    }
    
    public static void main( String args[] ){
        if ( args.length > 0 ){
            TestCase all = new TestCase();
            for ( String s : args )
                all.add( new FileTest( new File( s ) ) );
            all.runConsole();
        }
    }
}

@@ -148,17 +148,275 @@
 ertTest 
-%7B
+extends TestCase %7B%0A%0A    public ConvertTest()%7B%0A        %0A        File dir = new File( %22src/test/ed/js/engine/%22 );%0A        for ( File f : dir.listFiles() )%0A            if ( f.toString().endsWith( %22.js%22 ) )%0A                add( new FileTest( f ) );%0A        %0A    %7D
 %0A%0A    pu
@@ -2431,20 +2431,122 @@
 ;%0A        %7D%0A
+        else %7B%0A            ConvertTest ct = new ConvertTest();%0A            ct.runConsole();%0A        %7D%0A
     %7D%0A%7D%0A

make it a TestCase