/*
 *  wssccc all rights reserved
 */
package org.ngscript;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;

/**
 *
 * @author wssccc <wssccc@qq.com>
 */
@Slf4j
public class ConformanceTest {

    @Test
    public void doTest() throws Exception {
        Configuration.DEFAULT.setGenerateDebugInfo(false);
        Configuration.DEFAULT.setInteractive(false);
        testExamples();
        Configuration.DEFAULT.setInteractive(true);
        testExamples();
    }

    public void testExamples() throws Exception {
        try {
            //
            File folder = new File("src/test/ngscript/tc");
            File[] files = folder.listFiles();
            for (File file : files) {
                if (file.isFile()) {
                    System.out.println("Testing " + file);
                    try {
                        new Ngscript().eval(IOUtils.toString(new FileInputStream(file), StandardCharsets.UTF_8));
                    } catch (Exception ex) {
                        System.out.println("Failed while testing " + file);
                        throw ex;
                    }
                }
            }
        } catch (Exception ex) {
            log.error("error", ex);
            throw ex;
        }
    }
}

@@ -244,16 +244,42 @@
 harsets;
+%0Aimport java.util.Scanner;
 %0A%0A/**%0A *
@@ -414,310 +414,8 @@
 n %7B%0A
-        Configuration.DEFAULT.setGenerateDebugInfo(false);%0A        Configuration.DEFAULT.setInteractive(false);%0A        testExamples();%0A        Configuration.DEFAULT.setInteractive(true);%0A        testExamples();%0A    %7D%0A%0A    public void testExamples() throws Exception %7B%0A        try %7B%0A            //%0A    
     
@@ -470,28 +470,24 @@
 %22);%0A        
- 
-   
 File%5B%5D files
@@ -515,22 +515,48 @@
 ;%0A      
+  assert files != null;%0A
       
+  
 for (Fil
@@ -585,20 +585,16 @@
         
-    
 if (file
@@ -602,28 +602,24 @@
 isFile()) %7B%0A
-    
             
@@ -681,17 +681,76 @@
     
-    try %7B
+testEval(file);%0A                testInteractive(file);%0A            %7D
 %0A   
@@ -750,32 +750,81 @@
   %7D%0A        
+%7D%0A
     
+%7D%0A%0A
     
+void testEval(File file) throws Exception %7B%0A
         new 
@@ -917,123 +917,125 @@
     
-                %7D catch (Exception ex) %7B%0A                        System.out.println(%22Failed while testing %22 + 
+%7D%0A%0A    void testInteractive(File file) throws Exception %7B%0A        Scanner sc = new Scanner(new FileInputStream(
 file)
+)
 ;%0A  
@@ -1044,177 +1044,267 @@
     
-                throw ex;%0A                    %7D%0A                %7D%0A            %7D%0A        %7D catch (Exception ex) %7B%0A            log.error(%22error%22, ex);%0A            throw ex
+Configuration configuration = new Configuration();%0A        configuration.setInteractive(true);%0A        Ngscript ngscript = new Ngscript(configuration);%0A        while (sc.hasNextLine()) %7B%0A            String line = sc.nextLine();%0A            ngscript.eval(line)
 ;%0A  

update test