github.com/NeowayLabs/nash@v0.2.2-0.20200127205349-a227041ffd50/ast/tree_test.go (about) 1 package ast 2 3 import ( 4 "testing" 5 6 "github.com/madlambda/nash/token" 7 ) 8 9 // Test API 10 func TestTreeCreation(t *testing.T) { 11 tr := NewTree("example") 12 13 if tr.Name != "example" { 14 t.Errorf("Invalid name") 15 return 16 } 17 } 18 19 func TestTreeRawCreation(t *testing.T) { 20 tr := NewTree("creating a tree by hand") 21 22 ln := NewBlockNode(token.NewFileInfo(1, 0)) 23 rfarg := NewStringExpr(token.NewFileInfo(1, 0), "unp", false) 24 25 r := NewRforkNode(token.NewFileInfo(1, 0)) 26 r.SetFlags(rfarg) 27 ln.Push(r) 28 29 tr.Root = ln 30 31 if tr.String() != "rfork unp" { 32 t.Error("Failed to build AST by hand") 33 } 34 }