Search in sources :

Example 6 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_removeByObject.

public void test_removeByObject() {
    ITextRegion[] regions = new ITextRegion[3];
    TextRegionListImpl impl = new TextRegionListImpl();
    boolean added = impl.add(regions[0] = new ContextRegion(REGION_TYPE, 0, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 1, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    added = impl.add(regions[1] = new ContextRegion(REGION_TYPE, 1, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 2, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    added = impl.add(regions[2] = new ContextRegion(REGION_TYPE, 2, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 3, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    assertEquals("wrong object", 0, impl.indexOf(regions[0]));
    assertEquals("wrong object", 1, impl.indexOf(regions[1]));
    assertEquals("wrong object", 2, impl.indexOf(regions[2]));
    impl.remove(regions[1]);
    Iterator it = null;
    assertNotNull("no iterator returned", it = (Iterator) new Accessor(impl, TextRegionListImpl.class).invoke("iterator", new Object[0]));
    assertTrue(it.hasNext());
    assertEquals(regions[0], it.next());
    assertEquals(regions[2], it.next());
    assertFalse(it.hasNext());
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion) Accessor(org.eclipse.wst.sse.core.tests.util.Accessor)

Example 7 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_toArray.

public void test_toArray() {
    ITextRegion[] regions = new ITextRegion[3];
    TextRegionListImpl impl = new TextRegionListImpl();
    boolean added = impl.add(regions[0] = new ContextRegion(REGION_TYPE, 0, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 1, impl.size());
    added = impl.add(regions[1] = new ContextRegion(REGION_TYPE, 1, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 2, impl.size());
    added = impl.add(regions[2] = new ContextRegion(REGION_TYPE, 2, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 3, impl.size());
    assertEquals("wrong object", 0, impl.indexOf(regions[0]));
    assertEquals("wrong object", 1, impl.indexOf(regions[1]));
    assertEquals("wrong object", 2, impl.indexOf(regions[2]));
    assertTrue("wrong array", Arrays.equals(regions, impl.toArray()));
    impl.remove(regions[1]);
    assertTrue("wrong array", Arrays.equals(new ITextRegion[] { regions[0], regions[2] }, impl.toArray()));
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion)

Example 8 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_getUnder.

public void test_getUnder() {
    ITextRegion[] regions = new ITextRegion[3];
    TextRegionListImpl impl = new TextRegionListImpl();
    boolean added = impl.add(regions[0] = new ContextRegion(REGION_TYPE, 0, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 1, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    added = impl.add(regions[1] = new ContextRegion(REGION_TYPE, 1, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 2, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    added = impl.add(regions[2] = new ContextRegion(REGION_TYPE, 2, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 3, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    assertEquals("wrong object", regions[0], impl.get(0));
    assertEquals("wrong object", regions[1], impl.get(1));
    assertEquals("wrong object", regions[2], impl.get(2));
    ArrayIndexOutOfBoundsException e = null;
    try {
        impl.get(-1);
    } catch (ArrayIndexOutOfBoundsException e2) {
        e = e2;
    }
    assertNotNull("no ArrayIndexOutOfBoundsException thrown when expected", e);
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion) Accessor(org.eclipse.wst.sse.core.tests.util.Accessor)

Example 9 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_iterator2.

public void test_iterator2() {
    TextRegionListImpl impl = new TextRegionListImpl();
    boolean added = impl.add(new ContextRegion(REGION_TYPE, 0, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 1, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    added = impl.add(new ContextRegion(REGION_TYPE, 1, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 2, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    added = impl.add(new ContextRegion(REGION_TYPE, 2, 1, 1));
    assertTrue("region not added", added);
    assertEquals("count was wrong", 3, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    Iterator it = null;
    assertNotNull("no iterator returned", it = (Iterator) new Accessor(impl, TextRegionListImpl.class).invoke("iterator", new Object[0]));
    assertTrue(it.hasNext());
    assertNotNull(it.next());
    assertNotNull(it.next());
    assertNotNull(it.next());
    assertFalse(it.hasNext());
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) Iterator(java.util.Iterator) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion) Accessor(org.eclipse.wst.sse.core.tests.util.Accessor)

Example 10 with TextRegionListImpl

use of org.eclipse.wst.sse.core.internal.text.TextRegionListImpl in project webtools.sourceediting by eclipse.

the class TestRegionList method test_addAllToPosition.

public void test_addAllToPosition() {
    ITextRegion[] regions = new ITextRegion[3];
    TextRegionListImpl impl = new TextRegionListImpl();
    boolean added = impl.add(regions[0] = new ContextRegion(REGION_TYPE, 0, 1, 1));
    assertTrue("region not added", added);
    TextRegionListImpl impl2 = new TextRegionListImpl();
    added = impl2.add(regions[1] = new ContextRegion(REGION_TYPE, 1, 1, 1));
    assertTrue("region not added", added);
    added = impl2.add(regions[2] = new ContextRegion(REGION_TYPE, 2, 1, 1));
    assertTrue("region not added", added);
    added = impl.addAll(0, impl2);
    assertTrue("regions not added", added);
    assertEquals("count was wrong", 3, new Accessor(impl, TextRegionListImpl.class).getInt("fRegionsCount"));
    assertEquals("object was wrong", regions[1], ((ITextRegion[]) new Accessor(impl, TextRegionListImpl.class).get("fRegions"))[0]);
    assertEquals("object was wrong", regions[2], ((ITextRegion[]) new Accessor(impl, TextRegionListImpl.class).get("fRegions"))[1]);
    assertEquals("object was wrong", regions[0], ((ITextRegion[]) new Accessor(impl, TextRegionListImpl.class).get("fRegions"))[2]);
}
Also used : TextRegionListImpl(org.eclipse.wst.sse.core.internal.text.TextRegionListImpl) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion) Accessor(org.eclipse.wst.sse.core.tests.util.Accessor)

Aggregations

TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)30 ContextRegion (org.eclipse.wst.sse.core.internal.parser.ContextRegion)19 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)19 Accessor (org.eclipse.wst.sse.core.tests.util.Accessor)18 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)10 Iterator (java.util.Iterator)6 ICSSRuleContainer (org.eclipse.wst.css.core.internal.provisional.document.ICSSRuleContainer)5 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CSSSourceParser (org.eclipse.wst.css.core.internal.parser.CSSSourceParser)1 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 DOMException (org.w3c.dom.DOMException)1