summaryrefslogtreecommitdiff
path: root/parser/interpreter_test.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2023-11-10 22:08:46 +0100
committerMarc Vertes <mvertes@free.fr>2023-11-10 22:08:46 +0100
commitbec71a19e7d7cd0847d1cfa6ef2110d7301fcdd1 (patch)
tree7d977e9ad86c119603db88d3fdbf689a845ff8e5 /parser/interpreter_test.go
parent5220ccb741c7f3688731d3b3df6e5e851f50f5c5 (diff)
parser: implement support for var declarations
The full Go syntax is supported, blocks or line, mutiple comma separated variables, assignments. In local and global frame.
Diffstat (limited to 'parser/interpreter_test.go')
-rw-r--r--parser/interpreter_test.go29
1 files changed, 26 insertions, 3 deletions
diff --git a/parser/interpreter_test.go b/parser/interpreter_test.go
index 42223d4..edb6b0d 100644
--- a/parser/interpreter_test.go
+++ b/parser/interpreter_test.go
@@ -10,7 +10,10 @@ import (
"github.com/gnolang/parscan/scanner"
)
-type etest struct{ src, res, err string }
+type etest struct {
+ src, res, err string
+ skip bool
+}
var GoScanner *scanner.Scanner
@@ -21,6 +24,9 @@ func init() {
func gen(test etest) func(*testing.T) {
return func(t *testing.T) {
+ if test.skip {
+ t.Skip()
+ }
interp := parser.NewInterpreter(GoScanner)
errStr := ""
r, e := interp.Eval(test.src)
@@ -112,8 +118,8 @@ func TestFor(t *testing.T) {
}
func TestGoto(t *testing.T) {
- run(t, []etest{{
- src: `
+ run(t, []etest{
+ {src: `
func f(a int) int {
a = a+1
goto end
@@ -157,3 +163,20 @@ func TestSwitch(t *testing.T) {
{src: src1 + "f(6)", res: "0"},
})
}
+
+func TestVar(t *testing.T) {
+ run(t, []etest{
+ {src: "var a int; a", res: "0"},
+ {src: "var a, b, c int; a", res: "0"},
+ {src: "var a, b, c int; a + b", res: "0"},
+ {src: "var a, b, c int; a + b + c", res: "0"},
+ {src: "var a int = 2+1; a", res: "3"},
+ {src: "var a, b int = 2, 5; a+b", res: "7"},
+ {src: "var x = 5; x", res: "5"},
+ {src: "var a = 1; func f() int { var a, b int = 3, 4; return a+b}; a+f()", res: "8"},
+ {src: `var (
+ a, b int = 4+1, 3
+ c = 8
+); a+b+c`, res: "16"},
+ })
+}