62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package processing
|
|||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestPlainDescriptionFromAny_arrayAndHTML(t *testing.T) {
|
||
|
|
got := PlainDescriptionFromAny([]any{"Hello<br>World", "Second"})
|
||
|
|
if got != "Hello\nWorld\nSecond" {
|
||
|
|
t.Fatalf("array+html: %q", got)
|
||
|
|
}
|
||
|
|
got = PlainDescriptionFromAny(map[string]any{"#text": "Plain & ok"})
|
||
|
|
if got != "Plain & ok" {
|
||
|
|
t.Fatalf("#text: %q", got)
|
||
|
|
}
|
||
|
|
if PlainDescriptionFromAny(nil) != "" {
|
||
|
|
t.Fatal("nil should be empty")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestNormalizeMapped_descriptionArrayBecomesPlainString(t *testing.T) {
|
||
|
|
got := NormalizeMapped(map[string]any{
|
||
|
|
"description": []any{"Line1<br/>A", "Line2"},
|
||
|
|
"name": "Widget",
|
||
|
|
}, nil)
|
||
|
|
desc, ok := got["description"].(string)
|
||
|
|
if !ok {
|
||
|
|
t.Fatalf("description should be string, got %T %v", got["description"], got["description"])
|
||
|
|
}
|
||
|
|
if desc != "Line1\nA\nLine2" {
|
||
|
|
t.Fatalf("description=%q", desc)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestNormalizeMapped_eprelIDAlias(t *testing.T) {
|
||
|
|
got := NormalizeMapped(map[string]any{"EPRELID": "246834"}, nil)
|
||
|
|
if got["eprel_id"] != "246834" {
|
||
|
|
t.Fatalf("eprel_id=%v", got["eprel_id"])
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestStringFromAny_flattensArray(t *testing.T) {
|
||
|
|
got := stringFromAny([]any{"a", "b"})
|
||
|
|
if got != "a b" {
|
||
|
|
t.Fatalf("got %q", got)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestCanonicalizeAttrKey_eprel(t *testing.T) {
|
||
|
|
if canonicalizeAttrKey("EPRELID") != "eprel_id" {
|
||
|
|
t.Fatalf("got %q", canonicalizeAttrKey("EPRELID"))
|
||
|
|
}
|
||
|
|
if canonicalizeAttrKey("eprel") != "eprel_id" {
|
||
|
|
t.Fatalf("got %q", canonicalizeAttrKey("eprel"))
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestPlainDescriptionFromStored_jsonArrayString(t *testing.T) {
|
||
|
|
got := plainDescriptionFromStored(`["Hello<br>World"]`)
|
||
|
|
if got != "Hello\nWorld" {
|
||
|
|
t.Fatalf("got %q", got)
|
||
|
|
}
|
||
|
|
}
|