2021-02-25 04:02:10 -05:00
|
|
|
package d2tbl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func exampleData() *TextDictionary {
|
|
|
|
result := &TextDictionary{
|
2021-02-28 14:31:44 -05:00
|
|
|
"abc": "def",
|
|
|
|
"someStr": "Some long string",
|
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-28 14:35:35 -05:00
|
|
|
for key, value := range *tbl {
|
|
|
|
newValue, ok := newTbl[key]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("string %s wasn't encoded to table", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
if newValue != value {
|
|
|
|
t.Fatal("unexpected value set")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTBL_MarshalNoNameString(t *testing.T) {
|
|
|
|
tbl := &TextDictionary{
|
|
|
|
"#0": "OKEY",
|
|
|
|
}
|
|
|
|
|
|
|
|
data := tbl.Marshal()
|
|
|
|
|
|
|
|
newTbl, err := LoadTextDictionary(data)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
2021-02-28 14:31:44 -05:00
|
|
|
|
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")
|
|
|
|
}
|
2021-02-25 04:02:10 -05:00
|
|
|
}
|
|
|
|
}
|