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 !reflect.DeepEqual(e, expectedAst[i]) { t.Error(fmt.Sprintf("Expected: %q\nGot:%q", expectedAst[i], 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, "

1

"}, {2, "

2

"}, {3, "

3

"}, {4, "
quote
"}, {5, ``}, {6, "

text

"}, {7, "

more text

"}, {8, `

some link

`}, {9, ``}, {10, `
=> preformatted text
where markup is not lexed
`}, {11, `

linking

`}, {12, "

text

"}, {13, `
()
/\
`}, {14, Transclusion{"apple", 1, 3}}, {15, Img{ hyphaName: "Apple", inDesc: false, entries: []imgEntry{ {"hypha1", "", "", ""}, {"hypha2", "", "", ""}, {"hypha3", "60", "", ""}, {"hypha4", "", "", " line1\nline2\n"}, {"hypha5", "", "", "\nstate of minnesota\n"}, }, }}, }) }