From 47cace5cf8450e47d09d939c8854a2be062b3b33 Mon Sep 17 00:00:00 2001 From: Ian Lewis Date: Fri, 17 Jan 2025 06:30:24 +0000 Subject: [PATCH] test: Add more tests Signed-off-by: Ian Lewis --- stardict_test.go | 158 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 156 insertions(+), 2 deletions(-) diff --git a/stardict_test.go b/stardict_test.go index 627e499..52e39b0 100644 --- a/stardict_test.go +++ b/stardict_test.go @@ -145,13 +145,167 @@ func TestSearch(t *testing.T) { version=3.0.0 bookname=hoge wordcount=0 -idxfilesize=6`, +idxfilesize=0`, }, query: "foo", expected: nil, err: nil, }, + { + name: "index search", + dict: &testDict{ + ifo: `StarDict's dict ifo file +version=3.0.0 +bookname=hoge +wordcount=1 +idxfilesize=0`, + dict: []*dict.Word{ + { + Data: []*dict.Data{ + { + Type: dict.UTFTextType, + Data: []byte{'h', 'o', 'g', 'e'}, + }, + }, + }, + }, + idx: []*idx.Word{ + { + Word: "hoge", + Offset: 0, + Size: 6, + }, + }, + }, + query: "hoge", + + expected: []*Entry{ + { + word: "hoge", + data: []*dict.Data{ + { + Type: dict.UTFTextType, + Data: []byte{'h', 'o', 'g', 'e'}, + }, + }, + }, + }, + err: nil, + }, + + { + name: "syn search", + dict: &testDict{ + ifo: `StarDict's dict ifo file +version=3.0.0 +bookname=hoge +wordcount=1 +idxfilesize=0`, + dict: []*dict.Word{ + { + Data: []*dict.Data{ + { + Type: dict.UTFTextType, + Data: []byte{'h', 'o', 'g', 'e'}, + }, + }, + }, + }, + idx: []*idx.Word{ + { + Word: "hoge", + Offset: 0, + Size: 6, + }, + }, + syn: []*syn.Word{ + { + Word: "foo", + OriginalWordIndex: 0, + }, + }, + }, + query: "foo", + + expected: []*Entry{ + { + word: "hoge", + data: []*dict.Data{ + { + Type: dict.UTFTextType, + Data: []byte{'h', 'o', 'g', 'e'}, + }, + }, + }, + }, + err: nil, + }, + { + name: "combined idx/syn search", + dict: &testDict{ + ifo: `StarDict's dict ifo file +version=3.0.0 +bookname=hoge +wordcount=1 +idxfilesize=0`, + dict: []*dict.Word{ + { + Data: []*dict.Data{ + { + Type: dict.UTFTextType, + Data: []byte("hoge"), + }, + { + Type: dict.UTFTextType, + Data: []byte("foo"), + }, + }, + }, + }, + idx: []*idx.Word{ + { + Word: "hoge", + Offset: 0, + Size: 6, + }, + { + Word: "foo", + Offset: 6, + Size: 5, + }, + }, + syn: []*syn.Word{ + { + Word: "foo", + OriginalWordIndex: 0, + }, + }, + }, + query: "foo", + + expected: []*Entry{ + { + word: "foo", + data: []*dict.Data{ + { + Type: dict.UTFTextType, + Data: []byte("foo"), + }, + }, + }, + { + word: "hoge", + data: []*dict.Data{ + { + Type: dict.UTFTextType, + Data: []byte("hoge"), + }, + }, + }, + }, + err: nil, + }, } for _, test := range tests { @@ -172,7 +326,7 @@ idxfilesize=6`, if diff := cmp.Diff(test.err, err); diff != "" { t.Errorf("Search (-want, +got):\n%s", diff) } - if diff := cmp.Diff(test.expected, results); diff != "" { + if diff := cmp.Diff(test.expected, results, cmp.AllowUnexported(Entry{})); diff != "" { t.Errorf("Search (-want, +got):\n%s", diff) } })