Esempio n. 1
0
 def test_codegen_decrease_indent(self) -> None:
     state = WhitespaceInclusivePositionProvidingCodegenState(
         " " * 4, "\n", WhitespaceInclusivePositionProvider())
     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))
Esempio n. 2
0
 def test_codegen_add_token(self) -> None:
     state = WhitespaceInclusivePositionProvidingCodegenState(
         " " * 4, "\n", WhitespaceInclusivePositionProvider()
     )
     state.add_token("1234")
     self.assertEqual(position(state), (1, 4))
Esempio n. 3
0
 def test_codegen_initial_position(self) -> None:
     state = WhitespaceInclusivePositionProvidingCodegenState(
         " " * 4, "\n", WhitespaceInclusivePositionProvider()
     )
     self.assertEqual(position(state), (1, 0))
Esempio n. 4
0
    def test_whitespace_inclusive_position(self) -> None:
        # create a dummy node
        node = cst.Pass()

        # simulate codegen behavior for the dummy node
        # generates the code " pass "
        state = WhitespaceInclusivePositionProvidingCodegenState(
            " " * 4, "\n", WhitespaceInclusivePositionProvider()
        )
        state.before_codegen(node)
        state.add_token(" ")
        with state.record_syntactic_position(node):
            state.add_token("pass")
        state.add_token(" ")
        state.after_codegen(node)

        # check whitespace is correctly recorded
        self.assertEqual(state.provider._computed[node], CodeRange((1, 0), (1, 6)))