diff options
| author | Marc Vertes <mvertes@free.fr> | 2024-03-22 16:59:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-22 16:59:25 +0100 |
| commit | 362f7c9c45598b429c92e67756f41b690043e0c4 (patch) | |
| tree | 59dd897446880912b4a2ca4a3a8d8c49e3553211 /parser/interpreter_test.go | |
| parent | bf2d6438e95c60946c64a6692e3dae1d836364a6 (diff) | |
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.
Diffstat (limited to 'parser/interpreter_test.go')
| -rw-r--r-- | parser/interpreter_test.go | 18 |
1 files changed, 17 insertions, 1 deletions
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: "<nil>"}, + {src: src0 + "fmt.Println(4)", res: "<nil>"}, + {src: `func main() {import "fmt"; fmt.Println("hello")}`, err: "unexpected import"}, + {src: `import m "fmt"; m.Println(4)`, res: "<nil>"}, + {src: `import . "fmt"; Println(4)`, res: "<nil>"}, + }) +} |
