package gemtext import ( "fmt" "io/ioutil" "reflect" "testing" ) // TODO: move test gemtext 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.gmi") if err != nil { t.Error("Could not read test gemtext 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 gemtext is not lexed
`}, {11, `

linking

`}, {12, "

text

"}, {13, `
()
/\
`}, // More thorough testing of xclusions is done in xclusion_test.go {14, Transclusion{"apple", 1, 3}}, }) }