@@ -73,86 +73,122 @@ private static Context newContext(Engine engine) {
73
73
74
74
@ Test
75
75
public void testRootBodyTagModule () throws Exception {
76
- String code = "import time\n " + "time.gmtime()\n " ;
76
+ String code = "import time\n " +
77
+ "time.gmtime()\n " ;
77
78
checkRootTagAndRootBodyTag (code );
78
79
}
79
80
80
81
@ Test
81
82
public void testRootBodyTagGenerator01 () throws Exception {
82
- String code = "def test():\n " + " yield 22\n " + "for i in test():\n " + " i\n " ;
83
+ String code = "def test():\n " +
84
+ " yield 22\n " +
85
+ "for i in test():\n " +
86
+ " i\n " ;
83
87
checkRootTagAndRootBodyTag (code );
84
88
}
85
89
86
90
@ Test
87
91
public void testRootBodyTagGenerator02 () throws Exception {
88
- String code = "def test():\n " + " yield 22\n " + " yield 42\n " + " yield 62\n " + "for i in test():\n " + " i\n " ;
92
+ String code = "def test():\n " +
93
+ " yield 22\n " +
94
+ " yield 42\n " +
95
+ " yield 62\n " +
96
+ "for i in test():\n " +
97
+ " i\n " ;
89
98
checkRootTagAndRootBodyTag (code );
90
99
}
91
100
92
101
@ Test
93
102
public void testRootBodyTagGenerator03 () throws Exception {
94
- String code = "def fn(a, b):\n " + " yield a\n " + " yield b\n " + "for i in fn(3,4):\n " + " i\n " ;
103
+ String code = "def fn(a, b):\n " +
104
+ " yield a\n " +
105
+ " yield b\n " +
106
+ "for i in fn(3,4):\n " +
107
+ " i\n " ;
95
108
checkRootTagAndRootBodyTag (code );
96
109
}
97
110
98
111
@ Test
99
112
public void testRootBodyTagFunction01 () throws Exception {
100
- String code = "def test():\n " + " return 22\n " + "test()" ;
113
+ String code = "def test():\n " +
114
+ " return 22\n " +
115
+ "test()" ;
101
116
checkRootTagAndRootBodyTag (code );
102
117
}
103
118
104
119
@ Test
105
120
public void testRootBodyTagFunction02 () throws Exception {
106
- String code = "def test(a,b):\n " + " return a + b\n " + "test(1, 2)" ;
121
+ String code = "def test(a,b):\n " +
122
+ " return a + b\n " +
123
+ "test(1, 2)" ;
107
124
HashMap <InstrumentableNode , InstrumentableNode > rootsMap = checkRootTagAndRootBodyTag (code );
108
125
InnerRootNode inner = findInnerRootNodeWithEndOffset (rootsMap , 30 );
109
126
checkBodyPosition (rootsMap , inner , 17 , 29 );
110
127
}
111
128
112
129
@ Test
113
130
public void testRootBodyTagFunction03 () throws Exception {
114
- String code = "def test(a,b):\n " + " '''This is a simple doc'''\n " + " return a + b\n " + "test(1, 2)" ;
131
+ String code = "def test(a,b):\n " +
132
+ " '''This is a simple doc'''\n " +
133
+ " return a + b\n " +
134
+ "test(1, 2)" ;
115
135
HashMap <InstrumentableNode , InstrumentableNode > rootsMap = checkRootTagAndRootBodyTag (code );
116
136
InnerRootNode inner = findInnerRootNodeWithEndOffset (rootsMap , 59 );
117
137
checkBodyPosition (rootsMap , inner , 46 , 58 );
118
138
}
119
139
120
140
@ Test
121
141
public void testRootBodyTagFunction04 () throws Exception {
122
- String code = "def test():\n " + " '''Function without body'''\n " + "test()" ;
123
- HashMap <InstrumentableNode , InstrumentableNode > rootsMap = checkRootTagAndRootBodyTag (code , true );
142
+ String code = "def test():\n " +
143
+ " '''Function without body'''\n " +
144
+ "test()" ;
145
+ HashMap <InstrumentableNode , InstrumentableNode > rootsMap = checkRootTagAndRootBodyTag (code );
124
146
InnerRootNode inner = findInnerRootNodeWithEndOffset (rootsMap , 42 );
125
- Assert .assertEquals (null , rootsMap .get (inner ));
147
+ checkBodyPosition (rootsMap , inner , 41 , 42 );
148
+ }
149
+
150
+ @ Test
151
+ public void testRootBodyTagFunction05 () throws Exception {
152
+ String code = "def fn():\n " +
153
+ " try:\n " +
154
+ " pass\n " +
155
+ " except ValueError as va:\n " +
156
+ " pass\n " +
157
+ "fn()" ;
158
+ HashMap <InstrumentableNode , InstrumentableNode > rootsMap = checkRootTagAndRootBodyTag (code );
159
+ InnerRootNode inner = findInnerRootNodeWithEndOffset (rootsMap , 62 );
160
+ checkBodyPosition (rootsMap , inner , 12 , 62 );
126
161
}
127
162
128
163
@ Test
129
164
public void testRootBodyTagLambda01 () throws Exception {
130
- String code = "x = lambda a, b, c : a + b + c\n " + "x(5, 6, 2)" ;
165
+ String code = "x = lambda a, b, c : a + b + c\n " +
166
+ "x(5, 6, 2)" ;
131
167
checkRootTagAndRootBodyTag (code );
132
168
}
133
169
134
170
@ Test
135
171
public void testRootBodyTagClass01 () throws Exception {
136
- String code = "class MyClass:\n " + " x = 5\n " + "m = MyClass()\n " ;
172
+ String code = "class MyClass:\n " +
173
+ " x = 5\n " +
174
+ "m = MyClass()\n " ;
137
175
HashMap <InstrumentableNode , InstrumentableNode > rootsMap = checkRootTagAndRootBodyTag (code );
138
176
InnerRootNode inner = findInnerRootNodeWithEndOffset (rootsMap , 23 );
139
177
checkBodyPosition (rootsMap , inner , 17 , 22 );
140
178
}
141
179
142
180
@ Test
143
181
public void testRootBodyTagClass02 () throws Exception {
144
- String code = "class MyClass:\n " + " '''This is a simple test class'''\n " + " x = 5\n " + "m = MyClass()\n " ;
182
+ String code = "class MyClass:\n " +
183
+ " '''This is a simple test class'''\n " +
184
+ " x = 5\n " + "m = MyClass()\n " ;
145
185
HashMap <InstrumentableNode , InstrumentableNode > rootsMap = checkRootTagAndRootBodyTag (code );
146
186
InnerRootNode inner = findInnerRootNodeWithEndOffset (rootsMap , 59 );
147
187
checkBodyPosition (rootsMap , inner , 53 , 58 );
148
188
149
189
}
150
190
151
191
private HashMap <InstrumentableNode , InstrumentableNode > checkRootTagAndRootBodyTag (String code ) throws Exception {
152
- return checkRootTagAndRootBodyTag (code , false );
153
- }
154
-
155
- private HashMap <InstrumentableNode , InstrumentableNode > checkRootTagAndRootBodyTag (String code , boolean possibleEmptyRootTag ) throws Exception {
156
192
Engine engine = Engine .newBuilder ().build ();
157
193
Context newContext = newContext (engine );
158
194
newContext .initialize ("python" );
@@ -166,10 +202,8 @@ private HashMap<InstrumentableNode, InstrumentableNode> checkRootTagAndRootBodyT
166
202
167
203
newContext .eval (source );
168
204
169
- if (!possibleEmptyRootTag ) {
170
- for (InstrumentableNode rootBodyTag : rootsMap .values ()) {
171
- assertTrue ("There is a RootTag node without RootBodyTag node" , rootBodyTag != null );
172
- }
205
+ for (InstrumentableNode rootBodyTag : rootsMap .values ()) {
206
+ assertTrue ("There is a RootTag node without RootBodyTag node" , rootBodyTag != null );
173
207
}
174
208
return rootsMap ;
175
209
}
0 commit comments