1 | require File.dirname(__FILE__) + '/../../../spec_helper'
|
---|
2 | include OpenEHR::AssumedLibraryTypes
|
---|
3 |
|
---|
4 | describe ISO8601Time do
|
---|
5 | before(:each) do
|
---|
6 | @iso8601time = ISO8601Time.new('15:55:37.32+0900')
|
---|
7 | end
|
---|
8 |
|
---|
9 | it 'should be an instance of ISO8601Time' do
|
---|
10 | @iso8601time.should be_an_instance_of ISO8601Time
|
---|
11 | end
|
---|
12 |
|
---|
13 | it 's hour should be 15' do
|
---|
14 | @iso8601time.hour.should == 15
|
---|
15 | end
|
---|
16 |
|
---|
17 | it 's minute should be 55' do
|
---|
18 | @iso8601time.minute.should == 55
|
---|
19 | end
|
---|
20 |
|
---|
21 | it 's second should be 37'do
|
---|
22 | @iso8601time.second.should == 37
|
---|
23 | end
|
---|
24 |
|
---|
25 | it 's fractional second should be 0.32' do
|
---|
26 | @iso8601time.fractional_second == 0.32
|
---|
27 | end
|
---|
28 |
|
---|
29 | it 'have fractional_second' do
|
---|
30 | @iso8601time.should have_fractional_second
|
---|
31 | end
|
---|
32 |
|
---|
33 | it 's time zone should +0900' do
|
---|
34 | @iso8601time.timezone == '+0900'
|
---|
35 | end
|
---|
36 |
|
---|
37 | it 'should be 15:55:37.32+0900 as_string' do
|
---|
38 | @iso8601time.as_string.should == '15:55:37.32+0900'
|
---|
39 | end
|
---|
40 |
|
---|
41 | it 'decimal sign should not be comma' do
|
---|
42 | @iso8601time.is_decimal_sign_comma?.should_not be_true
|
---|
43 | end
|
---|
44 |
|
---|
45 | it 'should be extended' do
|
---|
46 | @iso8601time.is_extended?.should be_true
|
---|
47 | end
|
---|
48 |
|
---|
49 | it 'should not be partial' do
|
---|
50 | @iso8601time.is_partial?.should_not be true
|
---|
51 | end
|
---|
52 |
|
---|
53 | describe 'hour behavior' do
|
---|
54 | it 'should raise ArgumentError with nil hour' do
|
---|
55 | lambda {
|
---|
56 | @iso8601time.hour = nil
|
---|
57 | }.should raise_error ArgumentError
|
---|
58 | end
|
---|
59 |
|
---|
60 | it 'should not raise ArgumentError with -1 hour' do
|
---|
61 | lambda {
|
---|
62 | @iso8601time.hour = -1
|
---|
63 | }.should raise_error ArgumentError
|
---|
64 | end
|
---|
65 |
|
---|
66 | it 'should not raise ArgumentError with 0 hour' do
|
---|
67 | lambda {
|
---|
68 | @iso8601time.hour = 0
|
---|
69 | }.should_not raise_error ArgumentError
|
---|
70 | end
|
---|
71 |
|
---|
72 | it 'should not raise ArgumentError with 23 hour' do
|
---|
73 | lambda {
|
---|
74 | @iso8601time.hour = 23
|
---|
75 | }.should_not raise_error ArgumentError
|
---|
76 | end
|
---|
77 |
|
---|
78 | it 'should not raise ArgumentError with 24 hour' do
|
---|
79 | lambda {
|
---|
80 | @iso8601time.hour = 24
|
---|
81 | }.should raise_error ArgumentError
|
---|
82 | end
|
---|
83 | end
|
---|
84 |
|
---|
85 | describe 'minute behavior' do
|
---|
86 | it 'should raise ArgumentError with -1 miniute' do
|
---|
87 | lambda {
|
---|
88 | @iso8601time.minute = -1
|
---|
89 | }.should raise_error ArgumentError
|
---|
90 | end
|
---|
91 |
|
---|
92 | it 'should not raise ArgumentError with 0 minute' do
|
---|
93 | lambda {
|
---|
94 | @iso8601time.minute = 0
|
---|
95 | }.should_not raise_error ArgumentError
|
---|
96 | end
|
---|
97 |
|
---|
98 | it 'should not raise ArgumentError with 59 minute' do
|
---|
99 | lambda {
|
---|
100 | @iso8601time.minute = 59
|
---|
101 | }.should_not raise_error ArgumentError
|
---|
102 | end
|
---|
103 |
|
---|
104 | it 'should raise ArgumentError with 60 minute' do
|
---|
105 | lambda {
|
---|
106 | @iso8601time.minute = 60
|
---|
107 | }.should raise_error ArgumentError
|
---|
108 | end
|
---|
109 | end
|
---|
110 |
|
---|
111 | describe 'second behavior' do
|
---|
112 | it 'should raise ArgumentError with -1 miniute' do
|
---|
113 | lambda {
|
---|
114 | @iso8601time.second = -1
|
---|
115 | }.should raise_error ArgumentError
|
---|
116 | end
|
---|
117 |
|
---|
118 | it 'should not raise ArgumentError with 0 second' do
|
---|
119 | lambda {
|
---|
120 | @iso8601time.second = 0
|
---|
121 | }.should_not raise_error ArgumentError
|
---|
122 | end
|
---|
123 |
|
---|
124 | it 'should not raise ArgumentError with 59 second' do
|
---|
125 | lambda {
|
---|
126 | @iso8601time.second = 59
|
---|
127 | }.should_not raise_error ArgumentError
|
---|
128 | end
|
---|
129 |
|
---|
130 | it 'should raise ArgumentError with 60 second' do
|
---|
131 | lambda {
|
---|
132 | @iso8601time.second = 60
|
---|
133 | }.should raise_error ArgumentError
|
---|
134 | end
|
---|
135 | end
|
---|
136 |
|
---|
137 | describe 'fractional second behavior' do
|
---|
138 | it 'should raise ArgumentError less than -0.0' do
|
---|
139 | lambda {
|
---|
140 | @iso8601time.fractional_second = -0.1
|
---|
141 | }.should raise_error ArgumentError
|
---|
142 | end
|
---|
143 |
|
---|
144 | it 'should raise ArgumentError more than 1.0' do
|
---|
145 | lambda {
|
---|
146 | @iso8601time.fractional_second = 1.0
|
---|
147 | }.should raise_error ArgumentError
|
---|
148 | end
|
---|
149 | end
|
---|
150 |
|
---|
151 | describe 'timezone behavior' do
|
---|
152 | it 'should raise ArgumentError with invalid timezone' do
|
---|
153 | lambda {
|
---|
154 | @iso8601time.timezone = '+AbD:111'
|
---|
155 | }.should raise_error ArgumentError
|
---|
156 | end
|
---|
157 |
|
---|
158 | it 'should allow ArgumentError with nil timezone' do
|
---|
159 | lambda {
|
---|
160 | @iso8601time.timezone = nil
|
---|
161 | }.should_not raise_error ArgumentError
|
---|
162 | end
|
---|
163 | end
|
---|
164 |
|
---|
165 | describe 'constructor behavior' do
|
---|
166 | it 'should_not raise ArgumentError with 21:18:09.01' do
|
---|
167 | lambda {
|
---|
168 | ISO8601Time.new('21:18:09.01')
|
---|
169 | }.should_not raise_error ArgumentError
|
---|
170 | end
|
---|
171 |
|
---|
172 | it 'should_not raise ArgumentError with 21:18:09' do
|
---|
173 | lambda {
|
---|
174 | ISO8601Time.new('21:18:09')
|
---|
175 | }.should_not raise_error ArgumentError
|
---|
176 | end
|
---|
177 |
|
---|
178 | it 'should_not raise ArgumentError with 21:18' do
|
---|
179 | lambda {
|
---|
180 | ISO8601Time.new('21:18')
|
---|
181 | }.should_not raise_error ArgumentError
|
---|
182 | end
|
---|
183 |
|
---|
184 | it 'should_not raise ArgumentError with 21' do
|
---|
185 | lambda {
|
---|
186 | ISO8601Time.new('21')
|
---|
187 | }.should_not raise_error ArgumentError
|
---|
188 | end
|
---|
189 |
|
---|
190 | it 'should raise ArgumentError with malformation' do
|
---|
191 | lambda {
|
---|
192 | ISO8601Time.new('ABDCD')
|
---|
193 | }.should raise_error ArgumentError
|
---|
194 | end
|
---|
195 | end
|
---|
196 |
|
---|
197 | describe 'ISO8601 time validation' do
|
---|
198 | it 'should be valid iso8601 Time' do
|
---|
199 | ISO8601Time.should be_valid_iso8601_time '21:24:30.05+09:00'
|
---|
200 | end
|
---|
201 |
|
---|
202 | it 'should not be valid with over 24 hour' do
|
---|
203 | ISO8601Time.should_not be_valid_iso8601_time '24:24:30.05+09:00'
|
---|
204 | end
|
---|
205 |
|
---|
206 | it 'should be valid with over 24:00:00' do
|
---|
207 | ISO8601Time.should be_valid_iso8601_time '24:00:00.00'
|
---|
208 | end
|
---|
209 |
|
---|
210 | it 'should not vaild with under 0 hour' do
|
---|
211 | ISO8601Time.should_not be_valid_iso8601_time '-1:24:30.05+09:00'
|
---|
212 | end
|
---|
213 |
|
---|
214 | it 'should not valid with more than 60 minutes' do
|
---|
215 | ISO8601Time.should_not be_valid_iso8601_time '21:60:30'
|
---|
216 | end
|
---|
217 |
|
---|
218 | it 'should not valid with more than 60 seconds' do
|
---|
219 | ISO8601Time.should_not be_valid_iso8601_time '21:34:60'
|
---|
220 | end
|
---|
221 |
|
---|
222 | it 'should not valid with invalid hour in timezone' do
|
---|
223 | ISO8601Time.should_not be_valid_iso8601_time '21:24:30.05+24:00'
|
---|
224 | end
|
---|
225 |
|
---|
226 | it 'should not valid with invalid minute in timezone' do
|
---|
227 | ISO8601Time.should_not be_valid_iso8601_time '21:24:30.05+22:60'
|
---|
228 | end
|
---|
229 |
|
---|
230 | it 'should not valid with invalid minute in timezone' do
|
---|
231 | ISO8601Time.should_not be_valid_iso8601_time '21:24:30.05TAABZ'
|
---|
232 | end
|
---|
233 | end
|
---|
234 | end
|
---|