-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gnolang): prints nil slices as undefined
- Loading branch information
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package gnolang | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPrintlnPrintNil(t *testing.T){ | ||
m := NewMachine("test", nil) | ||
|
||
c := `package test | ||
func main() { | ||
var a []string | ||
println(a) | ||
}` | ||
n := MustParseFile("main.go", c) | ||
m.RunFiles(n) | ||
m.RunMain() | ||
assertOutput(t, c, "undefined\n") | ||
} | ||
|
||
func TestPrintlnFunction(t *testing.T) { | ||
m := NewMachine("test", nil) | ||
|
||
c := `package test | ||
func foo(a, b int) int { | ||
return a + b | ||
} | ||
func main() { | ||
println(foo(1, 3)) | ||
}` | ||
|
||
n := MustParseFile("main.go", c) | ||
m.RunFiles(n) | ||
m.RunMain() | ||
|
||
assertOutput(t, c, "4\n") | ||
} | ||
|
||
func TestComposite(t *testing.T) { | ||
m := NewMachine("test", nil) | ||
c := `package test | ||
func main() { | ||
a, b, c, d := 1, 2, 3, 4 | ||
x := []int{ | ||
a: b, | ||
c: d, | ||
} | ||
println(x) | ||
}` | ||
|
||
n := MustParseFile("main.go", c) | ||
m.RunFiles(n) | ||
m.RunMain() | ||
|
||
assertOutput(t, c, "slice[(0 int),(2 int),(0 int),(4 int)]\n") | ||
} | ||
|
||
// TODO: Resolve runtime error | ||
// current output: g recover <nil> wtf | ||
func TestRecover5(t *testing.T) { | ||
m := NewMachine("test", nil) | ||
c := `package test | ||
func main() { | ||
f() | ||
} | ||
func f() { | ||
defer func() { println("f recover", recover()) }() | ||
defer g() | ||
panic("wtf") | ||
} | ||
func g() { | ||
println("g recover", recover()) | ||
}` | ||
|
||
n := MustParseFile("main.go", c) | ||
m.RunFiles(n) | ||
m.RunMain() | ||
|
||
assertOutput(t, c, "g recover wtf\nf recover wtf\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
func main() { | ||
var a []string | ||
println(a) | ||
} |