func buildTemplate(data []byte, config *core.Configuration) (*Template, error) { parser := core.NewParser(data) template := new(Template) if err := extractTokens(parser, template, config); err != nil { return nil, err } return template, nil }
func newParser(s string) *core.Parser { return core.NewParser([]byte(s)) }
func TestOutputWithAnEscapeParameter(t *testing.T) { spec := gspec.New(t) output, err := newOutput(core.NewParser([]byte("{{'fun' | debug: 'te\\'st'}}"))) spec.Expect(err).ToBeNil() assertFilters(t, output, "debug(0, te'st)") }
func TestOutputHandlesEmptyOutput(t *testing.T) { spec := gspec.New(t) output, err := newOutput(core.NewParser([]byte("{{}}"))) spec.Expect(output).ToBeNil() spec.Expect(err).ToBeNil() }
func TestOutputWithMultipleFilters(t *testing.T) { output, _ := newOutput(core.NewParser([]byte("{{'fun' | debug | debug}}"))) assertFilters(t, output, "debug(0)", "debug(1)") }
func TestOutputWithMultipleFiltersHavingParameters(t *testing.T) { spec := gspec.New(t) output, err := newOutput(core.NewParser([]byte("{{'fun' | debug:1,2 | debug:'test' | debug : 'test' , 5}}"))) spec.Expect(err).ToBeNil() assertFilters(t, output, "debug(0, 1, 2)", "debug(1, test)", "debug(2, test, 5)") }
func TestOutputGeneratesErrorOnUnknownFilter(t *testing.T) { spec := gspec.New(t) _, err := newOutput(core.NewParser([]byte("{{'fun' | unknown }}"))) spec.Expect(err.Error()).ToEqual(`Unknown filter "unknown" ("{{'fun' | unknown }}" - line 1)`) }
func TestOutputGeneratesErrorOnInvalidParameter(t *testing.T) { spec := gspec.New(t) _, err := newOutput(core.NewParser([]byte("{{'fun' | debug: 'missing }}"))) spec.Expect(err.Error()).ToEqual(`Invalid value, a single quote might be missing ("{{'fun' | debug: 'missing }}" - line 1)`) }
func TestOutputNoFiltersForStatic(t *testing.T) { spec := gspec.New(t) output, _ := newOutput(core.NewParser([]byte("{{'fun'}}"))) spec.Expect(len(output.(*Output).Filters)).ToEqual(0) }
func TestOutputExtractionGivesErrorForUnclosedStatic(t *testing.T) { spec := gspec.New(t) output, err := newOutput(core.NewParser([]byte("{{ 'failure }}"))) spec.Expect(output).ToBeNil() spec.Expect(err.Error()).ToEqual(`Invalid value, a single quote might be missing ("{{ 'failure }}" - line 1)`) }
func TestOutputExtractsAStaticWithAnEndingQuote(t *testing.T) { output, _ := newOutput(core.NewParser([]byte("{{'it\\''}}"))) assertRender(t, output, nil, "it'") }
func TestOutputExtractsAComplexStatic(t *testing.T) { output, _ := newOutput(core.NewParser([]byte("{{'it\\'s over \\9000'}}"))) assertRender(t, output, nil, "it's over \\9000") }
func TestOutputExtractsASimpleStatic(t *testing.T) { output, _ := newOutput(core.NewParser([]byte("{{ 'over 9000'}}"))) assertRender(t, output, nil, "over 9000") }