From 362f7c9c45598b429c92e67756f41b690043e0c4 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 22 Mar 2024 16:59:25 +0100 Subject: feat: add initial support for import, provide minimal fmt (#6) The `import` statement is now parsed. It only provides minimal support for the `fmt` package (only `Println` symbol is defined). This should be sufficient to pass a few tests. Full support of package namespaces, source and binary imports will be supported later, based on this work. --- parser/interpreter_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'parser/interpreter_test.go') diff --git a/parser/interpreter_test.go b/parser/interpreter_test.go index df44fae..a459359 100644 --- a/parser/interpreter_test.go +++ b/parser/interpreter_test.go @@ -211,7 +211,7 @@ func TestStruct(t *testing.T) { } func TestType(t *testing.T) { - src0 := `type( + src0 := `type ( I int S string ) @@ -239,3 +239,19 @@ func TestVar(t *testing.T) { ); a+b+c`, res: "16"}, }) } + +func TestImport(t *testing.T) { + src0 := `import ( + "fmt" +) +` + run(t, []etest{ + {src: "fmt.Println(4)", err: "symbol not found: fmt"}, + {src: `import "xxx"`, err: "package not found: xxx"}, + {src: `import "fmt"; fmt.Println(4)`, res: ""}, + {src: src0 + "fmt.Println(4)", res: ""}, + {src: `func main() {import "fmt"; fmt.Println("hello")}`, err: "unexpected import"}, + {src: `import m "fmt"; m.Println(4)`, res: ""}, + {src: `import . "fmt"; Println(4)`, res: ""}, + }) +} -- cgit v1.2.3