package main import ( "slices" "strings" "testing" ) func TestSubmodules(t *testing.T) { tests := []struct { name string file string subs []Submodule }{ { name: "Empty submodules file", file: "", subs: []Submodule{}, }, { name: "Simple submodule", file: `[submodule "libfoo"] path = include/foo url = git://foo.com/git/lib.git [submodule "libbar"] path = include/bar url = git://bar.com/git/lib.git`, subs: []Submodule{ { Name: "libfoo", Path: "include/foo", Url: "git://foo.com/git/lib.git", }, { Name: "libbar", Path: "include/bar", Url: "git://bar.com/git/lib.git", }, }, }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { mods, err := ParseSubmodules(strings.NewReader(test.file)) if err != nil { t.Error("unexpected error:", err) } if !slices.Equal(mods, test.subs) { t.Error("expected", test.subs, "but got", mods) } }) } }