5 describe
'#original' do
6 it
"reports the string it was initialised with" do
7 test_label
= "Test label"
8 l1
= Label
.new test_label
9 l1
.original
.should
== test_label
13 describe
'#processed' do
14 it
"reports the original if no processing has been done" do
15 test_label
= "Test label"
16 l1
= Label
.new test_label
17 l1
.processed
.should
== [test_label
]
18 l1
.original
.should
== test_label
23 it
"splits the original on the specified regexp" do
24 l1
= Label
.new
"Test label"
26 l1
.processed
.should
== ["Test", "label"]
27 l1
.original
.should
== "Test label"
29 l1
= Label
.new
"Test_label"
31 l1
.processed
.should
== ["Test", "label"]
33 l1
= Label
.new
"Test label_string"
35 l1
.processed
.should
== ["Test", "label", "string"]
38 it
"splits the original on camel case" do
39 l1
= Label
.new
"TestLabel"
40 l1
.split
:camel_case => true
41 l1
.processed
.should
== ["Test", "Label"]
42 l1
.original
.should
== "TestLabel"
44 l2
= Label
.new
"testLabel"
45 l2
.split
:camel_case => true
46 l2
.processed
.should
== ["test", "Label"]
47 l2
.original
.should
== "testLabel"
50 it
"doesn't split the original on camel case if asked not to" do
51 l1
= Label
.new
"TestLabel"
52 l1
.split
:camel_case => false
53 l1
.processed
.should
== ["TestLabel"]
54 l1
.original
.should
== "TestLabel"
56 l2
= Label
.new
"TestLabel"
57 l2
.split
:camel_case => nil
58 l2
.processed
.should
== ["TestLabel"]
59 l2
.original
.should
== "TestLabel"
62 it
"splits the original on numbers" do
63 l1
= Label
.new
"Test123Label"
64 l1
.split
:numbers => true
65 l1
.processed
.should
== ["Test", "123", "Label"]
66 l1
.original
.should
== "Test123Label"
68 l2
= Label
.new
"test1label"
69 l2
.split
:numbers => true
70 l2
.processed
.should
== ["test", "1", "label"]
71 l2
.original
.should
== "test1label"
74 it
"doesn't split the original on numbers if asked not to" do
75 l1
= Label
.new
"Test123Label"
76 l1
.split
:numbers => false
77 l1
.processed
.should
== ["Test123Label"]
78 l1
.original
.should
== "Test123Label"
80 l2
= Label
.new
"Test123Label"
81 l2
.split
:numbers => nil
82 l2
.processed
.should
== ["Test123Label"]
83 l2
.original
.should
== "Test123Label"
86 it
"splits the original using a default regexp" do
87 l1
= Label
.new
"Test label_string\tfred"
89 l1
.processed
.should
== ["Test", "label", "string", "fred"]
92 it
"splits the original on camel case by default" do
93 l1
= Label
.new
"TestLabel"
95 l1
.processed
.should
== ["Test", "Label"]
96 l1
.original
.should
== "TestLabel"
99 it
"splits the original on numbers by default" do
100 l1
= Label
.new
"Test123Label"
102 l1
.processed
.should
== ["Test", "123", "Label"]
103 l1
.original
.should
== "Test123Label"
106 it
"splits the original on punctuation, whitespace, camel case, and numbers by default" do
107 l1
= Label
.new
"TestLabel is_split, 123 he,said456Fred"
109 l1
.processed
.should
== ["Test", "Label", "is", "split","123", "he", "said", "456", "Fred"]
110 l1
.original
.should
== "TestLabel is_split, 123 he,said456Fred"
113 it
"is idempotent" do
114 l1
= Label
.new
"TestLabel is_split, 123 he,said456Fred"
117 res1
.processed
.should
== res2
.processed
118 l1
.original
.should
== "TestLabel is_split, 123 he,said456Fred"
122 describe
"#downcase" do
123 it
"downcases all parts of the processed label" do
124 l1
= Label
.new
"Test label_string"
126 l1
.processed
.should
== ["test", "label", "string"]
131 it
"stems all parts of the processed label" do
132 l1
= Label
.new
"testing labeller string pontificated"
134 l1
.processed
.should
== ["test", "label", "string", "pontif"]
139 it
"tidies a label" do
140 l1
= Label
.new
"testingLabeller string, he_pontificated"
141 l2
= Label
.new l1
.original
143 l2
.split
.downcase
.stem
144 l1
.processed
.should
== l2
.processed