forked from diminish7/rave
/
test_blip.rb
132 lines (117 loc) · 4.32 KB
/
test_blip.rb
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
require File.join(File.dirname(__FILE__), "helper")
describe Rave::Models::Blip do
before :all do
@class = Rave::Models::Blip
end
describe "root?()" do
it "should return true if a blip has no parent blip id" do
blip = Blip.new
blip.parent_blip_id.should be_nil
blip.root?.should be_true
blip = Blip.new(:parent_blip_id => "parent_blip")
blip.parent_blip_id.should_not be_nil
blip.root?.should be_false
end
end
describe "has_annotation?()" do
it "should return true if the blip has an annotation with the given name" do
blip = Blip.new
blip.has_annotation?("test").should be_false
blip.annotations << Annotation.new(:name => "test")
blip.has_annotation?("test").should be_true
end
end
describe "operations" do
describe "clear()" do
it "should clear the text" do
blip = Blip.new(:content => "Hello wave!")
blip.context = Context.new
blip.content.should == "Hello wave!"
blip.clear
blip.content.should == ""
end
it "should add a delete operation to the context" do
blip = Blip.new(:content => "Hello wave!")
blip.context = Context.new
blip.clear
validate_operations(blip.context, [Operation::DOCUMENT_DELETE])
end
end
describe "insert_text()" do
it "should set the content of the blip" do
blip = Blip.new(:content => "hello wave!")
blip.context = Context.new
blip.content.should == "hello wave!"
blip.insert_text(" google", 5)
blip.content.should == "hello google wave!"
end
it "shuold add an insert operation to the context" do
blip = Blip.new(:content => "hello wave!")
blip.context = Context.new
blip.insert_text(" google", 5)
validate_operations(blip.context, [Operation::DOCUMENT_INSERT])
end
end
describe "set_text()" do
it "should set the content of the blip" do
blip = Blip.new
blip.context = Context.new
blip.content.should be_nil
blip.set_text "What up, blip?"
blip.content.should == "What up, blip?"
end
it "should add a delete and insert operation to the context" do
blip = Blip.new
blip.context = Context.new
blip.content.should be_nil
blip.set_text "What up, blip?"
validate_operations(blip.context, [Operation::DOCUMENT_DELETE, Operation::DOCUMENT_INSERT])
end
end
describe "delete_range()" do
it "should delete the range of content from the blip" do
blip = Blip.new(:content => "hello google wave!")
blip.context = Context.new
blip.content.should == "hello google wave!"
blip.delete_range(5..11)
blip.content.should == "hello wave!"
end
it "should add a delete operation to the context" do
blip = Blip.new(:content => "hello google wave!")
blip.context = Context.new
blip.delete_range(5..11)
validate_operations(blip.context, [Operation::DOCUMENT_DELETE])
end
end
describe "set_text_in_range()" do
it "should replace the range of content with the given text" do
blip = Blip.new(:content => "hello google wave!")
blip.context = Context.new
blip.content.should == "hello google wave!"
blip.set_text_in_range(6..16, "world")
blip.content.should == "hello world!"
end
it "should add a delete and insert operation to the context" do
blip = Blip.new(:content => "hello google wave!")
blip.context = Context.new
blip.set_text_in_range(6..16, "world")
validate_operations(blip.context, [Operation::DOCUMENT_DELETE, Operation::DOCUMENT_INSERT])
end
end
describe "append_text()" do
it "should append the given text to the blip's content" do
blip = Blip.new(:content => "hello")
blip.context = Context.new
blip.content.should == "hello"
blip.append_text(" world!")
blip.content.should == "hello world!"
end
it "should add an append operation to the context" do
blip = Blip.new(:content => "hello")
blip.context = Context.new
blip.append_text(" world!")
validate_operations(blip.context, [Operation::DOCUMENT_APPEND])
end
end
end
end