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