Пример #1
0
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")
}