github.com/vugu/vugu@v0.3.5/gen/parser-util_test.go (about) 1 package gen 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/vugu/html" 8 ) 9 10 func TestVgForExpr(t *testing.T) { 11 tests := []struct { 12 name string 13 node *html.Node 14 15 expectedRet vgForAttr 16 expectedError string 17 }{ 18 { 19 name: "no attr", 20 node: &html.Node{}, 21 expectedRet: vgForAttr{}, 22 }, 23 { 24 name: "attr not found", 25 node: &html.Node{ 26 Attr: []html.Attribute{ 27 {Key: "vg-html", Val: "html"}, 28 }, 29 }, 30 expectedRet: vgForAttr{}, 31 }, 32 { 33 name: "simple attr", 34 node: &html.Node{ 35 Attr: []html.Attribute{ 36 {Key: "vg-html", Val: "html"}, 37 {Key: "vg-for", Val: " value "}, 38 }, 39 }, 40 expectedRet: vgForAttr{ 41 expr: "value", 42 }, 43 }, 44 { 45 name: "attr with unknown option", 46 node: &html.Node{ 47 Attr: []html.Attribute{ 48 {Key: "vg-html", Val: "html"}, 49 {Key: "vg-for.unknown", Val: "value"}, 50 }, 51 }, 52 expectedError: "option \"unknown\" unknown", 53 }, 54 { 55 name: "attr with noshadow option", 56 node: &html.Node{ 57 Attr: []html.Attribute{ 58 {Key: "vg-html", Val: "html"}, 59 {Key: "vg-for.noshadow", Val: "value"}, 60 }, 61 }, 62 expectedRet: vgForAttr{ 63 expr: "value", 64 noshadow: true, 65 }, 66 }, 67 } 68 for _, tt := range tests { 69 t.Run(tt.name, func(t *testing.T) { 70 assert := assert.New(t) 71 72 attr, err := vgForExpr(tt.node) 73 74 assert.Equal(tt.expectedRet, attr) 75 if tt.expectedError == "" { 76 assert.NoError(err) 77 } else { 78 assert.EqualError(err, tt.expectedError) 79 } 80 }) 81 } 82 }