|
| 1 | +package parser_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/gamebox/gwirl/internal/parser" |
| 7 | +) |
| 8 | + |
| 9 | +var expressionTests = []ParsingTest{ |
| 10 | + {"simple expression", "@foobar\"", parser.NewTT2GoExp("foobar", false, noChildren)}, |
| 11 | + {"simple method", "@foobar()\"", parser.NewTT2GoExp("foobar()", false, noChildren)}, |
| 12 | + {"complex expression", "@foo.bar\"", parser.NewTT2GoExp("foo.bar", false, noChildren)}, |
| 13 | + {"complex method", "@foo.bar()\"", parser.NewTT2GoExp("foo.bar()", false, noChildren)}, |
| 14 | + {"complex method with params", "@foo.bar(param1, param2)\"", parser.NewTT2GoExp("foo.bar(param1, param2)", false, noChildren)}, |
| 15 | + {"complex method with literal params", "@foo.bar(\"hello\", 123)\"", parser.NewTT2GoExp("foo.bar(\"hello\", 123)", false, noChildren)}, |
| 16 | + {"complex method with struct literal param", "@foo.bar(MyStruct{something, else}, 123)\"", parser.NewTT2GoExp("foo.bar(MyStruct{something, else}, 123)", false, noChildren)}, |
| 17 | + {"complex method with chaining", "@foo.bar().something.else\"", parser.NewTT2GoExp("foo.bar().something.else", false, noChildren)}, |
| 18 | + {"complex method with params with chaining", "@foo.bar(param1, param2).something.else\"", parser.NewTT2GoExp("foo.bar(param1, param2).something.else", false, noChildren)}, |
| 19 | + {"complex method with literal params with chaining", "@foo.bar(\"hello\", 123).something.else\"", parser.NewTT2GoExp("foo.bar(\"hello\", 123).something.else", false, noChildren)}, |
| 20 | + |
| 21 | + // Transclusion tests |
| 22 | + { |
| 23 | + "simple method with transclusion", |
| 24 | + "@foobar() {\n\t<div>Hello</div>\n}", |
| 25 | + parser.NewTT2GoExp( |
| 26 | + "foobar()", |
| 27 | + false, |
| 28 | + simpleTransclusionChildren, |
| 29 | + ), |
| 30 | + }, |
| 31 | + |
| 32 | + { |
| 33 | + "complex method with transclusion", |
| 34 | + "@foo.bar() {\n\t<div>Hello</div>\n}", |
| 35 | + parser.NewTT2GoExp( |
| 36 | + "foo.bar()", |
| 37 | + false, |
| 38 | + simpleTransclusionChildren, |
| 39 | + ), |
| 40 | + }, |
| 41 | + |
| 42 | + { |
| 43 | + "complex method with param with transclusion", |
| 44 | + "@foo.bar(param1, param2) {\n\t<div>Hello</div>\n}", |
| 45 | + parser.NewTT2GoExp( |
| 46 | + "foo.bar(param1, param2)", |
| 47 | + false, |
| 48 | + simpleTransclusionChildren, |
| 49 | + ), |
| 50 | + }, |
| 51 | + |
| 52 | + { |
| 53 | + "complex method with literal params with transclusion", |
| 54 | + "@foo.bar(\"hello\", 123) {\n\t<div>Hello</div>\n}", |
| 55 | + parser.NewTT2GoExp( |
| 56 | + "foo.bar(\"hello\", 123)", |
| 57 | + false, |
| 58 | + simpleTransclusionChildren, |
| 59 | + ), |
| 60 | + }, |
| 61 | +} |
| 62 | + |
| 63 | +func TestExpressionParsing(t *testing.T) { |
| 64 | + runParserTest(expressionTests, t, func (p *parser.Parser2) *parser.TemplateTree2 { |
| 65 | + return p.Expression() |
| 66 | + },"") |
| 67 | +} |
| 68 | + |
0 commit comments