- Fix parser not producing the correct results - Add tests for everything - Add readme with example Ready for v1
53 lines
1 KiB
Go
53 lines
1 KiB
Go
package treeificator
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.mstar.dev/mstar/goutils/other"
|
|
)
|
|
|
|
func TestNodeUnmarshalTwoRawText(t *testing.T) {
|
|
strNode := Node{
|
|
NodeType: &DefaultInformer{},
|
|
Elements: []NodeElement{
|
|
NodeElement{
|
|
Text: other.IntoPointer("foo"),
|
|
Node: nil,
|
|
},
|
|
NodeElement{
|
|
Text: other.IntoPointer("bar"),
|
|
Node: nil,
|
|
},
|
|
},
|
|
}
|
|
if res := strNode.Unmarshal(); res != "foobar" {
|
|
t.Fatalf("expected \"foobar\" from unmarshal, got %v", res)
|
|
}
|
|
}
|
|
|
|
func TestNodeElementUnmarshalRawText(t *testing.T) {
|
|
node := NodeElement{
|
|
Text: other.IntoPointer("foo"),
|
|
Node: nil,
|
|
}
|
|
if res := node.Unmarshal(); res != "foo" {
|
|
t.Fatalf("expected \"foo\", got %v", res)
|
|
}
|
|
}
|
|
|
|
func TestNodeElementUnmarshalNode(t *testing.T) {
|
|
node := NodeElement{
|
|
Text: nil,
|
|
Node: &Node{
|
|
NodeType: &DefaultInformer{},
|
|
Elements: []NodeElement{
|
|
NodeElement{
|
|
Text: other.IntoPointer("foo"),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
if res := node.Unmarshal(); res != "foo" {
|
|
t.Fatalf("expected \"foo\", got %v", res)
|
|
}
|
|
}
|