-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword_test.go
78 lines (70 loc) · 1.97 KB
/
word_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
68
69
70
71
72
73
74
75
76
77
78
package textractor
import (
"testing"
"github.com/aws/aws-sdk-go-v2/service/textract/types"
"github.com/stretchr/testify/assert"
)
func TestWord(t *testing.T) {
// Create a sample line for testing
line := &Line{
base: base{
id: "line-1",
confidence: 0.9,
blockType: types.BlockTypeLine,
boundingBox: &BoundingBox{},
page: &Page{},
raw: types.Block{},
},
words: []*Word{
{
base: base{
id: "word-1",
confidence: 0.9,
blockType: types.BlockTypeWord,
boundingBox: &BoundingBox{},
page: &Page{},
raw: types.Block{},
},
text: "Hello",
textType: types.TextTypePrinted,
line: nil, // Link to the line is set later for testing
tableCell: nil, // Link to the table cell is set later for testing
},
{
base: base{
id: "word-2",
confidence: 0.9,
blockType: types.BlockTypeWord,
boundingBox: &BoundingBox{},
page: &Page{},
raw: types.Block{},
},
text: "World",
textType: types.TextTypeHandwriting,
line: nil, // Link to the line is set later for testing
tableCell: nil, // Link to the table cell is set later for testing
},
},
}
// Set the line reference in each word
for _, word := range line.words {
word.line = line
}
// Test Word methods
t.Run("Word_Text", func(t *testing.T) {
assert.Equal(t, "Hello", line.words[0].Text())
assert.Equal(t, "World", line.words[1].Text())
})
t.Run("Word_TextType", func(t *testing.T) {
assert.Equal(t, types.TextTypePrinted, line.words[0].TextType())
assert.Equal(t, types.TextTypeHandwriting, line.words[1].TextType())
})
t.Run("Word_IsPrinted", func(t *testing.T) {
assert.True(t, line.words[0].IsPrinted())
assert.True(t, line.words[1].IsHandwriting())
})
t.Run("Word_IsHandwriting", func(t *testing.T) {
assert.False(t, line.words[0].IsHandwriting())
assert.False(t, line.words[1].IsPrinted())
})
}