lang: Port TestAstFunc2 to txtar format
This ports TestAstFunc2 from our home-grown content storage system to the txtar package. Since a single file can be used to represent the entire folder hierarchy, this makes it much easier to see and edit tests.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
-- main.mcl --
|
||||
import "fmt"
|
||||
|
||||
$funcgen1 = func($a, $d) {
|
||||
func($i) {
|
||||
fmt.printf("text: %s, count: %d", $a, $d + $i)
|
||||
}
|
||||
}
|
||||
|
||||
$funcgen2 = func() {
|
||||
func($b) {
|
||||
if $b == "" {
|
||||
$funcgen1("hello magic number", 42)
|
||||
} else {
|
||||
$funcgen1("hello " + $b, 13)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$some_bool = true
|
||||
$fn = if $some_bool {
|
||||
$funcgen2()
|
||||
} else {
|
||||
func($bb) {
|
||||
func($ii) {
|
||||
if $bb == "james" {
|
||||
"hello purpleidea"
|
||||
} else {
|
||||
if $bb == "" {
|
||||
"who is there?"
|
||||
} else {
|
||||
"hello " + $bb
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$fn1 = $fn("user")
|
||||
$fn2 = $fn("james")
|
||||
$fn3 = $fn("")
|
||||
|
||||
$out1 = $fn1(1)
|
||||
$out2 = $fn2(22)
|
||||
$out3 = $fn3(0)
|
||||
|
||||
test $out1 {}
|
||||
test $out2 {}
|
||||
test $out3 {}
|
||||
-- OUTPUT --
|
||||
Vertex: test[text: hello james, count: 35]
|
||||
Vertex: test[text: hello magic number, count: 42]
|
||||
Vertex: test[text: hello user, count: 14]
|
||||
Reference in New Issue
Block a user