Fix logic errors in match-statement Array & Dictionary Patterns

This commit is contained in:
cdemirer
2022-03-02 19:05:18 +08:00
parent b7a852a05d
commit 3afe50c2fa
5 changed files with 193 additions and 105 deletions

View File

@@ -0,0 +1,43 @@
func foo(x):
match x:
{"key1": "value1", "key2": "value2"}:
print('{"key1": "value1", "key2": "value2"}')
{"key1": "value1", "key2"}:
print('{"key1": "value1", "key2"}')
{"key1", "key2": "value2"}:
print('{"key1", "key2": "value2"}')
{"key1", "key2"}:
print('{"key1", "key2"}')
{"key1": "value1"}:
print('{"key1": "value1"}')
{"key1"}:
print('{"key1"}')
_:
print("wildcard")
func bar(x):
match x:
{0}:
print("0")
{1}:
print("1")
{2}:
print("2")
_:
print("wildcard")
func test():
foo({"key1": "value1", "key2": "value2"})
foo({"key1": "value1", "key2": ""})
foo({"key1": "", "key2": "value2"})
foo({"key1": "", "key2": ""})
foo({"key1": "value1"})
foo({"key1": ""})
foo({"key1": "value1", "key2": "value2", "key3": "value3"})
foo({"key1": "value1", "key3": ""})
foo({"key2": "value2"})
foo({"key3": ""})
bar({0: "0"})
bar({1: "1"})
bar({2: "2"})
bar({3: "3"})

View File

@@ -0,0 +1,15 @@
GDTEST_OK
{"key1": "value1", "key2": "value2"}
{"key1": "value1", "key2"}
{"key1", "key2": "value2"}
{"key1", "key2"}
{"key1": "value1"}
{"key1"}
wildcard
wildcard
wildcard
wildcard
0
1
2
wildcard

View File

@@ -0,0 +1,26 @@
func foo(x):
match x:
1, [2]:
print('1, [2]')
_:
print('wildcard')
func bar(x):
match x:
[1], [2], [3]:
print('[1], [2], [3]')
[4]:
print('[4]')
_:
print('wildcard')
func test():
foo(1)
foo([2])
foo(2)
bar([1])
bar([2])
bar([3])
bar([4])
bar([5])

View File

@@ -0,0 +1,9 @@
GDTEST_OK
1, [2]
1, [2]
wildcard
[1], [2], [3]
[1], [2], [3]
[1], [2], [3]
[4]
wildcard