|
| 1 | +from esp32_ulp.util import split_tokens |
| 2 | + |
| 3 | +tests = [] |
| 4 | + |
| 5 | + |
| 6 | +def test(param): |
| 7 | + """ |
| 8 | + the @test decorator |
| 9 | + """ |
| 10 | + tests.append(param) |
| 11 | + |
| 12 | + |
| 13 | +@test |
| 14 | +def test_split_tokens(): |
| 15 | + assert split_tokens("") == [] |
| 16 | + assert split_tokens("t") == ['t'] |
| 17 | + assert split_tokens("test") == ['test'] |
| 18 | + assert split_tokens("t t") == ['t', ' ', 't'] |
| 19 | + assert split_tokens("t,t") == ['t', ',', 't'] |
| 20 | + assert split_tokens("test(arg)") == ['test', '(', 'arg', ')'] |
| 21 | + assert split_tokens("test(arg,arg2)") == ['test', '(', 'arg', ',', 'arg2', ')'] |
| 22 | + assert split_tokens("test(arg,arg2)") == ['test', '(', 'arg', ',', 'arg2', ')'] |
| 23 | + assert split_tokens(" test( arg, arg2)") == [' ', 'test', '(', ' ', 'arg', ',', ' ', 'arg2', ')'] |
| 24 | + assert split_tokens(" test( arg ) ") == [' ', 'test', '(', ' ', 'arg', ' ', ')', ' '] |
| 25 | + assert split_tokens("\t test \t ") == ['\t ', 'test', " \t "] |
| 26 | + assert split_tokens("test\nrow2") == ['test', "\n", "row2"] |
| 27 | + |
| 28 | + # split_token does not support comments. should generally only be used after comments are already stripped |
| 29 | + assert split_tokens("test(arg /*comment*/)") == ['test', '(', 'arg', ' ', '/', '*', 'comment', '*', '/', ')'] |
| 30 | + assert split_tokens("#test") == ['#', 'test'] |
| 31 | + |
| 32 | + |
| 33 | +if __name__ == '__main__': |
| 34 | + # run all methods marked with @test |
| 35 | + for t in tests: |
| 36 | + t() |
0 commit comments