package org.fixtrading.orchestra.dsl.antlr;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.junit.BeforeClass;
import org.junit.Test;

public class DslTest {

  private static List<String> fieldConditions = new ArrayList<String>();

  @BeforeClass
  public static void init() {
    fieldConditions.add("this.OrdType");
    fieldConditions.add("\"Stop\"");
    fieldConditions.add("this.OrdType == \"Stop\"");
    fieldConditions.add("this.OrdType in {\"Stop\", \"StopLimit\"}");
  }

  @Test
  public void testExampleFieldCondition() throws Exception {
    for (String fieldCondition : fieldConditions) {
      ScoreLexer l = new ScoreLexer(new ANTLRInputStream(new StringReader(fieldCondition)));
      ScoreParser p = new ScoreParser(new CommonTokenStream(l));
      p.addErrorListener(new BaseErrorListener() {
        @Override
        public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
            int charPositionInLine, String msg, RecognitionException e) {
          throw new IllegalStateException(
              String.format("Failed to parse at line %d position %d due to %s", line,
                  charPositionInLine, msg),
              e);
        }
      });
      p.anyExpression();
    }
  }
}

@@ -89,20 +89,17 @@
 il.Array
-List
+s
 ;%0Aimport
@@ -109,20 +109,26 @@
 va.util.
-List
+Collection
 ;%0A%0Aimpor
@@ -373,98 +373,199 @@
 nit.
-BeforeClass;%0Aimport org.junit.Test;%0A%0Apublic class DslTest %7B%0A%0A  private static List%3C
+Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.Parameterized;%0A%0A@RunWith(Parameterized.class)%0Apublic class DslTest %7B%0A%0A  private String fieldCondition;%0A%0A  public DslTest(
 String
-%3E
  fie
@@ -579,185 +579,242 @@
 tion
-s = new ArrayList%3CString%3E();%0A%0A  @BeforeClass%0A  public static void init() %7B%0A    fieldConditions.add(%22this.OrdType%22);%0A    fieldConditions.add(%22%5C%22Stop%5C%22%22);%0A    fieldConditions.add(
+) %7B%0A    this.fieldCondition = fieldCondition;%0A  %7D%0A%0A  @Parameterized.Parameters%0A  public static Collection%3CString%5B%5D%3E testFieldConditions() %7B%0A    return Arrays.asList(new String%5B%5D%5B%5D %7B%0A      %7B%22this.OrdType%22%7D, %0A      %7B%22%5C%22Stop%5C%22%22%7D,%0A      %7B
 %22thi
@@ -839,35 +839,71 @@
 p%5C%22%22
-);
+%7D,
 %0A    
-fieldConditions.add(
+  %7B%22this.OrdType in %7B%5C%22Stop%5C%22, %5C%22StopLimit%5C%22%7D%22%7D,%0A      %7B
 %22thi
@@ -908,36 +908,35 @@
 his.OrdType 
-in %7B
+== 
 %5C%22Stop%5C%22
 , %5C%22StopLimi
@@ -923,33 +923,194 @@
 %5C%22Stop%5C%22
-, %5C%22StopLimit%5C%22%7D%22
+ or this.OrdType == %5C%22StopLimit%5C%22%22%7D,%0A      %7B%22this.OrdQty %3E 0%22%7D,%0A      %7B%22this.OrdQty != 0%22%7D,%0A      %7B%22this.OrdQty %3E 0 and this.OrdQty %3C= 10%22%7D,%0A      %7B%22this.Price %3C 100.00%22%7D,%0A     %7D
 );%0A  %7D%0A%0A
@@ -1182,62 +1182,8 @@
 n %7B%0A
-    for (String fieldCondition : fieldConditions) %7B%0A  
     
@@ -1265,26 +1265,24 @@
 ndition)));%0A
-  
     ScorePar
@@ -1336,18 +1336,16 @@
 ));%0A    
-  
 p.addErr
@@ -1387,18 +1387,16 @@
 %7B%0A      
-  
 @Overrid
@@ -1397,18 +1397,16 @@
 verride%0A
-  
       pu
@@ -1500,18 +1500,16 @@
         
-  
 int char
@@ -1570,18 +1570,16 @@
         
-  
 throw ne
@@ -1602,31 +1602,16 @@
 ception(
-%0A              
 String.f
@@ -1616,16 +1616,29 @@
 .format(
+%0A            
 %22Failed 
@@ -1690,26 +1690,8 @@
 ine,
-%0A                 
  cha
@@ -1716,22 +1716,8 @@
 sg),
-%0A             
  e);
@@ -1727,22 +1727,18 @@
     
-  
 %7D%0A
-  
     %7D);%0A
     
@@ -1733,18 +1733,16 @@
     %7D);%0A
-  
     p.an
@@ -1756,20 +1756,14 @@
 sion();%0A
-    %7D%0A
   %7D%0A%7D%0A

Change unit test to run each expression individually