Added label objects
[erd-marker.git] / spec / erd_handler / label_spec.rb
1 require 'spec_helper'
2
3 module ErdHandler
4 describe Label do
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
10 end
11 end # original
12
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
19 end
20 end # processed
21
22 describe '#split' do
23 it "splits the original on the specified regexp" do
24 l1 = Label.new "Test label"
25 l1.split(/ /)
26 l1.processed.should == ["Test", "label"]
27 l1.original.should == "Test label"
28
29 l1 = Label.new "Test_label"
30 l1.split(/_/)
31 l1.processed.should == ["Test", "label"]
32
33 l1 = Label.new "Test label_string"
34 l1.split(/[ _]/)
35 l1.processed.should == ["Test", "label", "string"]
36 end
37
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"
43
44 l2 = Label.new "testLabel"
45 l2.split :camel_case => true
46 l2.processed.should == ["test", "Label"]
47 l2.original.should == "testLabel"
48 end
49
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"
55
56 l2 = Label.new "TestLabel"
57 l2.split :camel_case => nil
58 l2.processed.should == ["TestLabel"]
59 l2.original.should == "TestLabel"
60 end
61
62 it "splits the original using a default regexp" do
63 l1 = Label.new "Test label_string"
64 l1.split
65 l1.processed.should == ["Test", "label", "string"]
66 end
67
68 it "splits the original on camel case by default" do
69 l1 = Label.new "TestLabel"
70 l1.split
71 l1.processed.should == ["Test", "Label"]
72 l1.original.should == "TestLabel"
73 end
74
75 it "splits the original on punctuation and camel case by default" do
76 l1 = Label.new "TestLabel is_split, he,said"
77 l1.split
78 l1.processed.should == ["Test", "Label", "is", "split", "he", "said"]
79 l1.original.should == "TestLabel is_split, he,said"
80 end
81
82 it "is idempotent" do
83 l1 = Label.new "TestLabel is_split, he,said"
84 res1 = l1.split.dup
85 res2 = l1.split
86 res1.processed.should == res2.processed
87 l1.original.should == "TestLabel is_split, he,said"
88 end
89 end # split
90
91 describe "#downcase" do
92 it "downcases all parts of the processed label" do
93 l1 = Label.new "Test label_string"
94 l1.split.downcase
95 l1.processed.should == ["test", "label", "string"]
96 end
97 end # downcase
98
99 describe "#stem" do
100 it "stems all parts of the processed label" do
101 l1 = Label.new "testing labeller string pontificated"
102 l1.split.stem
103 l1.processed.should == ["test", "label", "string", "pontif"]
104 end
105 end # stem
106
107 describe "#tidy" do
108 it "tidies a label" do
109 l1 = Label.new "testingLabeller string, he_pontificated"
110 l2 = Label.new l1.original
111 l1.tidy
112 l2.split.downcase.stem
113 l1.processed.should == l2.processed
114
115 end
116 end # tidy
117
118 end
119 end