This repository has been archived by the owner on May 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
/
model_test.go
67 lines (53 loc) · 1.46 KB
/
model_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package prose
import (
"embed"
"io/fs"
"os"
"path/filepath"
"testing"
)
func TestModelFromDisk(t *testing.T) {
data := filepath.Join(testdata, "PRODUCT")
model := ModelFromDisk(data)
if model.Name != "PRODUCT" {
t.Errorf("ModelFromDisk() expected = PRODUCT, got = %v", model.Name)
}
temp := filepath.Join(testdata, "temp")
_ = os.RemoveAll(temp)
err := model.Write(temp)
if err != nil {
panic(err)
}
model = ModelFromDisk(temp)
if model.Name != "temp" {
t.Errorf("ModelFromDisk() expected = temp, got = %v", model.Name)
}
}
//go:embed testdata/PRODUCT
var embeddedModel embed.FS
func TestModelFromFS(t *testing.T) {
err := fs.WalkDir(embeddedModel, ".", func(path string, d fs.DirEntry, err error) error {
//fmt.Printf("Walking dir %s, err %s\n", path, err)
return nil
})
// Load the embedded PRODUCT model
model := ModelFromFS("PRODUCT", embeddedModel)
if model.Name != "PRODUCT" {
t.Errorf("ModelFromFS() expected = PRODUCT, got = %v", model.Name)
}
doc, err := NewDocument("Windows 10 is an operating system",
UsingModel(model))
if err != nil {
t.Errorf("Failed to create doc with ModelFromFS")
}
ents := doc.Entities()
if len(ents) != 1 {
t.Fatalf("Expected 1 entity, got %v", ents)
}
if ents[0].Text != "Windows 10" {
t.Errorf("Expected to find entity 'Windows 10' with ModelFromFS, got = %v", ents[0].Text)
}
if ents[0].Label != "PRODUCT" {
t.Errorf("Expected to tab entity with PRODUCT, got = %v", ents[0].Label)
}
}