def test_match(self): f = mocks.FE() w = messager.Messager(f) self.assertFalse(w.match('foo')) f.context.backends._messages[0]._display = chunks.Chunk([((), 'foo\n') ]) self.assertTrue(w.match('foo'))
def test_view_search(self): f = mocks.FE() w = messager.Messager(f) f.context.backends._messages[0]._display = chunks.Chunk([ ((), 'bar\nfoo\n') ]) w.search_re = re.compile('foo') self.assertEqual([ ({'visible', 'bar'}, 'bar\n'), ({'reverse'}, 'foo'), ((), '\n'), ], [chunk.tagsets() for (mark, chunk) in w.view(0)][0])
def test_find(self): f = mocks.FE() w = messager.Messager(f) self.assertFalse(w.find('foo', True)) self.assertEqual([[({'visible', 'bar'}, '\n')]], [chunk.tagsets() for (mark, chunk) in w.view(0)]) f.context.backends._messages.append(mocks.Message()) f.context.backends._messages[-1]._display = chunks.Chunk([((), 'foo\n') ]) self.assertEqual([[({'visible', 'bar'}, '\n')], [((), 'foo\n')]], [chunk.tagsets() for (mark, chunk) in w.view(0)]) self.assertTrue(w.find('foo', True)) self.assertEqual([[((), '\n')], [({'visible', 'bar'}, 'foo\n')]], [chunk.tagsets() for (mark, chunk) in w.view(0)])
def test_prefix_chunk(self): prefix_chunk = messages.SnipeMessage.Decor.prefix_chunk self.assertEqual(prefix_chunk('foo ', []), []) self.assertEqual(prefix_chunk( 'foo ', chunks.Chunk([((), 'bar')])), [(set(), 'foo bar\n')]) self.assertEqual( prefix_chunk('foo ', chunks.Chunk([((), 'bar\nbaz\n')])), [(set(), 'foo bar\nfoo baz\n')]) self.assertEqual( prefix_chunk('foo ', chunks.Chunk([((), 'bar\n\nbaz\n')])), [(set(), 'foo bar\nfoo \nfoo baz\n')]) self.assertEqual( prefix_chunk('foo ', chunks.Chunk([({'bold'}, 'bar\nbaz\n')])), [({'bold'}, 'foo bar\nfoo baz\n')]) self.assertEqual( prefix_chunk('foo ', chunks.Chunk([({'bold'}, 'bar\n\nbaz\n')])), [ ({'bold'}, 'foo bar\nfoo \nfoo baz\n'), ]) self.assertEqual( prefix_chunk('foo ', chunks.Chunk([(('bold',), '\nbar\nbaz\n')])), [ ({'bold'}, 'foo \nfoo bar\nfoo baz\n')]) self.assertEqual( prefix_chunk( 'foo ', chunks.Chunk([(('underline',), 'bar\nbaz\n')])), [ (set(), 'foo '), ({'underline'}, 'bar'), (set(), '\nfoo '), ({'underline'}, 'baz'), (set(), '\n'), ]) self.assertEqual( prefix_chunk( 'foo ', chunks.Chunk([(('underline',), 'bar\n\nbaz\n')])), [ (set(), 'foo '), ({'underline'}, 'bar'), (set(), '\nfoo \nfoo '), ({'underline'}, 'baz'), (set(), '\n'), ])