-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpipeline_test.go
More file actions
104 lines (89 loc) · 2.61 KB
/
pipeline_test.go
File metadata and controls
104 lines (89 loc) · 2.61 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package rescript
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDehyphenate(t *testing.T) {
assert := assert.New(t)
var ta *Node
var tb *Node
head := func(n *Node) *Node {
nn := n
for node := n; node != nil; node = node.Next() {
nn = node
}
return nn
}
str := func(n *Node) string {
return n.Token().String()
}
// basic, unchanged
ta = buildSampleList("foo", " ", "bar")
tb = Dehyphenate(ta)
assert.Equal(str(ta), str(tb))
assert.Equal(str(head(ta)), str(head(tb)))
// hyphenated word should be merged
//
// foo-
// bar
ta = buildSampleList("foo", "-", "\n", "bar")
tb = Dehyphenate(ta)
assert.Equal("foobar", str(tb), "Hyphenated words should be merged")
// hyphenated word should be merged
//
// foo- bar
ta = buildSampleList("foo", "-", " ", "bar")
tb = Dehyphenate(ta)
assert.Equal("foobar", str(tb), "Hyphenated words should be merged")
// subsequent hyphenations should also be merged
//
// foo- bar
ta = buildSampleList("foo", "-", " ", "bar", " ", "abc", "-", " ", "def")
tb = Dehyphenate(ta)
assert.Equal("foobar", str(tb), "Hyphenated words should be merged")
assert.Equal(" ", str(tb.Next()), "Hyphenated words should be merged")
assert.Equal("abcdef", str(tb.Next().Next()), "Hyphenated words should be merged")
// hyphenated word should be merged
//
// foo-bar
ta = buildSampleList("foo", "-", "bar")
tb = Dehyphenate(ta)
assert.Equal("foobar", str(tb), "Hyphenated words should be merged")
// two words separated by dash should NOT be merged
//
// foo - bar
ta = buildSampleList("foo", " ", "-", " ", "bar")
tb = Dehyphenate(ta)
assert.Equal("foo", str(tb), "Words separated by dash should NOT be merged")
assert.Equal("bar", str(head(tb)), "Words separated by dash should NOT be merged")
// List elements are not hyphenated words
//
// foo
// - item
ta = buildSampleList("foo", "\n", "-", " ", "item")
tb = Dehyphenate(ta)
assert.Equal("foo", str(tb), "Words separated by dash should NOT be merged")
assert.Equal("item", str(head(tb)), "Words separated by dash should NOT be merged")
// List elements are not hyphenated words (even if the list is not properly recognized)
//
// foo
// -item
ta = buildSampleList("foo", "\n", "-", "item")
tb = Dehyphenate(ta)
assert.Equal("foo", str(tb), "Words separated by dash should NOT be merged")
assert.Equal("item", str(head(tb)), "Words separated by dash should NOT be merged")
}
func buildSampleList(s ...string) *Node {
var tail *Node
var head *Node
for _, w := range s {
n := NewNode(NewToken(w))
if head != nil {
head.InsertAfter(n)
} else {
tail = n
}
head = n
}
return tail
}