github.com/goplus/gossa@v0.3.25/gopbuild/build_test.go (about) 1 package gopbuild 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/goplus/gossa" 8 ) 9 10 var test_gop = `println "Go+"` 11 var test_gop_go = `package main 12 13 import fmt "fmt" 14 15 func main() { 16 //line main.gop:1 17 fmt.Println("Go+") 18 } 19 ` 20 21 func TestGop(t *testing.T) { 22 ctx := gossa.NewContext(0) 23 data, err := BuildFile(ctx, "main.gop", test_gop) 24 if err != nil { 25 t.Fatalf("build gop error: %v", err) 26 } 27 if string(data) != test_gop_go { 28 fmt.Println("build gop error:") 29 fmt.Println(string(data)) 30 t.Fail() 31 } 32 } 33 34 var test_big = `a := 1/2r 35 println a+1/2r 36 ` 37 var test_big_go = `package main 38 39 import ( 40 fmt "fmt" 41 ng "github.com/goplus/gop/builtin/ng" 42 big "math/big" 43 ) 44 45 func main() { 46 //line main.gop:1 47 a := ng.Bigrat_Init__2(big.NewRat(1, 2)) 48 //line main.gop:2 49 fmt.Println(a.Gop_Add(ng.Bigrat_Init__2(big.NewRat(1, 2)))) 50 } 51 ` 52 53 func TestBig(t *testing.T) { 54 ctx := gossa.NewContext(0) 55 data, err := BuildFile(ctx, "main.gop", test_big) 56 if err != nil { 57 t.Fatalf("build gop error: %v", err) 58 } 59 if string(data) != test_big_go { 60 fmt.Println("build gop error:") 61 fmt.Println(string(data)) 62 t.Fail() 63 } 64 }