2015-03-25 23:10:09 +00:00
|
|
|
# make sure syntax error works correctly for bad const definition
|
2015-03-01 12:06:24 +00:00
|
|
|
|
2016-09-27 13:34:21 +10:00
|
|
|
from micropython import const
|
|
|
|
|
2020-03-22 21:26:08 -05:00
|
|
|
|
2015-03-25 23:10:09 +00:00
|
|
|
def test_syntax(code):
|
|
|
|
try:
|
|
|
|
exec(code)
|
|
|
|
except SyntaxError:
|
|
|
|
print("SyntaxError")
|
|
|
|
|
2020-03-22 21:26:08 -05:00
|
|
|
|
2015-03-25 23:10:09 +00:00
|
|
|
# argument not a constant
|
|
|
|
test_syntax("a = const(x)")
|
|
|
|
|
|
|
|
# redefined constant
|
|
|
|
test_syntax("A = const(1); A = const(2)")
|
2020-04-06 12:19:03 +10:00
|
|
|
|
|
|
|
# these operations are not supported within const
|
|
|
|
test_syntax("A = const(1 @ 2)")
|
|
|
|
test_syntax("A = const(1 / 2)")
|
2020-04-07 12:23:08 +10:00
|
|
|
test_syntax("A = const(1 ** -2)")
|
2020-04-06 12:19:03 +10:00
|
|
|
test_syntax("A = const(1 << -2)")
|
|
|
|
test_syntax("A = const(1 >> -2)")
|
|
|
|
test_syntax("A = const(1 % 0)")
|
|
|
|
test_syntax("A = const(1 // 0)")
|