Skip to content

Commit bf43a12

Browse files
author
Pierre Penninckx
committed
[fix] shows abnormal whitespace production on insert
Furthermore, this shows an unexpected behaviour with the index in a LineProxyList. The .insert(2, ...) should insert just before "class B" but instead inserts after it. This is because the \n after "class A" is merged with that node's value but it shouldn't.
1 parent 07eeb17 commit bf43a12

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

tests/test_insert.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/python
2+
# -*- coding:Utf-8 -*-
3+
4+
""" Tests the code insertion features """
5+
6+
import pytest
7+
# pylint: disable=redefined-outer-name
8+
from redbaron import RedBaron
9+
10+
11+
@pytest.fixture
12+
def red():
13+
return RedBaron("""\
14+
class A:
15+
pass
16+
17+
class B:
18+
pass
19+
""")
20+
21+
22+
def test_insert_with_class_0(red):
23+
red.insert(0, "a = 1")
24+
25+
print(red.dumps())
26+
assert red.dumps() == """\
27+
a = 1
28+
class A:
29+
pass
30+
31+
class B:
32+
pass
33+
"""
34+
35+
36+
def test_insert_with_class_1(red):
37+
red.insert(1, "a = 1")
38+
39+
print(red.dumps())
40+
assert red.dumps() == """\
41+
class A:
42+
pass
43+
a = 1
44+
45+
class B:
46+
pass
47+
"""
48+
49+
50+
def test_insert_with_class_2(red):
51+
red.insert(2, "a = 1")
52+
53+
print(red.dumps())
54+
assert red.dumps() == """\
55+
class A:
56+
pass
57+
58+
a = 1
59+
class B:
60+
pass
61+
"""
62+
63+
64+
def test_insert_with_class_3(red):
65+
red.insert(3, "a = 1")
66+
67+
print(red.dumps())
68+
assert red.dumps() == """\
69+
class A:
70+
pass
71+
72+
class B:
73+
pass
74+
a = 1
75+
"""
76+

0 commit comments

Comments
 (0)