Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit def78c7

Browse files
author
Juanjo Alvarez
committed
Add new tests, update some tests
Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent 041f83a commit def78c7

14 files changed

+1439
-18
lines changed

fixtures/empty_comment.py.sem.uast

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
},
2929
},
3030
Block: false,
31-
Prefix: "\n",
31+
Prefix: "",
3232
Suffix: "",
3333
Tab: "",
34-
Text: "",
34+
Text: "\n",
3535
},
3636
],
3737
},

fixtures/func_with_comments.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# comment above
2+
def foo(): # comment inline
3+
pass
4+
# comment after

fixtures/func_with_comments.py.native

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
'PY3AST': {
3+
'ast_type': "Module",
4+
body: [
5+
{
6+
args: {
7+
args: [],
8+
'ast_type': "arguments",
9+
},
10+
'ast_type': "FunctionDef",
11+
body: [
12+
{
13+
'ast_type': "Pass",
14+
'col_offset': 5,
15+
'end_col_offset': 9,
16+
'end_lineno': 3,
17+
lineno: 3,
18+
'noops_previous': {
19+
'ast_type': "PreviousNoops",
20+
'col_offset': 1,
21+
'end_col_offset': 15,
22+
'end_lineno': 1,
23+
lineno: 1,
24+
lines: [
25+
{
26+
'ast_type': "NoopLine",
27+
'col_offset': 1,
28+
lineno: 1,
29+
'noop_line': "# comment above\n",
30+
},
31+
],
32+
},
33+
},
34+
],
35+
'col_offset': 5,
36+
'decorator_list': [],
37+
'end_col_offset': 8,
38+
'end_lineno': 2,
39+
lineno: 2,
40+
name: "foo",
41+
'noops_sameline': {
42+
'ast_type': "SameLineNoops",
43+
'col_offset': 11,
44+
'end_col_offset': 27,
45+
'end_lineno': 2,
46+
lineno: 2,
47+
'noop_lines': [
48+
{
49+
'ast_type': "NoopSameLine",
50+
s: "# comment inline",
51+
},
52+
],
53+
},
54+
returns: ~,
55+
},
56+
],
57+
'noops_remainder': {
58+
'ast_type': "RemainderNoops",
59+
'col_offset': 1,
60+
'end_col_offset': 1,
61+
'end_lineno': 4,
62+
lineno: 4,
63+
lines: [
64+
{
65+
'ast_type': "NoopLine",
66+
'col_offset': 1,
67+
lineno: 4,
68+
'noop_line': "# comment after\n",
69+
},
70+
],
71+
},
72+
},
73+
}
+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{ '@type': "python:Module",
2+
'@role': [File, Module],
3+
'@pos': { '@type': "uast:Positions",
4+
},
5+
body: [
6+
{ '@type': "uast:FunctionGroup",
7+
'@pos': { '@type': "uast:Positions",
8+
start: { '@type': "uast:Position",
9+
offset: 20,
10+
line: 2,
11+
col: 5,
12+
},
13+
end: { '@type': "uast:Position",
14+
offset: 23,
15+
line: 2,
16+
col: 8,
17+
},
18+
},
19+
Nodes: [
20+
{
21+
async: false,
22+
comments: {
23+
'noops_sameline': { '@type': "python:SameLineNoops",
24+
'@role': [Comment],
25+
'@pos': { '@type': "uast:Positions",
26+
start: { '@type': "uast:Position",
27+
offset: 26,
28+
line: 2,
29+
col: 11,
30+
},
31+
end: { '@type': "uast:Position",
32+
offset: 42,
33+
line: 2,
34+
col: 27,
35+
},
36+
},
37+
'noop_lines': [
38+
{ '@type': "uast:Comment",
39+
'@pos': { '@type': "uast:Positions",
40+
},
41+
Block: false,
42+
Prefix: " ",
43+
Suffix: "",
44+
Tab: "",
45+
Text: "comment inline",
46+
},
47+
],
48+
},
49+
},
50+
decorators: [],
51+
},
52+
{ '@type': "uast:Alias",
53+
Name: { '@type': "uast:Identifier",
54+
Name: "foo",
55+
},
56+
Node: { '@type': "uast:Function",
57+
Body: { '@type': "uast:Block",
58+
Statements: [
59+
{ '@type': "python:Pass",
60+
'@token': "pass",
61+
'@role': [Noop, Statement],
62+
'@pos': { '@type': "uast:Positions",
63+
start: { '@type': "uast:Position",
64+
offset: 48,
65+
line: 3,
66+
col: 5,
67+
},
68+
end: { '@type': "uast:Position",
69+
offset: 52,
70+
line: 3,
71+
col: 9,
72+
},
73+
},
74+
'noops_previous': { '@type': "python:PreviousNoops",
75+
'@role': [Noop],
76+
'@pos': { '@type': "uast:Positions",
77+
start: { '@type': "uast:Position",
78+
offset: 0,
79+
line: 1,
80+
col: 1,
81+
},
82+
end: { '@type': "uast:Position",
83+
offset: 14,
84+
line: 1,
85+
col: 15,
86+
},
87+
},
88+
lines: [
89+
{ '@type': "uast:Comment",
90+
'@role': [Noop],
91+
'@pos': { '@type': "uast:Positions",
92+
start: { '@type': "uast:Position",
93+
offset: 0,
94+
line: 1,
95+
col: 1,
96+
},
97+
},
98+
Block: false,
99+
Prefix: " ",
100+
Suffix: "\n",
101+
Tab: "",
102+
Text: "comment above",
103+
},
104+
],
105+
},
106+
},
107+
],
108+
},
109+
Type: { '@type': "uast:FunctionType",
110+
Arguments: [],
111+
Returns: ~,
112+
},
113+
},
114+
},
115+
],
116+
},
117+
],
118+
'noops_remainder': { '@type': "python:RemainderNoops",
119+
'@role': [Noop],
120+
'@pos': { '@type': "uast:Positions",
121+
start: { '@type': "uast:Position",
122+
offset: 53,
123+
line: 4,
124+
col: 1,
125+
},
126+
end: { '@type': "uast:Position",
127+
offset: 53,
128+
line: 4,
129+
col: 1,
130+
},
131+
},
132+
lines: [
133+
{ '@type': "uast:Comment",
134+
'@role': [Noop],
135+
'@pos': { '@type': "uast:Positions",
136+
start: { '@type': "uast:Position",
137+
offset: 53,
138+
line: 4,
139+
col: 1,
140+
},
141+
},
142+
Block: false,
143+
Prefix: " ",
144+
Suffix: "\n",
145+
Tab: "",
146+
Text: "comment after",
147+
},
148+
],
149+
},
150+
}

