gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/elvish/parse/pprint_test.go (about) 1 package parse 2 3 import ( 4 "testing" 5 6 "github.com/u-root/u-root/cmds/core/elvish/tt" 7 ) 8 9 var n = mustParse("ls $x[0]$y[1];echo") 10 11 var pprintASTTests = tt.Table{ 12 tt.Args(n).Rets( 13 `Chunk 14 Pipeline/Form 15 Compound/Indexing/Primary Type=Bareword Value="ls" 16 Compound 17 Indexing 18 Primary Type=Variable Value="x" 19 Array/Compound/Indexing/Primary Type=Bareword Value="0" 20 Indexing 21 Primary Type=Variable Value="y" 22 Array/Compound/Indexing/Primary Type=Bareword Value="1" 23 Pipeline/Form/Compound/Indexing/Primary Type=Bareword Value="echo" 24 `), 25 } 26 27 func TestPPrintAST(t *testing.T) { 28 tt.Test(t, tt.Fn("PPrintAST", PPrintAST), pprintASTTests) 29 } 30 31 var pprintParseTreeTests = tt.Table{ 32 tt.Args(n).Rets( 33 `Chunk "ls $x[0]$y[1];echo" 0-18 34 Pipeline/Form "ls $x[0]$y[1]" 0-13 35 Compound/Indexing/Primary "ls" 0-2 36 Sep " " 2-3 37 Compound "$x[0]$y[1]" 3-13 38 Indexing "$x[0]" 3-8 39 Primary "$x" 3-5 40 Sep "[" 5-6 41 Array/Compound/Indexing/Primary "0" 6-7 42 Sep "]" 7-8 43 Indexing "$y[1]" 8-13 44 Primary "$y" 8-10 45 Sep "[" 10-11 46 Array/Compound/Indexing/Primary "1" 11-12 47 Sep "]" 12-13 48 Sep ";" 13-14 49 Pipeline/Form/Compound/Indexing/Primary "echo" 14-18 50 `), 51 } 52 53 func TestPprintParseTree(t *testing.T) { 54 tt.Test(t, tt.Fn("PPrintParseTree", PPrintParseTree), pprintParseTreeTests) 55 } 56 57 func mustParse(src string) Node { 58 n, err := Parse("[test]", src) 59 if err != nil { 60 panic(err) 61 } 62 return n 63 }