1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2025-02-13 12:06:31 -05:00
OpenDiablo2/d2common/d2fileformats/d2tbl/text_dictionary_test.go

41 lines
671 B
Go
Raw Normal View History

package d2tbl
import (
"testing"
)
func exampleData() *TextDictionary {
result := &TextDictionary{
"abc": "def",
"someStr": "Some long string",
// #2 is non-named (X: OK)
// so 2 is an index in map
"#2": "OK",
2021-02-28 08:14:47 -05:00
"teststring": "TeStxwsas123 long strin122*8:wq",
2021-02-25 05:58:32 -05:00
}
return result
}
func TestTBL_Marshal(t *testing.T) {
tbl := exampleData()
data := tbl.Marshal()
2021-02-25 06:03:00 -05:00
2021-02-25 05:58:32 -05:00
newTbl, err := LoadTextDictionary(data)
if err != nil {
t.Error(err)
}
2021-02-25 06:03:00 -05:00
for key, value := range *tbl {
newValue, ok := newTbl[key]
2021-02-25 06:08:02 -05:00
2021-02-25 06:03:00 -05:00
if !ok {
2021-02-28 08:14:47 -05:00
t.Fatalf("string %s wasn't encoded to table", key)
2021-02-25 06:03:00 -05:00
}
2021-02-25 06:08:02 -05:00
2021-02-25 06:03:00 -05:00
if newValue != value {
t.Fatal("unexpected value set")
}
}
}