under-os-core 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,133 @@
1
+ describe UnderOs::Color do
2
+ def from(*args)
3
+ UnderOs::Color.new(*args)
4
+ end
5
+
6
+ describe '#initialize' do
7
+ it "should initialize from a UIColor" do
8
+ color = from(UIColor.blueColor)
9
+ color.ui.should == UIColor.blueColor
10
+ end
11
+
12
+ it "should always return the same instance" do
13
+ color1 = from(UIColor.blackColor)
14
+ color2 = from(UIColor.blackColor)
15
+
16
+ color1.should === color2
17
+ end
18
+
19
+ it "should work with rgba arrays of integers" do
20
+ from(0, 0, 255, 1.0).should == UIColor.blueColor
21
+ end
22
+
23
+ it "should work with rgba arrays of floats" do
24
+ from(0.0, 0.0, 1.0, 1.0).should == UIColor.blueColor
25
+ end
26
+
27
+ it "should work with rgb arrays of integers" do
28
+ from(0, 0, 255).should == UIColor.blueColor
29
+ end
30
+
31
+ it "should work with rgb arrays of floats" do
32
+ from(0.0, 0.0, 1.0).should == UIColor.blueColor
33
+ end
34
+
35
+ it "should work with string color names" do
36
+ from('blue').should == UIColor.blueColor
37
+ end
38
+
39
+ it "should work with symbol color names" do
40
+ from(:blue).should == UIColor.blueColor
41
+ end
42
+
43
+ it "should work with string hex colors" do
44
+ from('#ff8000').should == UIColor.orangeColor
45
+ end
46
+
47
+ it "should work with short hand colors" do
48
+ from('#ff0').should == UIColor.yellowColor
49
+ end
50
+
51
+ it "should work with rgb() strings" do
52
+ from('rgb(10, 20, 30)').to_rgba.should == [10, 20, 30, 1.0]
53
+ end
54
+
55
+ it "should work with rgba() strings" do
56
+ from('rgba(100, 200, 250, 0.5)').to_rgba.should == [100, 200, 250, 0.5]
57
+ end
58
+
59
+ it 'should work with flaot color circle params' do
60
+ from(0.23).to_s.should == '#9eff00'
61
+ end
62
+
63
+ it 'should work with integer (in degrees) color circle params' do
64
+ from(23).to_s.should == '#9eff00'
65
+ end
66
+ end
67
+
68
+ describe '#to_rgba' do
69
+ it "should extract the data correctly" do
70
+ from(UIColor.blueColor).to_rgba.should == [0, 0, 255, 1.0]
71
+ end
72
+ end
73
+
74
+ describe '#to_rgb' do
75
+ it "should extract the data correctly" do
76
+ from(UIColor.yellowColor).to_rgb.should == [255, 255, 0]
77
+ end
78
+ end
79
+
80
+ describe '#to_hex' do
81
+ it "should extract the data correctly" do
82
+ from(UIColor.orangeColor).to_hex.should == '#ff8000'
83
+ end
84
+ end
85
+
86
+ describe '#to_s' do
87
+ it "should extract the data correctly" do
88
+ from(UIColor.brownColor).to_s.should == '#996633'
89
+ end
90
+ end
91
+
92
+ describe '#==' do
93
+ it "should work with other colors" do
94
+ from(UIColor.blueColor).should == from(UIColor.blueColor)
95
+ from(UIColor.blueColor).should.not == from(UIColor.orangeColor)
96
+ end
97
+
98
+ it "should work with UIColors" do
99
+ from(UIColor.blueColor).should == UIColor.blueColor
100
+ from(UIColor.blueColor).should.not == UIColor.orangeColor
101
+ end
102
+
103
+ it "should work with RGB arrays" do
104
+ from(UIColor.blueColor).should == [0, 0, 255]
105
+ from(UIColor.blueColor).should.not == [0, 255, 0]
106
+ end
107
+
108
+ it "should work with RGBA arrays" do
109
+ from(UIColor.blueColor).should == [0, 0, 255, 1.0]
110
+ from(UIColor.blueColor).should.not == [0, 255, 0, 1.0]
111
+ end
112
+
113
+ it "should work with string names" do
114
+ from(UIColor.blueColor).should == 'blue'
115
+ from(UIColor.blueColor).should.not == 'orange'
116
+ end
117
+
118
+ it "should work with symbol names" do
119
+ from(UIColor.blueColor).should == :blue
120
+ from(UIColor.blueColor).should.not == :orange
121
+ end
122
+
123
+ it "should work with hex values" do
124
+ from(UIColor.blueColor).should == '#0000ff'
125
+ from(UIColor.blueColor).should.not == '#00ff00'
126
+ end
127
+
128
+ it "should work with short hex values" do
129
+ from(UIColor.blueColor).should == '#00f'
130
+ from(UIColor.blueColor).should.not == '#0f0'
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,71 @@
1
+ describe UnderOs::Events do
2
+ class Dummy
3
+ include UnderOs::Events
4
+ end
5
+
6
+ before do
7
+ @dummy = Dummy.new
8
+ end
9
+
10
+ describe "#on" do
11
+ it "should add event listeners" do
12
+ @dummy.on(:smth) { }
13
+ UnderOs::Events::Listeners.all(@dummy, :smth).size.should == 1
14
+ end
15
+
16
+ it "should return the object itself back" do
17
+ @dummy.on(:smth) { }.should.be.same_as @dummy
18
+ end
19
+ end
20
+
21
+ describe "#off" do
22
+ it "should remove event listeners" do
23
+ @dummy.on(:smth) { }
24
+ @dummy.off(:smth)
25
+ UnderOs::Events::Listeners.all(@dummy, :smth).size.should == 0
26
+ end
27
+
28
+ it "should return the object itself back" do
29
+ @dummy.off(:smth).should.be.same_as @dummy
30
+ end
31
+ end
32
+
33
+ describe "#emit" do
34
+ it "should emit events" do
35
+ kicked = false
36
+ @dummy.on(:smth) { kicked = true }
37
+ @dummy.emit(:smth)
38
+ kicked.should == true
39
+ end
40
+
41
+ it "should return the object itself back" do
42
+ @dummy.emit(:smth).should.be.same_as @dummy
43
+ end
44
+
45
+ it "should accept optional params" do
46
+ event = nil
47
+ @dummy.on(:smth) { |e| event = e }
48
+ @dummy.emit(:smth, param1: 1, param2: 2)
49
+ event.params.should == {param1: 1, param2: 2}
50
+ end
51
+ end
52
+
53
+ describe 'UnderOs::Events::Event' do
54
+ before do
55
+ @event = UnderOs::Events::Event.new('event-name', param1: 1, param2: 2)
56
+ end
57
+
58
+ it "should give access to it's name" do
59
+ @event.name.should == :"event-name"
60
+ end
61
+
62
+ it "should give access to it's params" do
63
+ @event.params.should == {param1: 1, param2: 2}
64
+ end
65
+
66
+ it "should magically pass all the missing requests to the params" do
67
+ @event.param1.should == 1
68
+ @event.param2.should == 2
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,98 @@
1
+ describe UnderOs::File do
2
+ before do
3
+ @existing_path = NSBundle.mainBundle.pathForResource("under-os.css", ofType:nil)
4
+ end
5
+
6
+ describe '.exists?' do
7
+ it "returns true for existing files" do
8
+ UnderOs::File.exists?(@existing_path).should == true
9
+ end
10
+
11
+ it "returns false for non existing files" do
12
+ UnderOs::File.exists?("non-existing.file").should == false
13
+ end
14
+ end
15
+
16
+ describe '.size' do
17
+ it "returns file size" do
18
+ UnderOs::File.size(@existing_path).should > 0
19
+ end
20
+
21
+ it "raises an error when exessing a non-existing file" do
22
+ -> {
23
+ UnderOs::File.size("non-existing.file")
24
+ }.should.raise(StandardError)
25
+ end
26
+ end
27
+
28
+ describe '.read' do
29
+ it "reads files content" do
30
+ content = UnderOs::File.read(@existing_path)
31
+ content.class.should == String
32
+ content.size.should > 0
33
+ end
34
+
35
+ it "raises an error when read a non-existing file" do
36
+ -> {
37
+ UnderOs::File.read("non-existing.file")
38
+ }.should.raise(StandardError)
39
+ end
40
+ end
41
+
42
+ describe '.write' do
43
+ before do
44
+ UnderOs::File.delete('test.txt')
45
+ @result = UnderOs::File.write('test.txt', 'stuff')
46
+ end
47
+
48
+ it "creates new files" do
49
+ UnderOs::File.exists?('test.txt').should == true
50
+ end
51
+
52
+ it "writes stuff into files" do
53
+ UnderOs::File.read('test.txt').should == 'stuff'
54
+ end
55
+
56
+ it "overwrites existing files" do
57
+ UnderOs::File.write('test.txt', 'new stuff')
58
+ UnderOs::File.read('test.txt').should == 'new stuff'
59
+ end
60
+
61
+ it "returns a new File object" do
62
+ @result.class.should == UnderOs::File
63
+ end
64
+ end
65
+
66
+ describe '.size' do
67
+ it "returns the file size" do
68
+ UnderOs::File.write('test.txt', '12345')
69
+ UnderOs::File.size('test.txt').should == 5
70
+ end
71
+ end
72
+
73
+ describe '.delete' do
74
+ before do
75
+ UnderOs::File.write('test.txt', 'stuff')
76
+ end
77
+
78
+ it "deletes files" do
79
+ UnderOs::File.delete('test.txt')
80
+ UnderOs::File.exists?('test.txt').should == false
81
+ end
82
+ end
83
+
84
+ describe '.tmp' do
85
+ before do
86
+ @file = UnderOs::File.tmp("test.txt")
87
+ end
88
+
89
+ it "creates a new File instance" do
90
+ @file.class.should == UnderOs::File
91
+ end
92
+
93
+ it "should locate it in the tmp directory" do
94
+ @file.path.to_s.should == "#{NSTemporaryDirectory()}test.txt"
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,156 @@
1
+ describe UnderOs::Point do
2
+
3
+ describe '#initialize' do
4
+ it "should eat numbers" do
5
+ point = UnderOs::Point.new(10, 20)
6
+ point.x.should == 10
7
+ point.y.should == 20
8
+ end
9
+
10
+ it "should eat hashes" do
11
+ point = UnderOs::Point.new(x: 20, y: 30)
12
+ point.x.should == 20
13
+ point.y.should == 30
14
+ end
15
+
16
+ it "should eat hashes with string keys" do
17
+ point = UnderOs::Point.new('x' => 30, 'y' => 40)
18
+ point.x.should == 30
19
+ point.y.should == 40
20
+ end
21
+
22
+ it "should eat other opints" do
23
+ other_point = UnderOs::Point.new(x: 40, y: 50)
24
+ new_point = UnderOs::Point.new(other_point)
25
+ new_point.x.should == other_point.x
26
+ new_point.y.should == other_point.y
27
+ end
28
+ end
29
+
30
+ describe '#==' do
31
+ before do
32
+ @point = UnderOs::Point.new(x: 50, y: 60)
33
+ end
34
+
35
+ it "should allow comparison to another point" do
36
+ @point.should == UnderOs::Point.new(x: 50, y: 60)
37
+ @point.should.not == UnderOs::Point.new(x: 60, y: 50)
38
+ end
39
+
40
+ it "should allow comparison to a hash" do
41
+ @point.should == {x: 50, y: 60}
42
+ @point.should.not == {x: 60, y: 50}
43
+ end
44
+ end
45
+
46
+ describe '#*' do
47
+ it "should allow to multiply pointers by a factor" do
48
+ point = UnderOs::Point.new(x: 15, y: 25)
49
+ new_point = point * 2
50
+ new_point.should.not == point
51
+ new_point.should == {x: 30, y: 50}
52
+ end
53
+ end
54
+
55
+ describe "#+" do
56
+ before do
57
+ @point = UnderOs::Point.new(x: 10, y: 20)
58
+ end
59
+
60
+ describe "with another point" do
61
+ before do
62
+ @new_point = @point + UnderOs::Point.new(x: 11, y: 22)
63
+ end
64
+
65
+ it "should make an instance of a Point" do
66
+ @new_point.class.should == UnderOs::Point
67
+ end
68
+
69
+ it "should apply changes correctly" do
70
+ @new_point.x.should == 21
71
+ @new_point.y.should == 42
72
+ end
73
+ end
74
+
75
+ describe "with a number" do
76
+ before do
77
+ @new_point = @point + 4
78
+ end
79
+
80
+ it "should make an instance of a Point" do
81
+ @new_point.class.should == UnderOs::Point
82
+ end
83
+
84
+ it "should apply changes correctly" do
85
+ @new_point.x.should == 14
86
+ @new_point.y.should == 24
87
+ end
88
+ end
89
+
90
+ describe "with a Hash" do
91
+ before do
92
+ @new_point = @point + {x: 6, y: 8}
93
+ end
94
+
95
+ it "should make an instance of a Point" do
96
+ @new_point.class.should == UnderOs::Point
97
+ end
98
+
99
+ it "should apply changes correctly" do
100
+ @new_point.x.should == 16
101
+ @new_point.y.should == 28
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "#-" do
107
+ before do
108
+ @point = UnderOs::Point.new(x: 10, y: 20)
109
+ end
110
+
111
+ describe "with another point" do
112
+ before do
113
+ @new_point = @point - UnderOs::Point.new(x: 2, y: 4)
114
+ end
115
+
116
+ it "should make an instance of a Point" do
117
+ @new_point.class.should == UnderOs::Point
118
+ end
119
+
120
+ it "should apply changes correctly" do
121
+ @new_point.x.should == 8
122
+ @new_point.y.should == 16
123
+ end
124
+ end
125
+
126
+ describe "with a number" do
127
+ before do
128
+ @new_point = @point - 4
129
+ end
130
+
131
+ it "should make an instance of a Point" do
132
+ @new_point.class.should == UnderOs::Point
133
+ end
134
+
135
+ it "should apply changes correctly" do
136
+ @new_point.x.should == 6
137
+ @new_point.y.should == 16
138
+ end
139
+ end
140
+
141
+ describe "with a Hash" do
142
+ before do
143
+ @new_point = @point - {x: 6, y: 8}
144
+ end
145
+
146
+ it "should make an instance of a Point" do
147
+ @new_point.class.should == UnderOs::Point
148
+ end
149
+
150
+ it "should apply changes correctly" do
151
+ @new_point.x.should == 4
152
+ @new_point.y.should == 12
153
+ end
154
+ end
155
+ end
156
+ end