Example #1
0
    def test_basic_linear_identification(self):
        text = (
            LEVEL0 + FILLER + EL +
            LEVEL1 + FILLER + SIGNATURE + EL +
            LEVEL0 + FILLER + SIGNATURE + EL
        )
        code = mwpm.parse(text)
        blocks = indentblock.generate_indentblock_list(code)

        comments = comment.identify_comments_linear_merge(blocks)

        self.assertEqual(len(comments), 2)
    def test_handles_outdent(self):
        text = (
            LEVEL0 +
            LEVEL1 +
            LEVEL2 +
            OUTDENT + LEVEL0
        )
        code = mwpm.parse(text)

        blocks = indentblock.generate_indentblock_list(code)

        self.assertEqual(len(blocks), 4)
        self.assertEqual(blocks[3].indent, 3)
    def test_generates_list_from_reverse_input(self):
        text = (
            LEVEL3 +
            LEVEL2 +
            LEVEL1 +
            LEVEL0
        )
        code = mwpm.parse(text)

        blocks = indentblock.generate_indentblock_list(code)

        self.assertEqual(len(blocks), 4)
        self.assertEqual(blocks[0].indent, 3)
        self.assertEqual(blocks[1].indent, 2)
        self.assertEqual(blocks[2].indent, 1)
        self.assertEqual(blocks[3].indent, 0)
    def test_generates_list_from_basic_list_input(self):
        text = (
            LEVEL0 +
            LIST1 +
            LIST2 +
            LIST3
        )
        code = mwpm.parse(text)

        blocks = indentblock.generate_indentblock_list(code)

        self.assertEqual(len(blocks), 4)
        self.assertEqual(blocks[0].indent, 0)
        self.assertEqual(blocks[1].indent, 1)
        self.assertEqual(blocks[2].indent, 2)
        self.assertEqual(blocks[3].indent, 3)
Example #5
0
    def test_linear_identification_hierarchy_with_extra_endlines(self):
        text = (
            LEVEL0 + FILLER + EL + EL +
            LEVEL0 + FILLER + SIGNATURE + EL + EL +
            LEVEL1 + FILLER + SIGNATURE + EL + EL +
            LEVEL2 + FILLER + EL + EL +
            LEVEL2 + FILLER + SIGNATURE + EL + EL +
            LEVEL1 + FILLER + SIGNATURE + EL
        )
        code = mwpm.parse(text)
        blocks = indentblock.generate_indentblock_list(code)

        comments = comment.identify_comments_linear_merge(blocks)

        self.assertEqual(len(comments), 1, comments)
        self.assertEqual(len(comments[0].comments), 2)
        self.assertEqual(len(comments[0].comments[0].comments), 1)
        self.assertEqual(len(comments[0].comments[1].comments), 0)
    def test_gives_empty_start_zero_indent(self):
        text = (
            EMPTY +
            LEVEL0 +
            LIST1 +
            LIST1 +
            LIST2
        )
        code = mwpm.parse(text)

        blocks = indentblock.generate_indentblock_list(code)

        self.assertEqual(len(blocks), 5)
        self.assertEqual(blocks[0].indent, 0)
        self.assertEqual(blocks[1].indent, 0)
        self.assertEqual(blocks[2].indent, 1)
        self.assertEqual(blocks[3].indent, 1)
        self.assertEqual(blocks[4].indent, 2)
    def test_grants_empty_line_previous_indent(self):
        text = (
            LEVEL0 +
            LIST1 +
            EMPTY +
            LIST1 +
            LIST2
        )
        code = mwpm.parse(text)

        blocks = indentblock.generate_indentblock_list(code)

        self.assertEqual(len(blocks), 5)
        self.assertEqual(blocks[0].indent, 0)
        self.assertEqual(blocks[1].indent, 1)
        self.assertEqual(blocks[2].indent, 1)
        self.assertEqual(blocks[3].indent, 1)
        self.assertEqual(blocks[4].indent, 2)
    def test_breaks_same_level_apart(self):
        text = (
            LEVEL0 +
            LIST1 +
            LIST1 +
            LIST2 +
            LIST3
        )
        code = mwpm.parse(text)

        blocks = indentblock.generate_indentblock_list(code)

        self.assertEqual(len(blocks), 5)
        self.assertEqual(blocks[0].indent, 0)
        self.assertEqual(blocks[1].indent, 1)
        self.assertEqual(blocks[2].indent, 1)
        self.assertEqual(blocks[3].indent, 2)
        self.assertEqual(blocks[4].indent, 3)