예제 #1
0
파일: template.go 프로젝트: phlipper/liquid
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
}
예제 #2
0
func newParser(s string) *core.Parser {
	return core.NewParser([]byte(s))
}
예제 #3
0
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)")
}
예제 #4
0
func TestOutputHandlesEmptyOutput(t *testing.T) {
	spec := gspec.New(t)
	output, err := newOutput(core.NewParser([]byte("{{}}")))
	spec.Expect(output).ToBeNil()
	spec.Expect(err).ToBeNil()
}
예제 #5
0
func TestOutputWithMultipleFilters(t *testing.T) {
	output, _ := newOutput(core.NewParser([]byte("{{'fun' | debug | debug}}")))
	assertFilters(t, output, "debug(0)", "debug(1)")
}
예제 #6
0
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)")
}
예제 #7
0
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)`)
}
예제 #8
0
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)`)
}
예제 #9
0
func TestOutputNoFiltersForStatic(t *testing.T) {
	spec := gspec.New(t)
	output, _ := newOutput(core.NewParser([]byte("{{'fun'}}")))
	spec.Expect(len(output.(*Output).Filters)).ToEqual(0)
}
예제 #10
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)`)
}
예제 #11
0
func TestOutputExtractsAStaticWithAnEndingQuote(t *testing.T) {
	output, _ := newOutput(core.NewParser([]byte("{{'it\\''}}")))
	assertRender(t, output, nil, "it'")
}
예제 #12
0
func TestOutputExtractsAComplexStatic(t *testing.T) {
	output, _ := newOutput(core.NewParser([]byte("{{'it\\'s over \\9000'}}")))
	assertRender(t, output, nil, "it's over \\9000")
}
예제 #13
0
func TestOutputExtractsASimpleStatic(t *testing.T) {
	output, _ := newOutput(core.NewParser([]byte("{{  'over 9000'}}")))
	assertRender(t, output, nil, "over 9000")
}