コード例 #1
0
 def test_codegen_add_indent_tokens(self) -> None:
     state = WhitespaceInclusivePositionProvidingCodegenState(
         " " * 4, "\n", WhitespaceInclusivePositionProvider()
     )
     state.increase_indent(state.default_indent)
     state.add_indent_tokens()
     self.assertEqual(position(state), (1, 4))
コード例 #2
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)))
コード例 #3
0
 def test_codegen_add_token(self) -> None:
     state = WhitespaceInclusivePositionProvidingCodegenState(
         " " * 4, "\n", WhitespaceInclusivePositionProvider()
     )
     state.add_token("1234")
     self.assertEqual(position(state), (1, 4))
コード例 #4
0
 def test_codegen_initial_position(self) -> None:
     state = WhitespaceInclusivePositionProvidingCodegenState(
         " " * 4, "\n", WhitespaceInclusivePositionProvider()
     )
     self.assertEqual(position(state), (1, 0))