chore(ipub): small mock test for unmarshalling
This commit is contained in:
@@ -38,3 +38,40 @@ func TestMarshal(t *testing.T) {
|
||||
t.Logf("%#v", string(by))
|
||||
}
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
assert := tinyssert.New(tinyssert.WithTest(t), tinyssert.WithPanic())
|
||||
|
||||
s := []byte(`
|
||||
<html>
|
||||
<body data-ipub-element="body">
|
||||
<section data-ipub-element="content">
|
||||
<img data-ipub-element="image" src="https://hello.com/world.png"/>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
|
||||
var data ast.Section
|
||||
|
||||
err := xml.Unmarshal(s, &data)
|
||||
if err != nil && err != io.EOF {
|
||||
t.Error(err.Error())
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
body := data.Body
|
||||
assert.Equal(ast.KindBody, body.Kind())
|
||||
|
||||
t.Logf("%#v", body)
|
||||
|
||||
content := body.FirstChild()
|
||||
assert.Equal(ast.KindContent, content.Kind())
|
||||
|
||||
t.Logf("%#v", content)
|
||||
|
||||
img := content.FirstChild().(*ast.Image)
|
||||
assert.Equal(ast.KindImage, img.Kind())
|
||||
assert.Equal("https://hello.com/world.png", img.Source())
|
||||
|
||||
t.Logf("%#v", img)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user