-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast_test.go
53 lines (44 loc) · 921 Bytes
/
ast_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"testing"
)
func TestAddAtoms(t *testing.T) {
ast := AddOp{a: Atom(1), b: Atom(2)}
r, err := ast.eval()
if err != nil {
t.Fatalf("badness.com: %v", err)
}
if r != 3 {
t.Fatalf("Why is %v not three?", r)
}
}
func TestAddAdd(t *testing.T) {
ast1 := AddOp{a: Atom(1), b: AddOp{a: Atom(1), b: Atom(2)}}
ast2 := AddOp{b: Atom(1), a: AddOp{b: Atom(1), a: Atom(2)}}
r1, err := ast1.eval()
if err != nil {
t.Fatalf("badness.com: %v", err)
}
r2, err := ast2.eval()
if err != nil {
t.Fatalf("badness.com: %v", err)
}
if r1 != 4 {
t.Fatalf("Why is %v not four?", r1)
}
if r2 != 4 {
t.Fatalf("Why is %v not four?", r2)
}
}
// func TestExec(t *testing.T) {
// ast := ExecOp{args: []string{"echo", "1"}}
//
// r, err := ast.eval()
// if err != nil {
// t.Fatalf("badness.com: %v", err)
// }
//
// if r != 4 {
// t.Fatalf("Why is '%v' not echo 1?", r)
// }
// }