public void testTextMatcherWithoutShift() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i * 2 + 1, r.getStart()); assertEquals(i * 2 + 2, r.getEnd()); } assertNull(it.next()); }
public void testElementMatcherWithRestrictions() { String xml = "text <image attachment=\"nR_0YFT75\" style=\"full\">" + "<caption>good times</caption></image> hello"; ApiView apiView = createApiViewFromXml(xml); Map<String, String> restrictions = Maps.newHashMap(); assertEquals(1, countHits(new DocumentHitIterator.ElementMatcher( apiView, ElementType.ATTACHMENT, Collections.<String, String>emptyMap(), -1))); Restriction restriction = Attachment.restrictByAttachmentId("nR_0YFT75"); assertEquals(1, countHits(new DocumentHitIterator.ElementMatcher(apiView, ElementType.ATTACHMENT, ImmutableMap.of(restriction.getKey(), restriction.getValue()), -1))); restriction = Attachment.restrictByAttachmentId("nR_0YFT76"); assertEquals(0, countHits(new DocumentHitIterator.ElementMatcher(apiView, ElementType.ATTACHMENT, ImmutableMap.of(restriction.getKey(), restriction.getValue()), -1))); }
public void testSingleshot() { Range range = new Range(0, 10); DocumentHitIterator it = new DocumentHitIterator.Singleshot(range); Range first = it.next(); assertEquals(range, first); assertNull(it.next()); }
private static ApiView createApiViewFromXml(String xml) { IndexedDocument<Node, Element, Text> indexedDoc = DocProviders.POJO.parse(LineContainers.debugContainerWrap(xml)); Document doc = new DocumentImpl(createSequencer(indexedDoc), indexedDoc); return new ApiView(doc, mock(Wavelet.class)); }
public void testSingleshot() { Range range = new Range(0, 10); DocumentHitIterator it = new DocumentHitIterator.Singleshot(range); Range first = it.next(); assertEquals(range, first); assertNull(it.next()); }
private static ApiView createApiViewFromXml(String xml) { IndexedDocument<Node, Element, Text> indexedDoc = DocProviders.POJO.parse(LineContainers.debugContainerWrap(xml)); Document doc = new DocumentImpl(createSequencer(indexedDoc), indexedDoc); return new ApiView(doc, mock(Wavelet.class)); }
public void testTextMatcherWithoutShift() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i * 2 + 1, r.getStart()); assertEquals(i * 2 + 2, r.getEnd()); } assertNull(it.next()); }
public void testElementMatcherWithRestrictions() { String xml = "text <image attachment=\"nR_0YFT75\" style=\"full\">" + "<caption>good times</caption></image> hello"; ApiView apiView = createApiViewFromXml(xml); Map<String, String> restrictions = Maps.newHashMap(); assertEquals(1, countHits(new DocumentHitIterator.ElementMatcher( apiView, ElementType.ATTACHMENT, Collections.<String, String>emptyMap(), -1))); Restriction restriction = Attachment.restrictByAttachmentId("nR_0YFT75"); assertEquals(1, countHits(new DocumentHitIterator.ElementMatcher(apiView, ElementType.ATTACHMENT, ImmutableMap.of(restriction.getKey(), restriction.getValue()), -1))); restriction = Attachment.restrictByAttachmentId("nR_0YFT76"); assertEquals(0, countHits(new DocumentHitIterator.ElementMatcher(apiView, ElementType.ATTACHMENT, ImmutableMap.of(restriction.getKey(), restriction.getValue()), -1))); }
public void testBasicElementMatcher() { String xml = "text <gadget></gadget> <something/> <gadget/> hello"; ApiView apiView = createApiViewFromXml(xml); DocumentHitIterator it = new DocumentHitIterator.ElementMatcher( apiView, ElementType.GADGET, Collections.<String, String>emptyMap(), -1); List<Integer> hits = Lists.newArrayList(); assertEquals(xml.indexOf("<gadget>") + 1, it.next().getStart()); assertEquals(10, it.next().getStart()); // Elements get counted as 1 assertNull(it.next()); }
public void testBasicElementMatcher() { String xml = "text <gadget></gadget> <something/> <gadget/> hello"; ApiView apiView = createApiViewFromXml(xml); DocumentHitIterator it = new DocumentHitIterator.ElementMatcher( apiView, ElementType.GADGET, Collections.<String, String>emptyMap(), -1); List<Integer> hits = Lists.newArrayList(); assertEquals(xml.indexOf("<gadget>") + 1, it.next().getStart()); assertEquals(10, it.next().getStart()); // Elements get counted as 1 assertNull(it.next()); }
public void testTextMatcherDeletingTheFirstChar() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i + 1, r.getStart()); apiView.delete(1, 2); it.shift(1, -1); } assertNull(it.next()); }
public void testTextMatcherDeletingTheFirstChar() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i + 1, r.getStart()); apiView.delete(1, 2); it.shift(1, -1); } assertNull(it.next()); }
/** * Pretend we're shifting in the manner of INSERT_AFTER */ public void testTextMatcherShiftInsertAfter() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i * 3 + 1, r.getStart()); apiView.insert(r.getEnd(), "1"); it.shift(r.getEnd(), 1); } assertNull(it.next()); }
/** * Pretend we're shifting in the manner of INSERT_AFTER */ public void testTextMatcherShiftInsertAfter() { ApiView apiView = createApiViewFromXml("1 1 1"); DocumentHitIterator it = new DocumentHitIterator.TextMatcher(apiView, "1", -1); for (int i = 0; i < 3; i++) { Range r = it.next(); assertEquals(i * 3 + 1, r.getStart()); apiView.insert(r.getEnd(), "1"); it.shift(r.getEnd(), 1); } assertNull(it.next()); }