package markup import ( "fmt" "io/ioutil" "reflect" "testing" ) // TODO: move test markup docs to files, perhaps? These strings sure are ugly func TestLex(t *testing.T) { check := func(name, content string, expectedAst []Line) { if ast := lex(name, content); !reflect.DeepEqual(ast, expectedAst) { if len(ast) != len(expectedAst) { t.Error("Expected and generated AST length of", name, "do not match. Printed generated AST.") for _, l := range ast { fmt.Printf("%d: %s\n", l.id, l.contents) } return } for i, e := range ast { if e != expectedAst[i] { t.Error("Mismatch when lexing", name, "\nExpected:", expectedAst[i], "\nGot:", e) } } } } contentsB, err := ioutil.ReadFile("testdata/test.myco") if err != nil { t.Error("Could not read test markup file!") } contents := string(contentsB) check("Apple", contents, []Line{ {1, "
quote"}, {5, `
text
"}, {7, "more text
"}, {8, ``}, {9, `=> preformatted text
where markup is not lexed
`},
{11, ``},
{12, "text
"}, {13, `()
/\
`},
// More thorough testing of xclusions is done in xclusion_test.go
{14, Transclusion{"apple", 1, 3}},
})
}