Search in sources :

Example 56 with IntervalSet

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

the class TestIntervalSet method testRmLeftSide.

@Test
public void testRmLeftSide() throws Exception {
    IntervalSet s = IntervalSet.of(1, 10);
    s.add(-3, -3);
    s.remove(1);
    String expecting = "{-3, 2..10}";
    String result = s.toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 57 with IntervalSet

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

the class TestIntervalSet method testIsolatedElements.

@Test
public void testIsolatedElements() throws Exception {
    IntervalSet s = new IntervalSet();
    s.add(1);
    s.add('z');
    s.add('￰');
    String expecting = "{1, 122, 65520}";
    assertEquals(s.toString(), expecting);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 58 with IntervalSet

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

the class TestIntervalSet method testIntersectionWithTwoContainedElements.

// {2,15,18} & 10..20
@Test
public void testIntersectionWithTwoContainedElements() throws Exception {
    IntervalSet s = IntervalSet.of(10, 20);
    IntervalSet s2 = IntervalSet.of(2, 2);
    s2.add(15);
    s2.add(18);
    String expecting = "{15, 18}";
    String result = (s.and(s2)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 59 with IntervalSet

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

the class TestIntervalSet method testSubtractOfOverlappingRangeFromLeft.

@Test
public void testSubtractOfOverlappingRangeFromLeft() throws Exception {
    IntervalSet s = IntervalSet.of(10, 20);
    IntervalSet s2 = IntervalSet.of(5, 11);
    String expecting = "{12..20}";
    String result = (s.subtract(s2)).toString();
    assertEquals(expecting, result);
    IntervalSet s3 = IntervalSet.of(5, 10);
    expecting = "{11..20}";
    result = (s.subtract(s3)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 60 with IntervalSet

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

the class TestIntervalSet method testMergeOfRangesAndSingleValuesReverse.

@Test
public void testMergeOfRangesAndSingleValuesReverse() throws Exception {
    IntervalSet s = IntervalSet.of(43, 65534);
    s.add(42);
    s.add(0, 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)

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