Skip to content

Commit 38b54b6

Browse files
committed
tests/micropython: Add tests for const names being replaced in parser.
1 parent 3f0c1c2 commit 38b54b6

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

tests/micropython/const2.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# check that consts are not replaced in anything except standalone identifiers
2+
3+
X = const(1)
4+
Y = const(2)
5+
Z = const(3)
6+
7+
# import that uses a constant
8+
import micropython as X
9+
print(globals()['X'])
10+
11+
# function name that matches a constant
12+
def X():
13+
print('function X', X)
14+
globals()['X']()
15+
16+
# arguments that match a constant
17+
def f(X, *Y, **Z):
18+
pass
19+
f(1)
20+
21+
# class name that matches a constant
22+
class X:
23+
def f(self):
24+
print('class X', X)
25+
globals()['X']().f()
26+
27+
# constant within a class
28+
class A:
29+
C1 = const(4)
30+
def X(self):
31+
print('method X', Y, C1, self.C1)
32+
A().X()

tests/micropython/const2.py.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<module 'micropython'>
2+
function X 1
3+
class X 1
4+
method X 2 4 4

0 commit comments

Comments
 (0)