Files
wehub-resource-sync ead81af521
Deploy to GitHub Pages / deploy (push) Failing after 0s
CI / go (push) Has been cancelled
CI / build (darwin, macos-14) (push) Has been cancelled
CI / build (windows, windows-2025) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:13 +08:00

54 lines
1.1 KiB
Go

package tomlutil
import (
"reflect"
"testing"
)
func TestParseSections(t *testing.T) {
data := []byte(`
# a comment
stray = "ignored before any section"
[[station]]
name = "Radio A"
url = "http://a"
bitrate = "128"
[[station]]
name = "Radio B"
url = "http://b"
`)
var got []map[string]string
ParseSections(data, "station", func(f map[string]string) {
got = append(got, f)
})
want := []map[string]string{
{"name": "Radio A", "url": "http://a", "bitrate": "128"},
{"name": "Radio B", "url": "http://b"},
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("ParseSections = %v, want %v", got, want)
}
}
func TestParseSectionsLastKeyWins(t *testing.T) {
data := []byte("[[t]]\nk = \"first\"\nk = \"second\"\n")
var got string
ParseSections(data, "t", func(f map[string]string) { got = f["k"] })
if got != "second" {
t.Fatalf("k = %q, want second", got)
}
}
func TestParseSectionsEmptySectionEmits(t *testing.T) {
data := []byte("[[t]]\n[[t]]\nk = \"v\"\n")
count := 0
ParseSections(data, "t", func(map[string]string) { count++ })
if count != 2 {
t.Fatalf("emit count = %d, want 2", count)
}
}