1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-07-13 09:54:06 +00:00

Fix table test

This commit is contained in:
2025-06-14 15:30:42 +02:00
parent cc8a602b51
commit 53134a0d09

View File

@ -1,6 +1,22 @@
package fmp package fmp
import "testing" import (
"slices"
"testing"
)
func slicesHaveSameElements[Type comparable](a, b []Type) bool {
if len(a) != len(b) {
return false
}
for _, av := range a {
found := slices.Contains(b, av)
if !found {
return false
}
}
return true
}
func TestOpenFile(t *testing.T) { func TestOpenFile(t *testing.T) {
f, err := OpenFile("../files/Untitled.fmp12") f, err := OpenFile("../files/Untitled.fmp12")
@ -29,16 +45,13 @@ func TestTables(t *testing.T) {
} }
tables := f.Tables() tables := f.Tables()
expected := "Untitled, WayDomains, WayProcesses" expectedNames := []string{"Untitled", "WayDomains", "WayProcesses"}
tablesString := "" tableNames := []string{}
for i, table := range tables { for _, table := range tables {
tablesString += table.Name tableNames = append(tableNames, table.Name)
if i < len(tables)-1 {
tablesString += ", "
}
} }
if tablesString != expected { if !slicesHaveSameElements(tableNames, expectedNames) {
t.Errorf("expected tables to be '%s', got '%s'", expected, tablesString) t.Errorf("tables do not match")
} }
} }