Add a test for chained assignments

This commit is contained in:
Laria 2022-11-19 21:27:08 +01:00
parent 0267faede3
commit 7c5465d266
2 changed files with 63 additions and 0 deletions

View file

@ -66,6 +66,7 @@ functionaltest("type")
functionaltest("if")
functionaltest("while")
functionaltest("eq")
functionaltest("chained-assignments")
install(TARGETS apfl DESTINATION lib)
install(TARGETS apfl-bin DESTINATION bin)

View file

@ -0,0 +1,62 @@
===== script =====
# Simple chained assignment
a = b = "foo"
print a
print b
print ""
# Check return value of chained assignment. Also does local assignment `:=` work?
print ({
a = b := "bar"
})
print a
print b
print ""
# Throw a list matching in there
l = [x y] = [1 2]
print l
print x
print y
print ""
# Same as first two tests, but force using the matcher mechanism
[a] = [b] = ["foo"]
print a
print b
print ""
print ({
[a] = [b] := ["bar"]
})
print a
print b
===== output =====
foo
foo
bar
bar
foo
[
1
2
]
1
2
foo
foo
[
"bar"
]
bar
foo