5 describe
'#initialize' do
6 it
"should give an error if not given an original string" do
7 # Label.new.should raise_error(ArgumentError)
8 expect
{Label
.new
}.to
raise_error(ArgumentError
)
11 it
"should create a copy of the original as the processed string" do
12 test_label
= "Test label"
13 l1
= Label
.new test_label
14 l1
.original
.should
== test_label
17 it
"should tidy the processed string if asked" do
18 test_label
= "testingLabeller string, he_pontificated"
19 l1
= Label
.new test_label
.dup
, true
20 l2
= Label
.new test_label
.dup
21 l2
.split
.downcase
.stem
22 l1
.processed
.should
== l2
.processed
26 describe
'#original' do
27 it
"reports the string it was initialised with" do
28 test_label
= "Test label"
29 l1
= Label
.new test_label
30 l1
.original
.should
== test_label
32 #l1.original.should == ""
36 describe
'#processed' do
37 it
"reports the original if no processing has been done" do
38 test_label
= "Test label"
39 l1
= Label
.new test_label
40 l1
.processed
.should
== [test_label
]
41 l1
.original
.should
== test_label
46 it
"splits the original on the specified regexp" do
47 l1
= Label
.new
"Test label"
49 l1
.processed
.should
== ["Test", "label"]
50 l1
.original
.should
== "Test label"
52 l1
= Label
.new
"Test_label"
54 l1
.processed
.should
== ["Test", "label"]
56 l1
= Label
.new
"Test label_string"
58 l1
.processed
.should
== ["Test", "label", "string"]
61 it
"splits the original on camel case" do
62 l1
= Label
.new
"TestLabel"
63 l1
.split
:camel_case => true
64 l1
.processed
.should
== ["Test", "Label"]
65 l1
.original
.should
== "TestLabel"
67 l2
= Label
.new
"testLabel"
68 l2
.split
:camel_case => true
69 l2
.processed
.should
== ["test", "Label"]
70 l2
.original
.should
== "testLabel"
73 it
"doesn't split the original on camel case if asked not to" do
74 l1
= Label
.new
"TestLabel"
75 l1
.split
:camel_case => false
76 l1
.processed
.should
== ["TestLabel"]
77 l1
.original
.should
== "TestLabel"
79 l2
= Label
.new
"TestLabel"
80 l2
.split
:camel_case => nil
81 l2
.processed
.should
== ["TestLabel"]
82 l2
.original
.should
== "TestLabel"
85 it
"splits the original on numbers" do
86 l1
= Label
.new
"Test123Label"
87 l1
.split
:numbers => true
88 l1
.processed
.should
== ["Test", "123", "Label"]
89 l1
.original
.should
== "Test123Label"
91 l2
= Label
.new
"test1label"
92 l2
.split
:numbers => true
93 l2
.processed
.should
== ["test", "1", "label"]
94 l2
.original
.should
== "test1label"
97 it
"doesn't split the original on numbers if asked not to" do
98 l1
= Label
.new
"Test123Label"
99 l1
.split
:numbers => false
100 l1
.processed
.should
== ["Test123Label"]
101 l1
.original
.should
== "Test123Label"
103 l2
= Label
.new
"Test123Label"
104 l2
.split
:numbers => nil
105 l2
.processed
.should
== ["Test123Label"]
106 l2
.original
.should
== "Test123Label"
109 it
"splits the original using a default regexp" do
110 l1
= Label
.new
"Test label_string\tfred"
112 l1
.processed
.should
== ["Test", "label", "string", "fred"]
115 it
"splits the original on camel case by default" do
116 l1
= Label
.new
"TestLabel"
118 l1
.processed
.should
== ["Test", "Label"]
119 l1
.original
.should
== "TestLabel"
122 it
"splits the original on numbers by default" do
123 l1
= Label
.new
"Test123Label"
125 l1
.processed
.should
== ["Test", "123", "Label"]
126 l1
.original
.should
== "Test123Label"
129 it
"splits the original on punctuation, whitespace, camel case, and numbers by default" do
130 l1
= Label
.new
"TestLabel is_split, 123 he,said456Fred"
132 l1
.processed
.should
== ["Test", "Label", "is", "split","123", "he", "said", "456", "Fred"]
133 l1
.original
.should
== "TestLabel is_split, 123 he,said456Fred"
136 it
"is idempotent" do
137 l1
= Label
.new
"TestLabel is_split, 123 he,said456Fred"
140 res1
.processed
.should
== res2
.processed
141 l1
.original
.should
== "TestLabel is_split, 123 he,said456Fred"
145 describe
"#downcase" do
146 it
"downcases all parts of the processed label" do
147 l1
= Label
.new
"Test label_string"
149 l1
.processed
.should
== ["test", "label", "string"]
154 it
"stems all parts of the processed label" do
155 l1
= Label
.new
"testing labeller string pontificated"
157 l1
.processed
.should
== ["test", "label", "string", "pontif"]
162 it
"tidies a label" do
163 l1
= Label
.new
"testingLabeller string, he_pontificated"
164 l2
= Label
.new l1
.original
166 l2
.split
.downcase
.stem
167 l1
.processed
.should
== l2
.processed
171 describe
"#length" do
172 it
"returns the length of the processed label" do
173 l1
= Label
.new
"testingLabeller string, he_pontificated"
175 l1
.length
.should
== l1
.processed
.join('').length
179 describe
"#levenshtein" do
180 it
"calculates the Levenshtein distance of the processed string" do
181 l1
= Label
.new
"Fred"
182 l1
.levenshtein("Fred").should
== 0
183 l1
.levenshtein("Free").should
== 1
184 l1
.levenshtein("").should
== 4
186 l2
.levenshtein("Free").should
== 4
187 l2
.levenshtein("").should
== 0
188 l3
= Label
.new
"meilenstein"
189 l3
.levenshtein("levenshtein").should
== 4
190 l4
= Label
.new
"testingLabeller string, he_pontificated"
191 l4
.tidy
.levenshtein("testlabelstringhepontif").should
== 0
192 l4
.tidy
.levenshtein("testlabelXstringhepontif").should
== 1
195 it
"calculates the Levenshtein distance between Labels" do
196 l1
= Label
.new
"meilenstein"
197 l2
= Label
.new
"levenshtein"
198 l1
.levenshtein(l2
).should
== 4