def test_index_of_layer_containing_tag(self): stack = [] l1, l2, l3 = layer.Layer(stack), layer.Layer(stack), layer.Layer(stack) l1.tags, l1.text = {tag_m}, "..." l2.tags, l2.text = {tag_i, tag_s}, ",,," l3.tags, l3.text = {tag_p}, "---" fn = partial(tag.index_of_layer_containing_tag, stack) self.assertEqual(0, fn(tag_m.closing)) self.assertEqual(1, fn(tag_i.closing)) self.assertEqual(1, fn(tag_s.closing)) self.assertEqual(2, fn(tag_p.closing))
def test_close_one(self): stack = [] l1, l2 = layer.Layer(stack), layer.Layer(stack) l1.tags, l1.text = (), "..." l2.tags, l2.text = {tag_p}, ",,," expected = [] lay = layer.Layer(expected) lay.text = f"...[{tag_p.opening}],,,[/{tag_p.closing}]" lay.tags = () closings = {tag_p.closing} process_closing_tags(stack, closings) self.assertEqual(expected, stack)
def test_was_opened_AND_close_tags(self): stack = [] l1, l2 = layer.Layer(stack), layer.Layer(stack) l1.text = "..." l2.tags, l2.text = {tag_i}, ",,," self.assertTrue(tag.was_opened(stack, tag_i)) self.assertFalse(tag.was_opened(stack, tag.Tag("c green", "c"))) layer.close_tags(stack, {tag_i}, len(stack) - 1) expected = [] lay = layer.Layer(expected) lay.text = "...[i],,,[/i]" self.assertEqual(expected, stack)
def test_close_layer(self): stack = [] l1, l2, l3 = layer.Layer(stack), layer.Layer(stack), layer.Layer(stack) l1.tags, l1.text = {tag_m}, "..." l2.tags, l2.text = {tag_i}, ",,," l3.tags, l3.text = {tag_p, tag_s}, "+++" expected = [] l1, l2 = layer.Layer(expected), layer.Layer(expected) l1.tags, l1.text = {tag_m}, "..." l2.tags = {tag_i} l2.text = f",,,[{tag_p.opening}][{tag_s.opening}]" \ f"+++[/{tag_s.closing}][/{tag_p.closing}]" layer.close_layer(stack) self.assertEqual(expected, stack)
def test_new_layer(self): stack = [] lay = layer.Layer(stack) self.assertEqual(1, len(stack)) self.assertEqual(lay, stack[0])