Search in sources :

Example 61 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testSubtractOfWackyRange.

/** The following was broken:
	 	{0..113, 115..65534}-{0..115, 117..65534}=116..65534
	 */
@Test
public void testSubtractOfWackyRange() throws Exception {
    IntervalSet s = IntervalSet.of(0, 113);
    s.add(115, 200);
    IntervalSet s2 = IntervalSet.of(0, 115);
    s2.add(117, 200);
    String expecting = "116";
    String result = (s.subtract(s2)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 62 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testEquals.

@Test
public void testEquals() throws Exception {
    IntervalSet s = IntervalSet.of(10, 20);
    s.add(2);
    s.add(499, 501);
    IntervalSet s2 = IntervalSet.of(10, 20);
    s2.add(2);
    s2.add(499, 501);
    assertEquals(s, s2);
    IntervalSet s3 = IntervalSet.of(10, 20);
    s3.add(2);
    assertFalse(s.equals(s3));
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 63 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testMergeWhereAdditionMergesTwoExistingIntervals.

@Test
public void testMergeWhereAdditionMergesTwoExistingIntervals() throws Exception {
    // 42, 10, {0..9, 11..41, 43..65534}
    IntervalSet s = IntervalSet.of(42);
    s.add(10);
    s.add(0, 9);
    s.add(43, 65534);
    s.add(11, 41);
    String expecting = "{0..65534}";
    String result = s.toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 64 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testMergeOfRangesAndSingleValues.

@Test
public void testMergeOfRangesAndSingleValues() throws Exception {
    // {0..41, 42, 43..65534}
    IntervalSet s = IntervalSet.of(0, 41);
    s.add(42);
    s.add(43, 65534);
    String expecting = "{0..65534}";
    String result = s.toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 65 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testSingleElement.

@Test
public void testSingleElement() throws Exception {
    IntervalSet s = IntervalSet.of(99);
    String expecting = "99";
    assertEquals(s.toString(), expecting);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Aggregations

IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)84 Test (org.junit.Test)48 ATNState (org.antlr.v4.runtime.atn.ATNState)11 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)10 ATN (org.antlr.v4.runtime.atn.ATN)8 ArrayList (java.util.ArrayList)7 Grammar (org.antlr.v4.tool.Grammar)7 Interval (org.antlr.v4.runtime.misc.Interval)6 SetTransition (org.antlr.v4.runtime.atn.SetTransition)5 UnicodeSet (com.ibm.icu.text.UnicodeSet)4 HashMap (java.util.HashMap)4 Token (org.antlr.runtime.Token)4 NotSetTransition (org.antlr.v4.runtime.atn.NotSetTransition)4 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)4 LinkedHashMap (java.util.LinkedHashMap)3 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)3 AtomTransition (org.antlr.v4.runtime.atn.AtomTransition)3 DecisionState (org.antlr.v4.runtime.atn.DecisionState)3 RuleTransition (org.antlr.v4.runtime.atn.RuleTransition)3 Transition (org.antlr.v4.runtime.atn.Transition)3