Пример #1
0
 def test_codegen_decrease_indent(self) -> None:
     state = BasicCodegenState(" " * 4, "\n", BasicPositionProvider())
     state.increase_indent(state.default_indent)
     state.increase_indent(state.default_indent)
     state.increase_indent(state.default_indent)
     state.decrease_indent()
     state.add_indent_tokens()
     self.assertEqual(position(state), (1, 8))
Пример #2
0
    def test_position(self) -> None:
        # create a dummy node
        node = cst.Pass()

        # simulate codegen behavior for the dummy node
        # generates the code " pass "
        state = BasicCodegenState(" " * 4, "\n", BasicPositionProvider())
        start = CodePosition(state.line, state.column)
        state.add_token(" ")
        with state.record_syntactic_position(node):
            state.add_token("pass")
        state.add_token(" ")
        end = CodePosition(state.line, state.column)
        state.record_position(node, CodeRange(start, end))

        # check whitespace is correctly recorded
        self.assertEqual(state.provider._computed[node], CodeRange((1, 0), (1, 6)))
Пример #3
0
 def test_codegen_add_newline(self) -> None:
     state = BasicCodegenState(" " * 4, "\n", BasicPositionProvider())
     state.add_token("\n")
     self.assertEqual(position(state), (2, 0))
Пример #4
0
 def test_codegen_add_tokens(self) -> None:
     state = BasicCodegenState(" " * 4, "\n", BasicPositionProvider())
     state.add_token("1234\n1234")
     self.assertEqual(position(state), (2, 4))
Пример #5
0
 def test_codegen_initial_position(self) -> None:
     state = BasicCodegenState(" " * 4, "\n", BasicPositionProvider())
     self.assertEqual(position(state), (1, 0))