2021-02-25 09:02:10 +00:00
|
|
|
package d2tbl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func exampleData() *TextDictionary {
|
|
|
|
result := &TextDictionary{
|
2021-02-28 19:31:44 +00:00
|
|
|
"abc": "def",
|
|
|
|
"someStr": "Some long string",
|
2021-02-28 13:14:47 +00:00
|
|
|
"teststring": "TeStxwsas123 long strin122*8:wq",
|
2021-02-25 10:58:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTBL_Marshal(t *testing.T) {
|
|
|
|
tbl := exampleData()
|
|
|
|
data := tbl.Marshal()
|
2021-02-25 11:03:00 +00:00
|
|
|
|
2021-02-25 10:58:32 +00:00
|
|
|
newTbl, err := LoadTextDictionary(data)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2021-02-28 19:35:35 +00: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 19:31:44 +00:00
|
|
|
|
2021-02-25 11:03:00 +00:00
|
|
|
for key, value := range *tbl {
|
|
|
|
newValue, ok := newTbl[key]
|
2021-02-25 11:08:02 +00:00
|
|
|
|
2021-02-25 11:03:00 +00:00
|
|
|
if !ok {
|
2021-02-28 13:14:47 +00:00
|
|
|
t.Fatalf("string %s wasn't encoded to table", key)
|
2021-02-25 11:03:00 +00:00
|
|
|
}
|
2021-02-25 11:08:02 +00:00
|
|
|
|
2021-02-25 11:03:00 +00:00
|
|
|
if newValue != value {
|
|
|
|
t.Fatal("unexpected value set")
|
|
|
|
}
|
2021-02-25 09:02:10 +00:00
|
|
|
}
|
|
|
|
}
|