示例#1
0
    def testScanSingleHit(self):
        data = b"foobarbaz"
        chunk = streaming.Chunk(offset=0, data=data)
        spans = list(chunk.Scan(conditions.LiteralMatcher(b"bar")))

        self.assertLen(spans, 1)
        self.assertEqual(spans[0], self.Span(begin=3, end=6))
示例#2
0
    def testScanWithOverlapOverlapping(self):
        data = b"oooooo"
        chunk = streaming.Chunk(offset=0, data=data, overlap=3)
        spans = list(chunk.Scan(conditions.LiteralMatcher(b"oo")))

        self.assertLen(spans, 2)
        self.assertEqual(spans[0], self.Span(begin=2, end=4))
        self.assertEqual(spans[1], self.Span(begin=4, end=6))
示例#3
0
    def testScanWithOverlap(self):
        data = b"foofoobarfoofoo"
        chunk = streaming.Chunk(offset=0, data=data, overlap=8)
        spans = list(chunk.Scan(conditions.LiteralMatcher(b"foo")))

        self.assertLen(spans, 2)
        self.assertEqual(spans[0], self.Span(begin=9, end=12))
        self.assertEqual(spans[1], self.Span(begin=12, end=15))
示例#4
0
    def testScanOverlappedHits(self):
        data = b"xoxoxoxo"
        chunk = streaming.Chunk(offset=0, data=data)
        spans = list(chunk.Scan(conditions.LiteralMatcher(b"xoxo")))

        self.assertLen(spans, 2)
        self.assertEqual(spans[0], self.Span(begin=0, end=4))
        self.assertEqual(spans[1], self.Span(begin=4, end=8))
示例#5
0
    def testScanMultiHit(self):
        data = b"foobarfoo"
        chunk = streaming.Chunk(offset=0, data=data)
        spans = list(chunk.Scan(conditions.LiteralMatcher(b"foo")))

        self.assertLen(spans, 2)
        self.assertEqual(spans[0], self.Span(begin=0, end=3))
        self.assertEqual(spans[1], self.Span(begin=6, end=9))
示例#6
0
  def testNoMatchLiteral(self):
    matcher = conditions.LiteralMatcher(b"norf")

    span = matcher.Match(b"quux", 0)
    self.assertFalse(span)

    span = matcher.Match(b"norf", 2)
    self.assertFalse(span)

    span = matcher.Match(b"quuxnorf", 5)
    self.assertFalse(span)
示例#7
0
  def testMatchLiteral(self):
    matcher = conditions.LiteralMatcher(b"bar")

    span = matcher.Match(b"foobarbaz", 0)
    self.assertTrue(span)
    self.assertEqual(span.begin, 3)
    self.assertEqual(span.end, 6)

    span = matcher.Match(b"barbarbar", 0)
    self.assertTrue(span)
    self.assertEqual(span.begin, 0)
    self.assertEqual(span.end, 3)

    span = matcher.Match(b"barbarbar", 4)
    self.assertTrue(span)
    self.assertEqual(span.begin, 6)
    self.assertEqual(span.end, 9)