Exemplo n.º 1
0
    def test_line_change(self):
        code = "x=1\ny=2"
        block = Block(code)
        code_block = CodeBlock(code=code, block=block)

        new_code = "x=12\ny=2"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 0)
        self.assertEqual(last_line, 1)
        self.assertEqual(lines, 1)
Exemplo n.º 2
0
    def test_delete_in_middle(self):
        code = "x=1\na=9\ny=2"
        block = Block(code)
        code_block = CodeBlock(code=code, block=block)

        new_code = "x=1\ny=2"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 1)
        self.assertEqual(last_line, 2)
        self.assertEqual(lines, 0)
Exemplo n.º 3
0
    def test_delete_all(self):

        code = "x=1"
        block = Block(code)
        code_block = CodeBlock(code=code, block=block)

        new_code = ""

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 0)
        self.assertEqual(last_line, 1)
        self.assertEqual(lines, 0)
Exemplo n.º 4
0
    def test_insert_before_after_and_middle(self):

        code = "y=2\nz=4"
        block = Block(code)
        code_block = CodeBlock(code=code, block=block)

        new_code = "a=1\ny=2\nx=1\nz=4\nb=99"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 0)
        self.assertEqual(last_line, 0)
        self.assertEqual(lines, 3)
Exemplo n.º 5
0
    def test_insert_in_middle_multiline(self):

        code = "y=2\nz=4"
        block = Block(code)
        code_block = CodeBlock(code=code, block=block)

        new_code = "y=2\na=1\nb=2\nc=3\nz=4"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 1)
        self.assertEqual(last_line, 1)
        self.assertEqual(lines, 3)
Exemplo n.º 6
0
    def test_insert_after_line(self):

        code = "y=2"
        block = Block(code)
        code_block = CodeBlock(code=code, block=block)

        new_code = "y=2\nx=1"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 1)
        self.assertEqual(last_line, 1)
        self.assertEqual(lines, 1)
Exemplo n.º 7
0
    def test_modified_newline(self):
        code = "x=1\nz=3"

        block = Block(code)
        code_block = CodeBlock(code=code)

        new_code="x=1\ny=2\nz=3"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 1)
        self.assertEqual(last_line, 1)
        self.assertEqual(lines, 1)
Exemplo n.º 8
0
    def test_modified(self):
        code = "from foo import bar"

        block = Block(code)
        code_block = CodeBlock(code=code)

        new_code="from baz import nothing"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 0)
        self.assertEqual(last_line, 1)
        self.assertEqual(lines, 1)
Exemplo n.º 9
0
    def test_multi_line_partial_delete(self):
        code = "x=1\ny=2+x\nz=3"

        block = Block(code)
        code_block = CodeBlock(code=code)

        new_code="x=1\ny=2"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 1)
        self.assertEqual(last_line, 3)
        self.assertEqual(lines, 1)
Exemplo n.º 10
0
    def test_insert_into_empty(self):

        code = ""
        block = Block(code)
        code_block = CodeBlock(code=code, block=block)

        new_code = "x = 1"

        first_line, last_line, lines = code_block.get_changes(code_block.code, new_code)

        self.assertEqual(first_line, 0)
        self.assertEqual(last_line, 0)
        self.assertEqual(lines, 1)