comment_strip-ruby 0.1.2.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AUTHORS.md +21 -0
- data/CHANGES.md +62 -0
- data/CONTRIBUTING.md +36 -0
- data/EXAMPLES.md +9 -0
- data/FAQ.md +28 -0
- data/INSTALL.md +41 -0
- data/LICENSE +19 -18
- data/NEWS.md +16 -0
- data/README.md +81 -18
- data/Rakefile +21 -0
- data/SECURITY.md +23 -0
- data/TODO.md +49 -0
- data/examples/read_c_family_source.rb +39 -0
- data/examples/read_c_family_source_from_stdin.rb +39 -0
- data/lib/comment_strip/language_families/c.rb +259 -134
- data/lib/comment_strip/language_families/hash_line.rb +297 -0
- data/lib/comment_strip/strip.rb +31 -15
- data/lib/comment_strip/version.rb +8 -8
- data/lib/comment_strip.rb +7 -6
- data/test/unit/{tc_strip.rb → tc_strip_c.rb} +266 -236
- data/test/unit/tc_strip_c_defects.rb +179 -0
- data/test/unit/tc_strip_hash_line.rb +95 -0
- data/test/unit/tc_strip_hash_line_defects.rb +154 -0
- data/test/unit/ts_all.rb +1 -1
- metadata +37 -13
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
#! /usr/bin/env ruby
|
|
2
2
|
|
|
3
|
+
# NOTE: TAB characters in this test file are intentional and occur only
|
|
4
|
+
# inside HEREDOC fixtures containing imported C/C++ source. They preserve
|
|
5
|
+
# the fixtures' original whitespace so comment stripping can be tested
|
|
6
|
+
# accurately. All Ruby test code and all non-fixture lines must use spaces,
|
|
7
|
+
# with two-space indentation; do not add TABs elsewhere.
|
|
8
|
+
|
|
9
|
+
|
|
3
10
|
$:.unshift File.join(__dir__, '../..', 'lib')
|
|
4
11
|
|
|
5
12
|
|
|
@@ -9,63 +16,63 @@ require 'xqsr3/extensions/test/unit'
|
|
|
9
16
|
|
|
10
17
|
require 'test/unit'
|
|
11
18
|
|
|
12
|
-
class
|
|
19
|
+
class Test_C_strip_1 < Test::Unit::TestCase
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
include ::CommentStrip
|
|
15
22
|
|
|
16
|
-
|
|
23
|
+
def test_nil
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
assert_nil strip(nil, 'C')
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
assert_nil ::CommentStrip.strip(nil, 'C')
|
|
28
|
+
end
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
def test_unrecognised_families
|
|
24
31
|
|
|
25
|
-
|
|
32
|
+
unrecognised_families = %w{
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
Python
|
|
35
|
+
Perl
|
|
36
|
+
Ruby
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
Java
|
|
39
|
+
Kotlin
|
|
40
|
+
Scala
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
Rust
|
|
43
|
+
}
|
|
37
44
|
|
|
38
|
-
|
|
45
|
+
unrecognised_families.each do |family|
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
end
|
|
47
|
+
assert_raise_with_message(::RuntimeError, /family.*unrecognised/) { strip('', family) }
|
|
48
|
+
assert_raise_with_message(::RuntimeError, /family.*unrecognised/) { ::CommentStrip.strip('', family) }
|
|
43
49
|
end
|
|
50
|
+
end
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
def test_empty
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
assert_equal "", strip('', 'C')
|
|
55
|
+
assert_equal "", ::CommentStrip.strip('', :C)
|
|
56
|
+
end
|
|
50
57
|
|
|
51
|
-
|
|
58
|
+
def test_simple_main
|
|
52
59
|
|
|
53
|
-
|
|
60
|
+
input = <<-EOF_main
|
|
54
61
|
#include <stdio.h>
|
|
55
62
|
int main(int argc, char* argv[])
|
|
56
63
|
{
|
|
57
64
|
return 0;
|
|
58
65
|
}
|
|
59
66
|
EOF_main
|
|
60
|
-
|
|
67
|
+
expected = input
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
assert_equal expected, strip(input, 'C')
|
|
70
|
+
assert_equal expected, ::CommentStrip.strip(input, 'C')
|
|
71
|
+
end
|
|
65
72
|
|
|
66
|
-
|
|
73
|
+
def test_x_1
|
|
67
74
|
|
|
68
|
-
|
|
75
|
+
input = <<-EOF_main
|
|
69
76
|
#ifdef CLARA_PLATFORM_WINDOWS
|
|
70
77
|
case '/': from = i+1; return SlashOpt;
|
|
71
78
|
#endif
|
|
@@ -78,7 +85,7 @@ EOF_main
|
|
|
78
85
|
return !placeholder.empty();
|
|
79
86
|
}
|
|
80
87
|
EOF_main
|
|
81
|
-
|
|
88
|
+
expected = <<-EOF_main
|
|
82
89
|
#ifdef CLARA_PLATFORM_WINDOWS
|
|
83
90
|
case '/': from = i+1; return SlashOpt;
|
|
84
91
|
#endif
|
|
@@ -92,232 +99,232 @@ EOF_main
|
|
|
92
99
|
}
|
|
93
100
|
EOF_main
|
|
94
101
|
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
actual = strip(input, 'C')
|
|
103
|
+
actual = ::CommentStrip.strip(input, 'C')
|
|
97
104
|
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
assert_equal expected, actual
|
|
106
|
+
end
|
|
100
107
|
|
|
101
|
-
|
|
108
|
+
def test_x_2
|
|
102
109
|
|
|
103
|
-
|
|
110
|
+
input = <<-EOF_main
|
|
104
111
|
|
|
105
112
|
} // namespace something
|
|
106
113
|
EOF_main
|
|
107
|
-
|
|
114
|
+
expected = <<-EOF_main
|
|
108
115
|
|
|
109
116
|
}
|
|
110
117
|
EOF_main
|
|
111
118
|
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
actual = strip(input, 'C')
|
|
120
|
+
actual = ::CommentStrip.strip(input, 'C')
|
|
114
121
|
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
assert_equal expected, actual
|
|
123
|
+
end
|
|
117
124
|
|
|
118
|
-
|
|
125
|
+
def test_x_3
|
|
119
126
|
|
|
120
|
-
|
|
127
|
+
input = <<-EOF_main
|
|
121
128
|
|
|
122
129
|
#endif /* !LOG_PERROR */
|
|
123
130
|
EOF_main
|
|
124
|
-
|
|
131
|
+
expected = <<-EOF_main
|
|
125
132
|
|
|
126
133
|
#endif
|
|
127
134
|
EOF_main
|
|
128
135
|
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
actual = strip(input, 'C')
|
|
137
|
+
actual = ::CommentStrip.strip(input, 'C')
|
|
131
138
|
|
|
132
|
-
|
|
133
|
-
|
|
139
|
+
assert_equal expected, actual
|
|
140
|
+
end
|
|
134
141
|
|
|
135
|
-
|
|
142
|
+
def test_code_with_single_quoted_characters_1
|
|
136
143
|
|
|
137
|
-
|
|
144
|
+
input = <<-EOF_main
|
|
138
145
|
|
|
139
146
|
case '"': // " this is the comment "
|
|
140
147
|
EOF_main
|
|
141
|
-
|
|
148
|
+
expected = <<-EOF_main
|
|
142
149
|
|
|
143
150
|
case '"':
|
|
144
151
|
EOF_main
|
|
145
152
|
|
|
146
|
-
|
|
153
|
+
actual = strip(input, 'C')
|
|
147
154
|
|
|
148
|
-
|
|
149
|
-
|
|
155
|
+
assert_equal expected, actual
|
|
156
|
+
end
|
|
150
157
|
|
|
151
|
-
|
|
158
|
+
def test_code_with_single_quoted_characters_2
|
|
152
159
|
|
|
153
|
-
|
|
160
|
+
input = <<-EOF_main
|
|
154
161
|
|
|
155
|
-
case '
|
|
162
|
+
case '\"': // " this is the comment "
|
|
156
163
|
EOF_main
|
|
157
|
-
|
|
164
|
+
expected = <<-EOF_main
|
|
158
165
|
|
|
159
|
-
case '
|
|
166
|
+
case '\"':
|
|
160
167
|
EOF_main
|
|
161
168
|
|
|
162
|
-
|
|
169
|
+
actual = strip(input, 'C')
|
|
163
170
|
|
|
164
|
-
|
|
165
|
-
|
|
171
|
+
assert_equal expected, actual
|
|
172
|
+
end
|
|
166
173
|
|
|
167
|
-
|
|
174
|
+
def test_code_with_single_quoted_characters_3
|
|
168
175
|
|
|
169
|
-
|
|
176
|
+
input = <<-EOF_main
|
|
170
177
|
|
|
171
|
-
case '
|
|
178
|
+
case '\'': // " this is the comment "
|
|
172
179
|
EOF_main
|
|
173
|
-
|
|
180
|
+
expected = <<-EOF_main
|
|
174
181
|
|
|
175
|
-
case '
|
|
182
|
+
case '\'':
|
|
176
183
|
EOF_main
|
|
177
184
|
|
|
178
|
-
|
|
185
|
+
actual = strip(input, 'C')
|
|
179
186
|
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
assert_equal expected, actual
|
|
188
|
+
end
|
|
182
189
|
|
|
183
|
-
|
|
190
|
+
def test_code_with_single_quoted_characters_4
|
|
184
191
|
|
|
185
|
-
|
|
192
|
+
input = <<-EOF_main
|
|
186
193
|
|
|
187
194
|
case '\\\\': // " this is the comment "
|
|
188
195
|
EOF_main
|
|
189
|
-
|
|
196
|
+
expected = <<-EOF_main
|
|
190
197
|
|
|
191
198
|
case '\\\\':
|
|
192
199
|
EOF_main
|
|
193
200
|
|
|
194
|
-
|
|
201
|
+
actual = strip(input, 'C')
|
|
195
202
|
|
|
196
|
-
|
|
197
|
-
|
|
203
|
+
assert_equal expected, actual
|
|
204
|
+
end
|
|
198
205
|
|
|
199
|
-
|
|
206
|
+
def test_code_with_single_quoted_characters_5
|
|
200
207
|
|
|
201
|
-
|
|
208
|
+
input = <<-EOF_main
|
|
202
209
|
|
|
203
210
|
case '\\\\': // " this is the comment "
|
|
204
211
|
EOF_main
|
|
205
|
-
|
|
212
|
+
expected = <<-EOF_main
|
|
206
213
|
|
|
207
214
|
case '\\\\':
|
|
208
215
|
EOF_main
|
|
209
216
|
|
|
210
|
-
|
|
217
|
+
actual = strip(input, 'C')
|
|
211
218
|
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
assert_equal expected, actual
|
|
220
|
+
end
|
|
214
221
|
|
|
215
|
-
|
|
222
|
+
def test_code_with_single_quoted_characters_6
|
|
216
223
|
|
|
217
|
-
|
|
224
|
+
input = <<-EOF_main
|
|
218
225
|
|
|
219
226
|
#define SOME_CHAR '\\x80' /* some char */
|
|
220
227
|
EOF_main
|
|
221
|
-
|
|
228
|
+
expected = <<-EOF_main
|
|
222
229
|
|
|
223
230
|
#define SOME_CHAR '\\x80'
|
|
224
231
|
EOF_main
|
|
225
232
|
|
|
226
|
-
|
|
233
|
+
actual = strip(input, 'C')
|
|
227
234
|
|
|
228
|
-
|
|
229
|
-
|
|
235
|
+
assert_equal expected, actual
|
|
236
|
+
end
|
|
230
237
|
|
|
231
|
-
|
|
238
|
+
def test_code_with_double_quoted_characters_1
|
|
232
239
|
|
|
233
|
-
|
|
240
|
+
input = <<-EOF_main
|
|
234
241
|
|
|
235
242
|
case "'": // " this is the comment "
|
|
236
243
|
EOF_main
|
|
237
|
-
|
|
244
|
+
expected = <<-EOF_main
|
|
238
245
|
|
|
239
246
|
case "'":
|
|
240
247
|
EOF_main
|
|
241
248
|
|
|
242
|
-
|
|
249
|
+
actual = strip(input, 'C')
|
|
243
250
|
|
|
244
|
-
|
|
245
|
-
|
|
251
|
+
assert_equal expected, actual
|
|
252
|
+
end
|
|
246
253
|
|
|
247
|
-
|
|
254
|
+
def test_code_with_double_quoted_characters_2
|
|
248
255
|
|
|
249
|
-
|
|
256
|
+
input = <<-EOF_main
|
|
250
257
|
|
|
251
258
|
case "\\"": // " this is the comment "
|
|
252
259
|
EOF_main
|
|
253
|
-
|
|
260
|
+
expected = <<-EOF_main
|
|
254
261
|
|
|
255
262
|
case "\\"":
|
|
256
263
|
EOF_main
|
|
257
264
|
|
|
258
|
-
|
|
265
|
+
actual = strip(input, 'C')
|
|
259
266
|
|
|
260
|
-
|
|
261
|
-
|
|
267
|
+
assert_equal expected, actual
|
|
268
|
+
end
|
|
262
269
|
|
|
263
|
-
|
|
270
|
+
def test_code_with_double_quoted_characters_3
|
|
264
271
|
|
|
265
|
-
|
|
272
|
+
input = <<-EOF_main
|
|
266
273
|
|
|
267
274
|
case "\\'": // " this is the comment "
|
|
268
275
|
EOF_main
|
|
269
|
-
|
|
276
|
+
expected = <<-EOF_main
|
|
270
277
|
|
|
271
278
|
case "\\'":
|
|
272
279
|
EOF_main
|
|
273
280
|
|
|
274
|
-
|
|
281
|
+
actual = strip(input, 'C')
|
|
275
282
|
|
|
276
|
-
|
|
277
|
-
|
|
283
|
+
assert_equal expected, actual
|
|
284
|
+
end
|
|
278
285
|
|
|
279
|
-
|
|
286
|
+
def test_code_with_double_quoted_characters_4
|
|
280
287
|
|
|
281
|
-
|
|
288
|
+
input = <<-EOF_main
|
|
282
289
|
|
|
283
290
|
case "\\\\": // " this is the comment "
|
|
284
291
|
EOF_main
|
|
285
|
-
|
|
292
|
+
expected = <<-EOF_main
|
|
286
293
|
|
|
287
294
|
case "\\\\":
|
|
288
295
|
EOF_main
|
|
289
296
|
|
|
290
|
-
|
|
297
|
+
actual = strip(input, 'C')
|
|
291
298
|
|
|
292
|
-
|
|
293
|
-
|
|
299
|
+
assert_equal expected, actual
|
|
300
|
+
end
|
|
294
301
|
|
|
295
|
-
|
|
302
|
+
def test_code_with_double_quoted_characters_5
|
|
296
303
|
|
|
297
|
-
|
|
304
|
+
input = <<-EOF_main
|
|
298
305
|
|
|
299
306
|
case "\\\\": // " this is the comment "
|
|
300
307
|
EOF_main
|
|
301
|
-
|
|
308
|
+
expected = <<-EOF_main
|
|
302
309
|
|
|
303
310
|
case "\\\\":
|
|
304
311
|
EOF_main
|
|
305
312
|
|
|
306
|
-
|
|
313
|
+
actual = strip(input, 'C')
|
|
307
314
|
|
|
308
|
-
|
|
309
|
-
|
|
315
|
+
assert_equal expected, actual
|
|
316
|
+
end
|
|
310
317
|
|
|
311
|
-
|
|
318
|
+
def test_simple_main_with_trailing_cppcomment
|
|
312
319
|
|
|
313
|
-
|
|
320
|
+
input = <<-EOF_main
|
|
314
321
|
#include <stdio.h>
|
|
315
322
|
int main(int argc, char* argv[])
|
|
316
323
|
{
|
|
317
324
|
return 0; // same as EXIT_SUCCESS
|
|
318
325
|
}
|
|
319
326
|
EOF_main
|
|
320
|
-
|
|
327
|
+
expected = <<-EOF_main
|
|
321
328
|
#include <stdio.h>
|
|
322
329
|
int main(int argc, char* argv[])
|
|
323
330
|
{
|
|
@@ -325,19 +332,19 @@ int main(int argc, char* argv[])
|
|
|
325
332
|
}
|
|
326
333
|
EOF_main
|
|
327
334
|
|
|
328
|
-
|
|
329
|
-
|
|
335
|
+
assert_equal expected, strip(input, 'C')
|
|
336
|
+
end
|
|
330
337
|
|
|
331
|
-
|
|
338
|
+
def test_simple_main_with_trailing_cppcomment_and_divide_maths
|
|
332
339
|
|
|
333
|
-
|
|
340
|
+
input = <<-EOF_main
|
|
334
341
|
#include <stdio.h>
|
|
335
342
|
int main(int argc, char* argv[])
|
|
336
343
|
{
|
|
337
344
|
return 0 / 1; // same as EXIT_SUCCESS
|
|
338
345
|
}
|
|
339
346
|
EOF_main
|
|
340
|
-
|
|
347
|
+
expected = <<-EOF_main
|
|
341
348
|
#include <stdio.h>
|
|
342
349
|
int main(int argc, char* argv[])
|
|
343
350
|
{
|
|
@@ -345,19 +352,19 @@ int main(int argc, char* argv[])
|
|
|
345
352
|
}
|
|
346
353
|
EOF_main
|
|
347
354
|
|
|
348
|
-
|
|
349
|
-
|
|
355
|
+
assert_equal expected, strip(input, 'C')
|
|
356
|
+
end
|
|
350
357
|
|
|
351
|
-
|
|
358
|
+
def test_simple_main_with_ccomment
|
|
352
359
|
|
|
353
|
-
|
|
360
|
+
input = <<-EOF_main
|
|
354
361
|
#include <stdio.h>
|
|
355
362
|
int main(int argc, char* argv[])
|
|
356
363
|
{
|
|
357
364
|
return 2; /* same as EXIT_SUCCESS */
|
|
358
365
|
}
|
|
359
366
|
EOF_main
|
|
360
|
-
|
|
367
|
+
expected = <<-EOF_main
|
|
361
368
|
#include <stdio.h>
|
|
362
369
|
int main(int argc, char* argv[])
|
|
363
370
|
{
|
|
@@ -365,38 +372,38 @@ int main(int argc, char* argv[])
|
|
|
365
372
|
}
|
|
366
373
|
EOF_main
|
|
367
374
|
|
|
368
|
-
|
|
369
|
-
|
|
375
|
+
assert_equal expected, strip(input, 'C')
|
|
376
|
+
end
|
|
370
377
|
|
|
371
|
-
|
|
378
|
+
def test_ccomment_inline
|
|
372
379
|
|
|
373
|
-
|
|
374
|
-
|
|
380
|
+
input = 'int i = func(/*x=*/x, /*y=*/y);'
|
|
381
|
+
expected = 'int i = func(x, y);'
|
|
375
382
|
|
|
376
|
-
|
|
377
|
-
|
|
383
|
+
assert_equal expected, strip(input, 'C')
|
|
384
|
+
end
|
|
378
385
|
|
|
379
|
-
|
|
386
|
+
def test_multiline_1
|
|
380
387
|
|
|
381
|
-
|
|
388
|
+
input = <<-EOF_main
|
|
382
389
|
|
|
383
390
|
/** Some function description
|
|
384
391
|
*/
|
|
385
392
|
int func();
|
|
386
393
|
EOF_main
|
|
387
|
-
|
|
394
|
+
expected = <<-EOF_main
|
|
388
395
|
|
|
389
396
|
|
|
390
397
|
|
|
391
398
|
int func();
|
|
392
399
|
EOF_main
|
|
393
400
|
|
|
394
|
-
|
|
395
|
-
|
|
401
|
+
assert_equal expected, strip(input, 'C')
|
|
402
|
+
end
|
|
396
403
|
|
|
397
|
-
|
|
404
|
+
def test_multiline_2
|
|
398
405
|
|
|
399
|
-
|
|
406
|
+
input = <<-EOF_main
|
|
400
407
|
|
|
401
408
|
/** Some function description
|
|
402
409
|
*/
|
|
@@ -408,7 +415,7 @@ int func();
|
|
|
408
415
|
|
|
409
416
|
int fn();
|
|
410
417
|
EOF_main
|
|
411
|
-
|
|
418
|
+
expected = <<-EOF_main
|
|
412
419
|
|
|
413
420
|
|
|
414
421
|
|
|
@@ -421,12 +428,12 @@ int func();
|
|
|
421
428
|
int fn();
|
|
422
429
|
EOF_main
|
|
423
430
|
|
|
424
|
-
|
|
425
|
-
|
|
431
|
+
assert_equal expected, strip(input, 'C')
|
|
432
|
+
end
|
|
426
433
|
|
|
427
|
-
|
|
434
|
+
def test_multiline_3
|
|
428
435
|
|
|
429
|
-
|
|
436
|
+
input = <<-EOF_main
|
|
430
437
|
|
|
431
438
|
/** Some function description
|
|
432
439
|
*
|
|
@@ -434,7 +441,7 @@ EOF_main
|
|
|
434
441
|
*/
|
|
435
442
|
int func();
|
|
436
443
|
EOF_main
|
|
437
|
-
|
|
444
|
+
expected = <<-EOF_main
|
|
438
445
|
|
|
439
446
|
|
|
440
447
|
|
|
@@ -443,12 +450,12 @@ EOF_main
|
|
|
443
450
|
int func();
|
|
444
451
|
EOF_main
|
|
445
452
|
|
|
446
|
-
|
|
447
|
-
|
|
453
|
+
assert_equal expected, strip(input, 'C')
|
|
454
|
+
end
|
|
448
455
|
|
|
449
|
-
|
|
456
|
+
def test_multiline_4
|
|
450
457
|
|
|
451
|
-
|
|
458
|
+
input = <<-EOF_main
|
|
452
459
|
|
|
453
460
|
/** //////////////////////////////////
|
|
454
461
|
*
|
|
@@ -465,42 +472,72 @@ EOF_main
|
|
|
465
472
|
int func();
|
|
466
473
|
EOF_main
|
|
467
474
|
|
|
468
|
-
|
|
469
|
-
|
|
475
|
+
assert_equal expected, strip(input, 'C')
|
|
476
|
+
end
|
|
470
477
|
|
|
471
|
-
|
|
478
|
+
def test_comments_in_strings_1
|
|
472
479
|
|
|
473
|
-
|
|
480
|
+
input = <<-EOF_main
|
|
474
481
|
|
|
475
482
|
string s("//"); // THIS is the comment
|
|
476
483
|
EOF_main
|
|
477
|
-
|
|
484
|
+
expected = <<-EOF_main
|
|
478
485
|
|
|
479
486
|
string s("//");
|
|
480
487
|
EOF_main
|
|
481
|
-
|
|
488
|
+
actual = strip(input, 'C')
|
|
482
489
|
|
|
483
|
-
|
|
484
|
-
|
|
490
|
+
assert_equal expected, actual
|
|
491
|
+
end
|
|
485
492
|
|
|
486
|
-
|
|
493
|
+
def test_comments_in_strings_2
|
|
487
494
|
|
|
488
|
-
|
|
495
|
+
input = <<-EOF_main
|
|
489
496
|
|
|
490
497
|
string s("/*"); // THIS is the comment
|
|
491
498
|
EOF_main
|
|
492
|
-
|
|
499
|
+
expected = <<-EOF_main
|
|
493
500
|
|
|
494
501
|
string s("/*");
|
|
495
502
|
EOF_main
|
|
496
|
-
|
|
503
|
+
actual = strip(input, 'C')
|
|
497
504
|
|
|
498
|
-
|
|
499
|
-
|
|
505
|
+
assert_equal expected, actual
|
|
506
|
+
end
|
|
507
|
+
|
|
508
|
+
def test_comments_in_strings_3
|
|
509
|
+
|
|
510
|
+
input = <<-EOF_main
|
|
500
511
|
|
|
501
|
-
|
|
512
|
+
string s("/"); // THIS is the comment
|
|
513
|
+
EOF_main
|
|
514
|
+
expected = <<-EOF_main
|
|
515
|
+
|
|
516
|
+
string s("/");
|
|
517
|
+
EOF_main
|
|
518
|
+
actual = strip(input, 'C')
|
|
502
519
|
|
|
503
|
-
|
|
520
|
+
assert_equal expected, actual
|
|
521
|
+
end
|
|
522
|
+
|
|
523
|
+
def test_comments_in_strings_4
|
|
524
|
+
|
|
525
|
+
input = <<-EOF_main
|
|
526
|
+
|
|
527
|
+
string s("/* this is a comment */"); // this is THE comment
|
|
528
|
+
EOF_main
|
|
529
|
+
expected = <<-EOF_main
|
|
530
|
+
|
|
531
|
+
string s("/* this is a comment */");
|
|
532
|
+
EOF_main
|
|
533
|
+
actual = strip(input, 'C')
|
|
534
|
+
|
|
535
|
+
assert_equal expected, actual
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
def test_real_sample_1
|
|
539
|
+
|
|
540
|
+
input = <<-EOF_main
|
|
504
541
|
/* /////////////////////////////////////////////////////////////////////////
|
|
505
542
|
* includes
|
|
506
543
|
*
|
|
@@ -531,7 +568,7 @@ EOF_main
|
|
|
531
568
|
# pragma warning(disable : 4702) // suppresses "unreachable code"
|
|
532
569
|
#endif /* compiler */
|
|
533
570
|
EOF_main
|
|
534
|
-
|
|
571
|
+
expected = <<-EOF_main
|
|
535
572
|
|
|
536
573
|
|
|
537
574
|
|
|
@@ -562,14 +599,14 @@ EOF_main
|
|
|
562
599
|
# pragma warning(disable : 4702)
|
|
563
600
|
#endif
|
|
564
601
|
EOF_main
|
|
565
|
-
|
|
602
|
+
actual = strip(input, 'C')
|
|
566
603
|
|
|
567
|
-
|
|
568
|
-
|
|
604
|
+
assert_equal expected, actual
|
|
605
|
+
end
|
|
569
606
|
|
|
570
|
-
|
|
607
|
+
def test_real_sample_2
|
|
571
608
|
|
|
572
|
-
|
|
609
|
+
input = <<-EOF_main
|
|
573
610
|
/* /////////////////////////////////////////////////////////////////////////
|
|
574
611
|
* includes
|
|
575
612
|
*/
|
|
@@ -616,7 +653,7 @@ EOF_main
|
|
|
616
653
|
# include <crtdbg.h>
|
|
617
654
|
#endif
|
|
618
655
|
EOF_main
|
|
619
|
-
|
|
656
|
+
expected = <<-EOF_main
|
|
620
657
|
|
|
621
658
|
|
|
622
659
|
|
|
@@ -664,12 +701,12 @@ EOF_main
|
|
|
664
701
|
#endif
|
|
665
702
|
EOF_main
|
|
666
703
|
|
|
667
|
-
|
|
668
|
-
|
|
704
|
+
assert_equal expected, strip(input, 'C')
|
|
705
|
+
end
|
|
669
706
|
|
|
670
|
-
|
|
707
|
+
def test_real_sample_3
|
|
671
708
|
|
|
672
|
-
|
|
709
|
+
input = <<-EOF_main
|
|
673
710
|
/* /////////////////////////////////////////////////////////////////////////
|
|
674
711
|
* File: src/fmt_cache.cpp
|
|
675
712
|
*
|
|
@@ -752,7 +789,7 @@ EOF_main
|
|
|
752
789
|
#include <new>
|
|
753
790
|
EOF_main
|
|
754
791
|
|
|
755
|
-
|
|
792
|
+
expected = <<-EOF_main
|
|
756
793
|
|
|
757
794
|
|
|
758
795
|
|
|
@@ -835,14 +872,12 @@ EOF_main
|
|
|
835
872
|
#include <new>
|
|
836
873
|
EOF_main
|
|
837
874
|
|
|
838
|
-
|
|
875
|
+
assert_equal expected, strip(input, 'C')
|
|
876
|
+
end
|
|
839
877
|
|
|
840
|
-
|
|
841
|
-
end
|
|
842
|
-
|
|
843
|
-
def test_real_sample_4
|
|
878
|
+
def test_real_sample_4
|
|
844
879
|
|
|
845
|
-
|
|
880
|
+
input = <<-EOF_main
|
|
846
881
|
/* /////////////////////////////////////////////////////////////////////////
|
|
847
882
|
* File: src/fmt_cache.cpp
|
|
848
883
|
*
|
|
@@ -1547,7 +1582,7 @@ pattern_t pattern_record_t::pattern() const
|
|
|
1547
1582
|
/* ///////////////////////////// end of file //////////////////////////// */
|
|
1548
1583
|
EOF_main
|
|
1549
1584
|
|
|
1550
|
-
|
|
1585
|
+
expected = <<-EOF_main
|
|
1551
1586
|
|
|
1552
1587
|
|
|
1553
1588
|
|
|
@@ -2252,12 +2287,12 @@ pattern_t pattern_record_t::pattern() const
|
|
|
2252
2287
|
|
|
2253
2288
|
EOF_main
|
|
2254
2289
|
|
|
2255
|
-
|
|
2256
|
-
|
|
2290
|
+
assert_equal expected, strip(input, 'C')
|
|
2291
|
+
end
|
|
2257
2292
|
|
|
2258
|
-
|
|
2293
|
+
def test_real_sample_5
|
|
2259
2294
|
|
|
2260
|
-
|
|
2295
|
+
input = <<-EOF_main
|
|
2261
2296
|
/*****************************************************************************
|
|
2262
2297
|
/* Start of crcmodel.c
|
|
2263
2298
|
/*****************************************************************************
|
|
@@ -2303,7 +2338,7 @@ LOCAL ulong reflect (ulong v, int b)
|
|
|
2303
2338
|
/* Returns the value v with the bottom b [0,32] bits reflected. */
|
|
2304
2339
|
/* Example: reflect(0x3e23L,3) == 0x3e26 */
|
|
2305
2340
|
EOF_main
|
|
2306
|
-
|
|
2341
|
+
expected = <<-EOF_main
|
|
2307
2342
|
|
|
2308
2343
|
|
|
2309
2344
|
|
|
@@ -2349,14 +2384,14 @@ LOCAL ulong reflect (ulong v, int b)
|
|
|
2349
2384
|
|
|
2350
2385
|
|
|
2351
2386
|
EOF_main
|
|
2352
|
-
|
|
2387
|
+
actual = strip(input, 'C')
|
|
2353
2388
|
|
|
2354
|
-
|
|
2355
|
-
|
|
2389
|
+
assert_equal expected, actual
|
|
2390
|
+
end
|
|
2356
2391
|
|
|
2357
|
-
|
|
2392
|
+
def test_real_sample_6
|
|
2358
2393
|
|
|
2359
|
-
|
|
2394
|
+
input = <<-EOF_main
|
|
2360
2395
|
|
|
2361
2396
|
|
|
2362
2397
|
|
|
@@ -2444,8 +2479,6 @@ namespace {
|
|
|
2444
2479
|
|
|
2445
2480
|
default:
|
|
2446
2481
|
// Check for control characters and invalid utf-8
|
|
2447
|
-
EOF_main
|
|
2448
|
-
x1 = <<-EOF_main
|
|
2449
2482
|
// Escape control characters in standard ascii
|
|
2450
2483
|
// see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
|
|
2451
2484
|
if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) {
|
|
@@ -2646,7 +2679,7 @@ x1 = <<-EOF_main
|
|
|
2646
2679
|
}
|
|
2647
2680
|
EOF_main
|
|
2648
2681
|
|
|
2649
|
-
|
|
2682
|
+
expected = <<-EOF_main
|
|
2650
2683
|
|
|
2651
2684
|
|
|
2652
2685
|
|
|
@@ -2734,9 +2767,6 @@ namespace {
|
|
|
2734
2767
|
|
|
2735
2768
|
default:
|
|
2736
2769
|
|
|
2737
|
-
EOF_main
|
|
2738
|
-
x1 = <<-EOF_main
|
|
2739
|
-
|
|
2740
2770
|
|
|
2741
2771
|
|
|
2742
2772
|
if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) {
|
|
@@ -2937,14 +2967,14 @@ x1 = <<-EOF_main
|
|
|
2937
2967
|
}
|
|
2938
2968
|
EOF_main
|
|
2939
2969
|
|
|
2940
|
-
|
|
2970
|
+
actual = strip(input, 'C')
|
|
2941
2971
|
|
|
2942
|
-
|
|
2943
|
-
|
|
2972
|
+
assert_equal expected, actual
|
|
2973
|
+
end
|
|
2944
2974
|
|
|
2945
|
-
|
|
2975
|
+
def test_real_sample_7
|
|
2946
2976
|
|
|
2947
|
-
|
|
2977
|
+
input = <<-EOF_main
|
|
2948
2978
|
#if defined(RECLS_CPP_NO_METHOD_PROPERTY_SUPPORT)
|
|
2949
2979
|
/* Do not define RECLS_CPP_METHOD_PROPERTY_SUPPORT */
|
|
2950
2980
|
#else /* ? RECLS_CPP_???_METHOD_PROPERTY_SUPPORT */
|
|
@@ -2966,7 +2996,7 @@ EOF_main
|
|
|
2966
2996
|
#endif /* RECLS_CPP_???_METHOD_PROPERTY_SUPPORT */
|
|
2967
2997
|
|
|
2968
2998
|
EOF_main
|
|
2969
|
-
|
|
2999
|
+
expected = <<-EOF_main
|
|
2970
3000
|
#if defined(RECLS_CPP_NO_METHOD_PROPERTY_SUPPORT)
|
|
2971
3001
|
|
|
2972
3002
|
#else
|
|
@@ -2989,14 +3019,14 @@ EOF_main
|
|
|
2989
3019
|
|
|
2990
3020
|
EOF_main
|
|
2991
3021
|
|
|
2992
|
-
|
|
3022
|
+
actual = strip(input, 'C')
|
|
2993
3023
|
|
|
2994
|
-
|
|
2995
|
-
|
|
3024
|
+
assert_equal expected, actual
|
|
3025
|
+
end
|
|
2996
3026
|
|
|
2997
|
-
|
|
3027
|
+
def test_real_sample_8
|
|
2998
3028
|
|
|
2999
|
-
|
|
3029
|
+
input = <<-EOF_main
|
|
3000
3030
|
/*****************************************************************************
|
|
3001
3031
|
/* Start of crcmodel.c
|
|
3002
3032
|
/*****************************************************************************
|
|
@@ -3141,7 +3171,7 @@ ulong cm_tab (p_cm_t p_cm, int index)
|
|
|
3141
3171
|
/* End of crcmodel.c */
|
|
3142
3172
|
/******************************************************************************/
|
|
3143
3173
|
EOF_main
|
|
3144
|
-
|
|
3174
|
+
expected = <<-EOF_main
|
|
3145
3175
|
|
|
3146
3176
|
|
|
3147
3177
|
|
|
@@ -3287,14 +3317,14 @@ ulong cm_tab (p_cm_t p_cm, int index)
|
|
|
3287
3317
|
|
|
3288
3318
|
EOF_main
|
|
3289
3319
|
|
|
3290
|
-
|
|
3320
|
+
actual = strip(input, 'C')
|
|
3291
3321
|
|
|
3292
|
-
|
|
3293
|
-
|
|
3322
|
+
assert_equal expected, actual
|
|
3323
|
+
end
|
|
3294
3324
|
|
|
3295
|
-
|
|
3325
|
+
def test_real_sample_9
|
|
3296
3326
|
|
|
3297
|
-
|
|
3327
|
+
input = <<-EOF_main
|
|
3298
3328
|
/*
|
|
3299
3329
|
* This source file is part of the bstring string library. This code was
|
|
3300
3330
|
* written by Paul Hsieh in 2002-2010, and is covered by either the 3-clause
|
|
@@ -3436,7 +3466,7 @@ int ret = 0;
|
|
|
3436
3466
|
}
|
|
3437
3467
|
|
|
3438
3468
|
EOF_main
|
|
3439
|
-
|
|
3469
|
+
expected = <<-EOF_main
|
|
3440
3470
|
|
|
3441
3471
|
|
|
3442
3472
|
|
|
@@ -3579,14 +3609,14 @@ int ret = 0;
|
|
|
3579
3609
|
|
|
3580
3610
|
EOF_main
|
|
3581
3611
|
|
|
3582
|
-
|
|
3612
|
+
actual = strip(input, 'C')
|
|
3583
3613
|
|
|
3584
|
-
|
|
3585
|
-
|
|
3614
|
+
assert_equal expected, actual
|
|
3615
|
+
end
|
|
3586
3616
|
|
|
3587
|
-
|
|
3617
|
+
def test_real_sample_10
|
|
3588
3618
|
|
|
3589
|
-
|
|
3619
|
+
input = <<-EOF_main
|
|
3590
3620
|
// Scintilla source code edit control
|
|
3591
3621
|
/** @file CharacterSet.h
|
|
3592
3622
|
** Encapsulates a set of characters. Used to test if a character is within a set.
|
|
@@ -3647,7 +3677,7 @@ public:
|
|
|
3647
3677
|
};
|
|
3648
3678
|
EOF_main
|
|
3649
3679
|
|
|
3650
|
-
|
|
3680
|
+
expected = <<-EOF_main
|
|
3651
3681
|
|
|
3652
3682
|
|
|
3653
3683
|
|
|
@@ -3708,10 +3738,10 @@ public:
|
|
|
3708
3738
|
};
|
|
3709
3739
|
EOF_main
|
|
3710
3740
|
|
|
3711
|
-
|
|
3741
|
+
actual = strip(input, 'C')
|
|
3712
3742
|
|
|
3713
|
-
|
|
3714
|
-
|
|
3743
|
+
assert_equal expected, actual
|
|
3744
|
+
end
|
|
3715
3745
|
end
|
|
3716
3746
|
|
|
3717
3747
|
# ############################## end of file ############################# #
|