Skip to content

Commit da40d22

Browse files
committed
Add/fix kernel_tests for the new execution semantics
1 parent 910ee8a commit da40d22

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

kernel_test.go

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,74 @@ func TestEvaluate(t *testing.T) {
7474
Output string
7575
}{
7676
{[]string{
77-
`import "fmt"`,
7877
"a := 1",
79-
"fmt.Println(a)",
80-
}, "1\n"},
78+
"a",
79+
}, "1"},
8180
{[]string{
8281
"a = 2",
83-
"fmt.Println(a)",
84-
}, "2\n"},
82+
"a + 3",
83+
}, "5"},
8584
{[]string{
8685
"func myFunc(x int) int {",
8786
" return x+1",
8887
"}",
89-
`fmt.Println("func defined")`,
90-
}, "func defined\n"},
88+
"myFunc(1)",
89+
}, "2"},
9190
{[]string{
9291
"b := myFunc(1)",
93-
"fmt.Println(b)",
94-
}, "2\n"},
92+
}, ""},
93+
{[]string{
94+
"type Rect struct {",
95+
" Width, Height int",
96+
"}",
97+
"Rect{10, 30}",
98+
}, "{10 30}"},
99+
{[]string{
100+
"type Rect struct {",
101+
" Width, Height int",
102+
"}",
103+
"&Rect{10, 30}",
104+
}, "&{10 30}"},
105+
{[]string{
106+
"func a(b int) (int, int) {",
107+
" return 2 + b, b",
108+
"}",
109+
"a(10)",
110+
}, "12"},
111+
{[]string{
112+
`import "errors"`,
113+
"func a() (interface{}, error) {",
114+
` return nil, errors.New("To err is human")`,
115+
"}",
116+
"a()",
117+
}, "To err is human"},
118+
{[]string{
119+
`c := []string{"gophernotes", "is", "super", "bad"}`,
120+
"c[:3]",
121+
}, "[gophernotes is super]"},
122+
{[]string{
123+
"m := map[string]int{",
124+
` "a": 10,`,
125+
` "c": 30,`,
126+
"}",
127+
`m["c"]`,
128+
}, "30"},
129+
{[]string{
130+
"if 1 < 2 {",
131+
" 3",
132+
"}",
133+
}, ""},
134+
{[]string{
135+
"d := 10",
136+
"d++",
137+
}, ""},
138+
{[]string{
139+
"out := make(chan int)",
140+
"go func() {",
141+
" out <- 123",
142+
"}()",
143+
"<-out",
144+
}, "123"},
95145
}
96146

97147
t.Logf("Should be able to evaluate valid code in notebook cells.")

0 commit comments

Comments
 (0)