diff options
Diffstat (limited to 'word_test.go')
| -rw-r--r-- | word_test.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/word_test.go b/word_test.go new file mode 100644 index 0000000..5dcb468 --- /dev/null +++ b/word_test.go @@ -0,0 +1,66 @@ +// Copyright 2020, Shulhan <ms@kilabit.info>. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package kamusku + +import ( + "io/ioutil" + "testing" + + "github.com/shuLhan/share/lib/test" +) + +func TestWord_parseHTMLEntri(t *testing.T) { + cases := []struct { + infile string + cari string + exp *Word + }{{ + infile: "testdata/entri.html", + cari: "informasi", + exp: &Word{ + Definition: []*WordDefinition{{ + Value: "penerangan", + Classes: []string{"Nomina: kata benda"}, + }, { + Value: "pemberitahuan; kabar atau berita tentang sesuatu", + Classes: []string{"Nomina: kata benda"}, + }, { + Value: "keseluruhan makna yang menunjang amanat yang " + + "terlihat dalam bagian-bagian " + + "amanat itu", + Classes: []string{ + "Nomina: kata benda", + "Linguistik: -", + }, + }}, + }, + }, { + infile: "testdata/entri_analisa.html", + cari: "analisa", + exp: &Word{ + Message: `"analisa" adalah bentuk tidak baku dari "analisis"`, + }, + }} + + for _, c := range cases { + htmlBody, err := ioutil.ReadFile(c.infile) + if err != nil { + t.Fatal(err) + } + + got := new(Word) + + err = got.parseHTMLEntri(c.cari, htmlBody) + if err != nil { + t.Fatal(err) + } + + for x, def := range c.exp.Definition { + test.Assert(t, "Definition", def, got.Definition[x], true) + } + + test.Assert(t, c.infile, c.exp, got, true) + } +} |
