func TestSpecifications(t *testing.T) { var file *os.File var err error if file, err = os.Open("tests.json"); err != nil { t.Fatalf(err.Error()) } var tests map[string]map[string]test decoder := json.NewDecoder(file) if err = decoder.Decode(&tests); err != nil { t.Fatalf(err.Error()) } res := results{} for categoryName := range tests { failed := false for testName, test := range tests[categoryName] { var opts gohaml.EngineOptions var err error if opts, err = mergeConfig(test.Config); err != nil { t.Fatalf("\t%v\n", err.Error()) } if engine, err := gohaml.NewEngine(test.Haml, &opts); err != nil { t.Errorf(" ERROR IN '%s': %s\n", testName, err.Error()) res.failed += 1 } else { output, err := engine.Render(test.Locals) switch { case err != nil: t.Errorf(" ERROR IN '%s': %s\n", testName, err.Error()) res.failed += 1 case output != test.Html: if !failed { failed = true t.Log(categoryName) } t.Errorf(" %s\n", testName) t.Errorf(" input : %s\n", replaceNewlines(test.Haml)) t.Errorf(" expected: %s\n", replaceNewlines(test.Html)) t.Errorf(" got : %s\n", replaceNewlines(output)) res.failed += 1 default: res.passed += 1 } } } } t.Logf("%d tests, %d failures", res.passed+res.failed, res.failed) }
func (engine *HamlEngine) ParseAndAdd(templateName string, templateSource string, basePath string) *revel.Error { tpl, err := gohaml.NewEngine(templateSource) if nil != err { _, line, description := parseHamlError(err) return &revel.Error{ Title: "Template Compilation Error", Path: templateName, Description: description, Line: line, SourceLines: strings.Split(templateSource, "\n"), } } engine.templateSet[strings.ToLower(templateName)] = tpl return nil }