package org.spoofax.jsglr2.integrationtest.grammars;

import org.junit.Test;
import org.spoofax.jsglr2.incremental.EditorUpdate;
import org.spoofax.jsglr2.integrationtest.BaseTestWithSdf3ParseTables;
import org.spoofax.terms.ParseError;

public class ExpPrioritiesTest extends BaseTestWithSdf3ParseTables {

    public ExpPrioritiesTest() {
        super("exp-priorities.sdf3");
    }

    @Test public void oneTerm() throws ParseError {
        testSuccessByExpansions("x", "Term()");
    }

    @Test public void onePlus() throws ParseError {
        testSuccessByExpansions("x+x", "Add(Term(),Term())");
    }

    @Test public void oneMult() throws ParseError {
        testSuccessByExpansions("x*x", "Mult(Term(),Term())");
    }

    @Test public void twoPlus() throws ParseError {
        testSuccessByExpansions("x+x+x", "Add(Add(Term(),Term()),Term())");
    }

    @Test public void multPlus() throws ParseError {
        testSuccessByExpansions("x*x+x", "Add(Mult(Term(),Term()),Term())");
    }

    @Test public void plusMult() throws ParseError {
        testSuccessByExpansions("x+x*x", "Add(Term(),Mult(Term(),Term()))");
    }

    @Test public void twoMult() throws ParseError {
        testSuccessByExpansions("x*x*x", "Mult(Mult(Term(),Term()),Term())");
    }

    @Test public void changingPriorities() {
        testIncrementalSuccessByExpansions("x+x+x",
                new EditorUpdate[] { new EditorUpdate(1, 2, "*"), new EditorUpdate(3, 4, "*"), new EditorUpdate(1, 2, "+"),
                        new EditorUpdate(3, 4, "+") },
                new String[] { "Add(Add(Term(),Term()),Term())", "Add(Mult(Term(),Term()),Term())",
                        "Mult(Mult(Term(),Term()),Term())", "Add(Term(),Mult(Term(),Term()))",
                        "Add(Add(Term(),Term()),Term())" });
    }

}

@@ -1316,24 +1316,50 @@
 orities() %7B%0A
+        // @formatter:off%0A
         test
@@ -1402,36 +1402,32 @@
 x%22,%0A            
-    
 new EditorUpdate
@@ -1430,16 +1430,32 @@
 date%5B%5D %7B
+%0A               
  new Edi
@@ -1471,24 +1471,40 @@
 (1, 2, %22*%22),
+%0A               
  new EditorU
@@ -1520,16 +1520,32 @@
 4, %22*%22),
+%0A               
  new Edi
@@ -1578,32 +1578,24 @@
             
-        
 new EditorUp
@@ -1613,16 +1613,24 @@
 %22+%22)
- %7D,%0A
+%0A        
     
+%7D,%0A
     
@@ -1651,16 +1651,32 @@
 ring%5B%5D %7B
+%0A               
  %22Add(Ad
@@ -1697,24 +1697,40 @@
 )),Term())%22,
+%0A               
  %22Add(Mult(T
@@ -1769,24 +1769,16 @@
         
-       
- 
 %22Mult(Mu
@@ -1804,16 +1804,32 @@
 erm())%22,
+%0A               
  %22Add(Te
@@ -1868,32 +1868,24 @@
             
-        
 %22Add(Add(Ter
@@ -1908,12 +1908,49 @@
 ())%22
- %7D);
+%0A            %7D);%0A        // @formatter:on
 %0A   

Change formatting of incremental changingPriorities test