From 69d81e61aeefaa77253ce6e62434bbf1902c7f4b Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Wed, 3 Oct 2018 17:24:57 +0200 Subject: [PATCH] fix import test --- _test/src0.go | 2 +- interp/interp_test.go | 716 +++++++++++++++++++++--------------------- 2 files changed, 359 insertions(+), 359 deletions(-) diff --git a/_test/src0.go b/_test/src0.go index 80931e63..cd5fc6e1 100644 --- a/_test/src0.go +++ b/_test/src0.go @@ -1,6 +1,6 @@ package main -import "github.com/containous/gi/_test/provider" +import "github.com/containous/dyngo/_test/provider" func main() { provider.Sample() diff --git a/interp/interp_test.go b/interp/interp_test.go index 0ec3abd4..4e15bc70 100644 --- a/interp/interp_test.go +++ b/interp/interp_test.go @@ -2,32 +2,6 @@ package interp // Do not edit! File generated by ../_test/gen_example.sh -func Example_a1() { - src := ` -package main - -func main() { - a := [6]int{1, 2, 3, 4, 5, 6} - println(a[1]) // 2 - for i, v := range a { - println(v) - if i == 3 { - break - } - } -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 2 - // 1 - // 2 - // 3 - // 4 -} - func Example_a10() { src := ` package main @@ -151,6 +125,32 @@ func main() { } +func Example_a1() { + src := ` +package main + +func main() { + a := [6]int{1, 2, 3, 4, 5, 6} + println(a[1]) // 2 + for i, v := range a { + println(v) + if i == 3 { + break + } + } +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 2 + // 1 + // 2 + // 3 + // 4 +} + func Example_a2() { src := ` package main @@ -357,6 +357,20 @@ func main() { // 1 2 } +func Example_bool0() { + src := ` +package main + +import "fmt" + +func main() { + fmt.Println(true) +}` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + +} + func Example_bool() { src := ` package main @@ -374,20 +388,6 @@ func main() { // false true } -func Example_bool0() { - src := ` -package main - -import "fmt" - -func main() { - fmt.Println(true) -}` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - -} - func Example_chan0() { src := ` package main @@ -630,30 +630,6 @@ func main() { println(a, b, c) } // 1 2 3 } -func Example_cont() { - src := ` -package main - -func main() { - for i := 0; i < 10; i++ { - if i < 5 { - continue - } - println(i) - } -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 5 - // 6 - // 7 - // 8 - // 9 -} - func Example_cont0() { src := ` package main @@ -716,6 +692,30 @@ func main() { // 10 } +func Example_cont() { + src := ` +package main + +func main() { + for i := 0; i < 10; i++ { + if i < 5 { + continue + } + println(i) + } +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 5 + // 6 + // 7 + // 8 + // 9 +} + func Example_export0() { src := ` package main @@ -742,27 +742,6 @@ func (s *Sample) Test() { } -func Example_fib() { - src := ` -package main - -// Compute fibonacci numbers, no memoization -func fib(n int) int { - if n < 2 { - return n - } - return fib(n-2) + fib(n-1) -} - -func main() { - println(fib(35)) - //println(fib(10)) -}` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - -} - func Example_fib0() { src := ` package main @@ -786,6 +765,27 @@ func main() { // 3 } +func Example_fib() { + src := ` +package main + +// Compute fibonacci numbers, no memoization +func fib(n int) int { + if n < 2 { + return n + } + return fib(n-2) + fib(n-1) +} + +func main() { + println(fib(35)) + //println(fib(10)) +}` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + +} + func Example_for0() { src := ` package main @@ -862,23 +862,6 @@ func main() { // 4 } -func Example_fun() { - src := ` -package main - -func f(i int) int { return i + 15 } - -func main() { - println(f(4)) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 19 -} - func Example_fun2() { src := ` package main @@ -937,6 +920,23 @@ func main() { // ok } +func Example_fun() { + src := ` +package main + +func f(i int) int { return i + 15 } + +func main() { + println(f(4)) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 19 +} + func Example_goroutine() { src := ` package main @@ -1181,38 +1181,6 @@ func main() { } -func Example_iota() { - src := ` -package main - -import "fmt" - -const ( - Foo = iota - Bar - Baz -) - -const ( - Asm = iota - C - Java - Go -) - -func main() { - fmt.Println(Foo, Bar, Baz) - fmt.Println(Asm, C, Java, Go) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 0 1 2 - // 0 1 2 3 -} - func Example_iota0() { src := ` package main @@ -1245,6 +1213,38 @@ func main() { // 0 1 2 3 } +func Example_iota() { + src := ` +package main + +import "fmt" + +const ( + Foo = iota + Bar + Baz +) + +const ( + Asm = iota + C + Java + Go +) + +func main() { + fmt.Println(Foo, Bar, Baz) + fmt.Println(Asm, C, Java, Go) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 0 1 2 + // 0 1 2 3 +} + func Example_ioutil() { src := ` package main @@ -1317,25 +1317,6 @@ func f(i int) int { return i + 1 } // 6 } -func Example_map() { - src := ` -package main - -type Dict map[string]string - -func main() { - dict := make(Dict) - dict["truc"] = "machin" - println(dict["truc"]) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // machin -} - func Example_map2() { src := ` package main @@ -1408,6 +1389,25 @@ func main() { // false } +func Example_map() { + src := ` +package main + +type Dict map[string]string + +func main() { + dict := make(Dict) + dict["truc"] = "machin" + println(dict["truc"]) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // machin +} + func Example_math0() { src := ` package main @@ -1428,28 +1428,6 @@ func main() { // -1 } -func Example_method() { - src := ` -package main - -type Coord struct { - x, y int -} - -func (c Coord) dist() int { return c.x*c.x + c.y*c.y } - -func main() { - o := Coord{3, 4} - println(o.dist()) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 25 -} - func Example_method0() { src := ` package main @@ -1490,31 +1468,6 @@ func main() { // Baz Called } -func Example_method1() { - src := ` -package main - -type Sample struct { - Name string -} - -func (s *Sample) foo(i int) { - println("in foo", s.Name, i) -} - -func main() { - sample := Sample{"hello"} - s := &sample - s.foo(3) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // in foo hello 3 -} - func Example_method10() { src := ` package main @@ -1559,6 +1512,31 @@ type Coord struct { // 25 } +func Example_method1() { + src := ` +package main + +type Sample struct { + Name string +} + +func (s *Sample) foo(i int) { + println("in foo", s.Name, i) +} + +func main() { + sample := Sample{"hello"} + s := &sample + s.foo(3) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // in foo hello 3 +} + func Example_method2() { src := ` package main @@ -1795,6 +1773,28 @@ func (c Coord) dist() int { return c.x*c.x + c.y*c.y } // 25 } +func Example_method() { + src := ` +package main + +type Coord struct { + x, y int +} + +func (c Coord) dist() int { return c.x*c.x + c.y*c.y } + +func main() { + o := Coord{3, 4} + println(o.dist()) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 25 +} + func Example_neg0() { src := ` package main @@ -2018,26 +2018,6 @@ func main() { // 5 } -func Example_ptr5() { - src := ` -package main - -type Foo struct { - val int -} - -func main() { - var a = &Foo{3} - println(a.val) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 3 -} - func Example_ptr5a() { src := ` package main @@ -2059,6 +2039,26 @@ func main() { // 3 } +func Example_ptr5() { + src := ` +package main + +type Foo struct { + val int +} + +func main() { + var a = &Foo{3} + println(a.val) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 3 +} + func Example_ptr6() { src := ` package main @@ -2146,25 +2146,6 @@ func main() { // 2 3 } -func Example_run1() { - src := ` -package main - -func f() (int, int) { return 2, 3 } - -func g(i, j int) int { return i + j } - -func main() { - println(g(f())) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 5 -} - func Example_run10() { src := ` package main @@ -2237,6 +2218,25 @@ func f(a int) (int, int) { // 4 5 } +func Example_run1() { + src := ` +package main + +func f() (int, int) { return 2, 3 } + +func g(i, j int) int { return i + j } + +func main() { + println(g(f())) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 5 +} + func Example_run4() { src := ` package main @@ -2530,30 +2530,6 @@ func main() { // [6 7] } -func Example_server() { - src := ` -package main - -import ( - "fmt" - "net/http" -) - -var v string = "v1.0" - -func main() { - a := "hello " - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "Welcome to my website! ", a, v) - }) - - http.ListenAndServe(":8080", nil) -}` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - -} - func Example_server0() { src := ` package main @@ -2579,33 +2555,6 @@ func main() { } -func Example_server1() { - src := ` -package main - -import ( - "fmt" - "net/http" -) - -type Middleware struct { - Name string -} - -func (m *Middleware) Handler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w, "Welcome to my website", m.Name) -} - -func main() { - m := &Middleware{"Test"} - http.HandleFunc("/", m.Handler) - http.ListenAndServe(":8080", nil) -}` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - -} - func Example_server1a() { src := ` package main @@ -2639,6 +2588,33 @@ func main() { } +func Example_server1() { + src := ` +package main + +import ( + "fmt" + "net/http" +) + +type Middleware struct { + Name string +} + +func (m *Middleware) Handler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "Welcome to my website", m.Name) +} + +func main() { + m := &Middleware{"Test"} + http.HandleFunc("/", m.Handler) + http.ListenAndServe(":8080", nil) +}` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + +} + func Example_server2() { src := ` package main @@ -2761,6 +2737,30 @@ func main() { } +func Example_server() { + src := ` +package main + +import ( + "fmt" + "net/http" +) + +var v string = "v1.0" + +func main() { + a := "hello " + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprint(w, "Welcome to my website! ", a, v) + }) + + http.ListenAndServe(":8080", nil) +}` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + +} + func Example_sieve() { src := ` // A concurrent prime sieve @@ -2819,7 +2819,7 @@ func Example_src0() { src := ` package main -import "github.com/containous/gi/_test/provider" +import "github.com/containous/dyngo/_test/provider" func main() { provider.Sample() @@ -2913,48 +2913,6 @@ func main() { // hello world } -func Example_struct() { - src := ` -package main - -type T struct { - f int - g int -} - -func main() { - a := T{7, 8} - println(a.f, a.g) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 7 8 -} - -func Example_struct0() { - src := ` -package main - -type T struct { - f int - g int -} - -func main() { - a := T{} - println(a.f, a.g) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 0 0 -} - func Example_struct0a() { src := ` package main @@ -2978,6 +2936,27 @@ func main() { // 8 } +func Example_struct0() { + src := ` +package main + +type T struct { + f int + g int +} + +func main() { + a := T{} + println(a.f, a.g) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 0 0 +} + func Example_struct1() { src := ` package main @@ -3148,6 +3127,27 @@ func main() { } +func Example_struct() { + src := ` +package main + +type T struct { + f int + g int +} + +func main() { + a := T{7, 8} + println(a.f, a.g) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // 7 8 +} + func Example_switch() { src := ` package main @@ -3438,22 +3438,6 @@ type T int // int } -func Example_var() { - src := ` -package main - -func main() { - var a, b, c int - println(a, b, c) -} -` - i := NewInterpreter(Opt{Entry: "main"}) - i.Eval(src) - - // Output: - // 0 0 0 -} - func Example_var2() { src := ` package main @@ -3502,25 +3486,20 @@ func main() { // 2 3 } -func Example_variadic() { +func Example_var() { src := ` package main -import "fmt" - -func f(a ...int) { - fmt.Println(a) -} - func main() { - f(1, 2, 3, 4) + var a, b, c int + println(a, b, c) } ` i := NewInterpreter(Opt{Entry: "main"}) i.Eval(src) // Output: - // [1 2 3 4] + // 0 0 0 } func Example_variadic0() { @@ -3543,3 +3522,24 @@ func main() { // Output: // hello [] } + +func Example_variadic() { + src := ` +package main + +import "fmt" + +func f(a ...int) { + fmt.Println(a) +} + +func main() { + f(1, 2, 3, 4) +} +` + i := NewInterpreter(Opt{Entry: "main"}) + i.Eval(src) + + // Output: + // [1 2 3 4] +}