fixtures/func_with_comments.py.uast

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{ '@type': "Module",
2+
'@role': [File, Module],
3+
'@pos': { '@type': "uast:Positions",
4+
},
5+
body: [
6+
{ '@type': "FunctionDef",
7+
'@token': "foo",
8+
'@role': [Declaration, Function, Identifier, Name],
9+
'@pos': { '@type': "uast:Positions",
10+
start: { '@type': "uast:Position",
11+
offset: 20,
12+
line: 2,
13+
col: 5,
14+
},
15+
end: { '@type': "uast:Position",
16+
offset: 23,
17+
line: 2,
18+
col: 8,
19+
},
20+
},
21+
args: { '@type': "arguments",
22+
'@role': [Argument, Declaration, Function, Incomplete],
23+
'@pos': { '@type': "uast:Positions",
24+
},
25+
args: [],
26+
},
27+
body: { '@type': "FunctionDef.body",
28+
'@role': [Body, Declaration, Function],
29+
'body_stmts': [
30+
{ '@type': "Pass",
31+
'@token': "pass",
32+
'@role': [Noop, Statement],
33+
'@pos': { '@type': "uast:Positions",
34+
start: { '@type': "uast:Position",
35+
offset: 48,
36+
line: 3,
37+
col: 5,
38+
},
39+
end: { '@type': "uast:Position",
40+
offset: 52,
41+
line: 3,
42+
col: 9,
43+
},
44+
},
45+
'noops_previous': { '@type': "PreviousNoops",
46+
'@role': [Noop],
47+
'@pos': { '@type': "uast:Positions",
48+
start: { '@type': "uast:Position",
49+
offset: 0,
50+
line: 1,
51+
col: 1,
52+
},
53+
end: { '@type': "uast:Position",
54+
offset: 14,
55+
line: 1,
56+
col: 15,
57+
},
58+
},
59+
lines: [
60+
{ '@type': "NoopLine",
61+
'@token': "# comment above\n",
62+
'@role': [Comment, Noop],
63+
'@pos': { '@type': "uast:Positions",
64+
start: { '@type': "uast:Position",
65+
offset: 0,
66+
line: 1,
67+
col: 1,
68+
},
69+
},
70+
},
71+
],
72+
},
73+
},
74+
],
75+
},
76+
'decorator_list': { '@type': "FunctionDef.decorators",
77+
'@role': [Declaration, Function, Incomplete],
78+
decorators: [],
79+
},
80+
'noops_sameline': { '@type': "SameLineNoops",
81+
'@role': [Comment],
82+
'@pos': { '@type': "uast:Positions",
83+
start: { '@type': "uast:Position",
84+
offset: 26,
85+
line: 2,
86+
col: 11,
87+
},
88+
end: { '@type': "uast:Position",
89+
offset: 42,
90+
line: 2,
91+
col: 27,
92+
},
93+
},
94+
'noop_lines': [
95+
{ '@type': "NoopSameLine",
96+
'@token': "# comment inline",
97+
'@role': [Comment, Noop],
98+
'@pos': { '@type': "uast:Positions",
99+
},
100+
},
101+
],
102+
},
103+
returns: ~,
104+
},
105+
],
106+
'noops_remainder': { '@type': "RemainderNoops",
107+
'@role': [Noop],
108+
'@pos': { '@type': "uast:Positions",
109+
start: { '@type': "uast:Position",
110+
offset: 53,
111+
line: 4,
112+
col: 1,
113+
},
114+
end: { '@type': "uast:Position",
115+
offset: 53,
116+
line: 4,
117+
col: 1,
118+
},
119+
},
120+
lines: [
121+
{ '@type': "NoopLine",
122+
'@token': "# comment after\n",
123+
'@role': [Comment, Noop],
124+
'@pos': { '@type': "uast:Positions",
125+
start: { '@type': "uast:Position",
126+
offset: 53,
127+
line: 4,
128+
col: 1,
129+
},
130+
},
131+
},
132+
],
133+
},
134+
}

fixtures/issue177.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def testfnc1(**options):
2+
print "force python2"

0 commit comments

Comments
 (0)