forked from micropython/micropython-esp32-ulp
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnocomment.py
60 lines (36 loc) · 1.18 KB
/
nocomment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
fromesp32_ulp.nocommentimportremove_comments
ORIG="""\
/*
* HEADER
*/
# single, full line comment
label: // another rest-of-line comment
nop /* partial line */
.string "try confusing /* with a comment start"
.string "should be there 1" /* another comment */
.string 'try confusing */ with a comment end'
.string "more confusing \\" /* should be there 2"
/* comment */
.string 'more confusing \\' */'
/***** FOOTER *****/
"""
EXPECTED="""\
label:
nop
.string "try confusing /* with a comment start"
.string "should be there 1"
.string 'try confusing */ with a comment end'
.string "more confusing \\" /* should be there 2"
.string 'more confusing \\' */'
"""
deftest_remove_comments():
lines_orig=ORIG.splitlines()
len_orig=len(lines_orig)
lines_expected=EXPECTED.splitlines()
len_expected=len(lines_expected)
lines_got=remove_comments(ORIG)
len_got=len(lines_got)
assertlen_orig==len_expected==len_got, \
"line count differs %d %d %d"% (len_orig, len_expected, len_got)
assertlines_expected==lines_got, "texts differ"
test_remove_comments()