adlint 1.10.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +197 -4
- data/MANIFEST +17 -0
- data/NEWS +23 -4
- data/etc/mesg.d/en_US/messages.yml +14 -1
- data/etc/mesg.d/ja_JP/messages.yml +14 -1
- data/features/message_detection/W0093.feature +87 -0
- data/features/message_detection/W0687.feature +25 -0
- data/features/message_detection/W0688.feature +63 -0
- data/features/message_detection/W0689.feature +46 -0
- data/features/message_detection/W0690.feature +35 -0
- data/features/message_detection/W0698.feature +3 -2
- data/features/message_detection/W0703.feature +1 -0
- data/features/message_detection/W0723.feature +34 -0
- data/features/message_detection/W0732.feature +158 -0
- data/features/message_detection/W0733.feature +158 -0
- data/features/message_detection/W0734.feature +322 -0
- data/features/message_detection/W0735.feature +322 -0
- data/features/message_detection/W1052.feature +66 -0
- data/features/message_detection/W9001.feature +33 -0
- data/features/message_detection/W9003.feature +131 -0
- data/lib/adlint/c/ctrlexpr.rb +51 -50
- data/lib/adlint/c/domain.rb +237 -223
- data/lib/adlint/c/expr.rb +6 -8
- data/lib/adlint/c/interp.rb +8 -11
- data/lib/adlint/c/message.rb +20 -0
- data/lib/adlint/c/message_shima.rb +63 -0
- data/lib/adlint/c/object.rb +5 -4
- data/lib/adlint/c/operator.rb +99 -0
- data/lib/adlint/c/parser.rb +2 -2
- data/lib/adlint/c/parser.y +2 -2
- data/lib/adlint/c/phase.rb +6 -1
- data/lib/adlint/c/syntax.rb +442 -30
- data/lib/adlint/c/type.rb +449 -363
- data/lib/adlint/c/value.rb +96 -25
- data/lib/adlint/c.rb +1 -0
- data/lib/adlint/prelude.rb +16 -18
- data/lib/adlint/version.rb +2 -2
- data/share/doc/developers_guide_ja.html +11 -5
- data/share/doc/developers_guide_ja.texi +9 -3
- data/share/doc/users_guide_en.html +697 -131
- data/share/doc/users_guide_en.texi +491 -41
- data/share/doc/users_guide_ja.html +709 -139
- data/share/doc/users_guide_ja.texi +499 -45
- data/spec/adlint/c/ctrlexpr_spec.rb +168 -0
- data/spec/adlint/c/domain_spec.rb +835 -0
- data/spec/adlint/c/operator_spec.rb +406 -0
- data/spec/adlint/c/syntax_spec.rb +717 -0
- data/spec/adlint/c/type_spec.rb +55 -30
- metadata +19 -2
@@ -0,0 +1,835 @@
|
|
1
|
+
# Unit specification of domain of values bound to variables.
|
2
|
+
#
|
3
|
+
# Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
|
4
|
+
# Copyright:: Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
|
5
|
+
# License:: GPLv3+: GNU General Public License version 3 or later
|
6
|
+
#
|
7
|
+
# Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
|
8
|
+
|
9
|
+
#--
|
10
|
+
# ___ ____ __ ___ _________
|
11
|
+
# / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
|
12
|
+
# / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
|
13
|
+
# / __ |/ /_/ / /___/ / /| / / /
|
14
|
+
# /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
|
15
|
+
#
|
16
|
+
# This file is part of AdLint.
|
17
|
+
#
|
18
|
+
# AdLint is free software: you can redistribute it and/or modify it under the
|
19
|
+
# terms of the GNU General Public License as published by the Free Software
|
20
|
+
# Foundation, either version 3 of the License, or (at your option) any later
|
21
|
+
# version.
|
22
|
+
#
|
23
|
+
# AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
|
24
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
25
|
+
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
26
|
+
#
|
27
|
+
# You should have received a copy of the GNU General Public License along with
|
28
|
+
# AdLint. If not, see <http://www.gnu.org/licenses/>.
|
29
|
+
#
|
30
|
+
#++
|
31
|
+
|
32
|
+
require "spec_helper"
|
33
|
+
|
34
|
+
module AdLint
|
35
|
+
module C
|
36
|
+
|
37
|
+
describe ValueDomain do
|
38
|
+
describe EqualToValueDomain do
|
39
|
+
context "(== -2147483648)" do
|
40
|
+
subject { ValueDomain.equal_to(-2147483648) }
|
41
|
+
|
42
|
+
it "should contain (== -2147483648)" do
|
43
|
+
subject.contain?(ValueDomain.equal_to(-2147483648)).should be_true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should not contain (== 2147483647)" do
|
47
|
+
subject.contain?(ValueDomain.equal_to(2147483647)).should be_false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "(== 2147483647)" do
|
52
|
+
subject { ValueDomain.equal_to(2147483647) }
|
53
|
+
|
54
|
+
it "should not contain (== -2147483648)" do
|
55
|
+
subject.contain?(ValueDomain.equal_to(-2147483648)).should be_false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "(== 2)" do
|
60
|
+
subject { ValueDomain.equal_to(2) }
|
61
|
+
|
62
|
+
it "* (== 3) should be (== 6)" do
|
63
|
+
rhs = ValueDomain.equal_to(3)
|
64
|
+
(subject * rhs).to_s.should == "(== 6)"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "* (== 0) should be (== 0)" do
|
68
|
+
rhs = ValueDomain.equal_to(0)
|
69
|
+
(subject * rhs).to_s.should == "(== 0)"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "* (== -3) should be (== -6)" do
|
73
|
+
rhs = ValueDomain.equal_to(-3)
|
74
|
+
(subject * rhs).to_s.should == "(== -6)"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "* (< 3) should be (< 6)" do
|
78
|
+
rhs = ValueDomain.less_than(3)
|
79
|
+
(subject * rhs).to_s.should == "(< 6)"
|
80
|
+
end
|
81
|
+
|
82
|
+
it "* (< 0) should be (< 0)" do
|
83
|
+
rhs = ValueDomain.less_than(0)
|
84
|
+
(subject * rhs).to_s.should == "(< 0)"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "* (< -3) should be (< -6)" do
|
88
|
+
rhs = ValueDomain.less_than(-3)
|
89
|
+
(subject * rhs).to_s.should == "(< -6)"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "* (> 3) should be (> 6)" do
|
93
|
+
rhs = ValueDomain.greater_than(3)
|
94
|
+
(subject * rhs).to_s.should == "(> 6)"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "* (> 0) should be (> 0)" do
|
98
|
+
rhs = ValueDomain.greater_than(0)
|
99
|
+
(subject * rhs).to_s.should == "(> 0)"
|
100
|
+
end
|
101
|
+
|
102
|
+
it "* (> -3) should be (> -6)" do
|
103
|
+
rhs = ValueDomain.greater_than(-3)
|
104
|
+
(subject * rhs).to_s.should == "(> -6)"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "(== 0)" do
|
109
|
+
subject { ValueDomain.equal_to(0) }
|
110
|
+
|
111
|
+
it "* (== 3) should be (== 0)" do
|
112
|
+
rhs = ValueDomain.equal_to(3)
|
113
|
+
(subject * rhs).to_s.should == "(== 0)"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "* (== 0) should be (== 0)" do
|
117
|
+
rhs = ValueDomain.equal_to(0)
|
118
|
+
(subject * rhs).to_s.should == "(== 0)"
|
119
|
+
end
|
120
|
+
|
121
|
+
it "* (== -3) should be (== 0)" do
|
122
|
+
rhs = ValueDomain.equal_to(-3)
|
123
|
+
(subject * rhs).to_s.should == "(== 0)"
|
124
|
+
end
|
125
|
+
|
126
|
+
it "* (< 3) should be (== 0)" do
|
127
|
+
rhs = ValueDomain.less_than(3)
|
128
|
+
(subject * rhs).to_s.should == "(== 0)"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "* (< 0) should be (== 0)" do
|
132
|
+
rhs = ValueDomain.less_than(0)
|
133
|
+
(subject * rhs).to_s.should == "(== 0)"
|
134
|
+
end
|
135
|
+
|
136
|
+
it "* (< -3) should be (== 0)" do
|
137
|
+
rhs = ValueDomain.less_than(-3)
|
138
|
+
(subject * rhs).to_s.should == "(== 0)"
|
139
|
+
end
|
140
|
+
|
141
|
+
it "* (> 3) should be (== 0)" do
|
142
|
+
rhs = ValueDomain.greater_than(3)
|
143
|
+
(subject * rhs).to_s.should == "(== 0)"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "* (> 0) should be (== 0)" do
|
147
|
+
rhs = ValueDomain.greater_than(0)
|
148
|
+
(subject * rhs).to_s.should == "(== 0)"
|
149
|
+
end
|
150
|
+
|
151
|
+
it "* (> -3) should be (== 0)" do
|
152
|
+
rhs = ValueDomain.greater_than(-3)
|
153
|
+
(subject * rhs).to_s.should == "(== 0)"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "(== -2)" do
|
158
|
+
subject { ValueDomain.equal_to(-2) }
|
159
|
+
|
160
|
+
it "* (== 3) should be (== -6)" do
|
161
|
+
rhs = ValueDomain.equal_to(3)
|
162
|
+
(subject * rhs).to_s.should == "(== -6)"
|
163
|
+
end
|
164
|
+
|
165
|
+
it "* (== 0) should be (== 0)" do
|
166
|
+
rhs = ValueDomain.equal_to(0)
|
167
|
+
(subject * rhs).to_s.should == "(== 0)"
|
168
|
+
end
|
169
|
+
|
170
|
+
it "* (== -3) should be (== 6)" do
|
171
|
+
rhs = ValueDomain.equal_to(-3)
|
172
|
+
(subject * rhs).to_s.should == "(== 6)"
|
173
|
+
end
|
174
|
+
|
175
|
+
it "* (< 3) should be (> -6)" do
|
176
|
+
rhs = ValueDomain.less_than(3)
|
177
|
+
(subject * rhs).to_s.should == "(> -6)"
|
178
|
+
end
|
179
|
+
|
180
|
+
it "* (< 0) should be (> 0)" do
|
181
|
+
rhs = ValueDomain.less_than(0)
|
182
|
+
(subject * rhs).to_s.should == "(> 0)"
|
183
|
+
end
|
184
|
+
|
185
|
+
it "* (< -3) should be (> 6)" do
|
186
|
+
rhs = ValueDomain.less_than(-3)
|
187
|
+
(subject * rhs).to_s.should == "(> 6)"
|
188
|
+
end
|
189
|
+
|
190
|
+
it "* (> 3) should be (< -6)" do
|
191
|
+
rhs = ValueDomain.greater_than(3)
|
192
|
+
(subject * rhs).to_s.should == "(< -6)"
|
193
|
+
end
|
194
|
+
|
195
|
+
it "* (> 0) should be (< 0)" do
|
196
|
+
rhs = ValueDomain.greater_than(0)
|
197
|
+
(subject * rhs).to_s.should == "(< 0)"
|
198
|
+
end
|
199
|
+
|
200
|
+
it "* (> -3) should be (< 6)" do
|
201
|
+
rhs = ValueDomain.greater_than(-3)
|
202
|
+
(subject * rhs).to_s.should == "(< 6)"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe LessThanValueDomain do
|
208
|
+
context "(< 128)" do
|
209
|
+
subject { ValueDomain.less_than(128) }
|
210
|
+
|
211
|
+
it "< (== 127) should be (== Unlimited)" do
|
212
|
+
rhs = ValueDomain.equal_to(127)
|
213
|
+
(subject < rhs).to_s.should == "(== Unlimited)"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context "(< 2)" do
|
218
|
+
subject { ValueDomain.less_than(2) }
|
219
|
+
|
220
|
+
it "* (== 3) should be (< 6)" do
|
221
|
+
rhs = ValueDomain.equal_to(3)
|
222
|
+
(subject * rhs).to_s.should == "(< 6)"
|
223
|
+
end
|
224
|
+
|
225
|
+
it "* (== 0) should be (== 0)" do
|
226
|
+
rhs = ValueDomain.equal_to(0)
|
227
|
+
(subject * rhs).to_s.should == "(== 0)"
|
228
|
+
end
|
229
|
+
|
230
|
+
it "* (== -3) should be (> -6)" do
|
231
|
+
rhs = ValueDomain.equal_to(-3)
|
232
|
+
(subject * rhs).to_s.should == "(> -6)"
|
233
|
+
end
|
234
|
+
|
235
|
+
it "* (< 3) should be (== Unlimited)" do
|
236
|
+
rhs = ValueDomain.less_than(3)
|
237
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
238
|
+
end
|
239
|
+
|
240
|
+
it "* (< 0) should be (== Unlimited)" do
|
241
|
+
rhs = ValueDomain.less_than(0)
|
242
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
243
|
+
end
|
244
|
+
|
245
|
+
it "* (< -3) should be (== Unlimited)" do
|
246
|
+
rhs = ValueDomain.less_than(-3)
|
247
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
248
|
+
end
|
249
|
+
|
250
|
+
it "* (> 3) should be (== Unlimited)" do
|
251
|
+
rhs = ValueDomain.greater_than(3)
|
252
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
253
|
+
end
|
254
|
+
|
255
|
+
it "* (> 0) should be (== Unlimited)" do
|
256
|
+
rhs = ValueDomain.greater_than(0)
|
257
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
258
|
+
end
|
259
|
+
|
260
|
+
it "* (> -3) should be (== Unlimited)" do
|
261
|
+
rhs = ValueDomain.greater_than(-3)
|
262
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
context "(< 0)" do
|
267
|
+
subject { ValueDomain.less_than(0) }
|
268
|
+
|
269
|
+
it "* (== 3) should be (< 0)" do
|
270
|
+
rhs = ValueDomain.equal_to(3)
|
271
|
+
(subject * rhs).to_s.should == "(< 0)"
|
272
|
+
end
|
273
|
+
|
274
|
+
it "* (== 0) should be (== 0)" do
|
275
|
+
rhs = ValueDomain.equal_to(0)
|
276
|
+
(subject * rhs).to_s.should == "(== 0)"
|
277
|
+
end
|
278
|
+
|
279
|
+
it "* (== -3) should be (> 0)" do
|
280
|
+
rhs = ValueDomain.equal_to(-3)
|
281
|
+
(subject * rhs).to_s.should == "(> 0)"
|
282
|
+
end
|
283
|
+
|
284
|
+
it "* (< 3) should be (== Unlimited)" do
|
285
|
+
rhs = ValueDomain.less_than(3)
|
286
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
287
|
+
end
|
288
|
+
|
289
|
+
it "* (< 0) should be (> 0)" do
|
290
|
+
rhs = ValueDomain.less_than(0)
|
291
|
+
(subject * rhs).to_s.should == "(> 0)"
|
292
|
+
end
|
293
|
+
|
294
|
+
it "* (< -3) should be (> 0)" do
|
295
|
+
rhs = ValueDomain.less_than(-3)
|
296
|
+
(subject * rhs).to_s.should == "(> 0)"
|
297
|
+
end
|
298
|
+
|
299
|
+
it "* (> 3) should be (< 0)" do
|
300
|
+
rhs = ValueDomain.greater_than(3)
|
301
|
+
(subject * rhs).to_s.should == "(< 0)"
|
302
|
+
end
|
303
|
+
|
304
|
+
it "* (> 0) should be (< 0)" do
|
305
|
+
rhs = ValueDomain.greater_than(0)
|
306
|
+
(subject * rhs).to_s.should == "(< 0)"
|
307
|
+
end
|
308
|
+
|
309
|
+
it "* (> -3) should be (== Unlimited)" do
|
310
|
+
rhs = ValueDomain.greater_than(-3)
|
311
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context "(< -2)" do
|
316
|
+
subject { ValueDomain.less_than(-2) }
|
317
|
+
|
318
|
+
it "* (== 3) should be (< -6)" do
|
319
|
+
rhs = ValueDomain.equal_to(3)
|
320
|
+
(subject * rhs).to_s.should == "(< -6)"
|
321
|
+
end
|
322
|
+
|
323
|
+
it "* (== 0) should be (== 0)" do
|
324
|
+
rhs = ValueDomain.equal_to(0)
|
325
|
+
(subject * rhs).to_s.should == "(== 0)"
|
326
|
+
end
|
327
|
+
|
328
|
+
it "* (== -3) should be (> 6)" do
|
329
|
+
rhs = ValueDomain.equal_to(-3)
|
330
|
+
(subject * rhs).to_s.should == "(> 6)"
|
331
|
+
end
|
332
|
+
|
333
|
+
it "* (< 3) should be (== Unlimited)" do
|
334
|
+
rhs = ValueDomain.less_than(3)
|
335
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
336
|
+
end
|
337
|
+
|
338
|
+
it "* (< 0) should be (> 0)" do
|
339
|
+
rhs = ValueDomain.less_than(0)
|
340
|
+
(subject * rhs).to_s.should == "(> 0)"
|
341
|
+
end
|
342
|
+
|
343
|
+
it "* (< -3) should be (> 6)" do
|
344
|
+
rhs = ValueDomain.less_than(-3)
|
345
|
+
(subject * rhs).to_s.should == "(> 6)"
|
346
|
+
end
|
347
|
+
|
348
|
+
it "* (> 3) should be (< -6)" do
|
349
|
+
rhs = ValueDomain.greater_than(3)
|
350
|
+
(subject * rhs).to_s.should == "(< -6)"
|
351
|
+
end
|
352
|
+
|
353
|
+
it "* (> 0) should be (< 0)" do
|
354
|
+
rhs = ValueDomain.greater_than(0)
|
355
|
+
(subject * rhs).to_s.should == "(< 0)"
|
356
|
+
end
|
357
|
+
|
358
|
+
it "* (> -3) should be (== Unlimited)" do
|
359
|
+
rhs = ValueDomain.greater_than(-3)
|
360
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
describe GreaterThanValueDomain do
|
366
|
+
context "(> -129)" do
|
367
|
+
subject { ValueDomain.greater_than(-129) }
|
368
|
+
|
369
|
+
it "< (== 127) should be (== Unlimited)" do
|
370
|
+
rhs = ValueDomain.equal_to(127)
|
371
|
+
(subject < rhs).to_s.should == "(== Unlimited)"
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
context "(> 2)" do
|
376
|
+
subject { ValueDomain.greater_than(2) }
|
377
|
+
|
378
|
+
it "* (== 3) should be (> 6)" do
|
379
|
+
rhs = ValueDomain.equal_to(3)
|
380
|
+
(subject * rhs).to_s.should == "(> 6)"
|
381
|
+
end
|
382
|
+
|
383
|
+
it "* (== 0) should be (== 0)" do
|
384
|
+
rhs = ValueDomain.equal_to(0)
|
385
|
+
(subject * rhs).to_s.should == "(== 0)"
|
386
|
+
end
|
387
|
+
|
388
|
+
it "* (== -3) should be (< -6)" do
|
389
|
+
rhs = ValueDomain.equal_to(-3)
|
390
|
+
(subject * rhs).to_s.should == "(< -6)"
|
391
|
+
end
|
392
|
+
|
393
|
+
it "* (< 3) should be (== Unlimited)" do
|
394
|
+
rhs = ValueDomain.less_than(3)
|
395
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
396
|
+
end
|
397
|
+
|
398
|
+
it "* (< 0) should be (< 0)" do
|
399
|
+
rhs = ValueDomain.less_than(0)
|
400
|
+
(subject * rhs).to_s.should == "(< 0)"
|
401
|
+
end
|
402
|
+
|
403
|
+
it "* (< -3) should be (< -6)" do
|
404
|
+
rhs = ValueDomain.less_than(-3)
|
405
|
+
(subject * rhs).to_s.should == "(< -6)"
|
406
|
+
end
|
407
|
+
|
408
|
+
it "* (> 3) should be (> 6)" do
|
409
|
+
rhs = ValueDomain.greater_than(3)
|
410
|
+
(subject * rhs).to_s.should == "(> 6)"
|
411
|
+
end
|
412
|
+
|
413
|
+
it "* (> 0) should be (> 0)" do
|
414
|
+
rhs = ValueDomain.greater_than(0)
|
415
|
+
(subject * rhs).to_s.should == "(> 0)"
|
416
|
+
end
|
417
|
+
|
418
|
+
it "* (> -3) should be (== Unlimited)" do
|
419
|
+
rhs = ValueDomain.greater_than(-3)
|
420
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
context "(> 0)" do
|
425
|
+
subject { ValueDomain.greater_than(0) }
|
426
|
+
|
427
|
+
it "* (== 3) should be (> 0)" do
|
428
|
+
rhs = ValueDomain.equal_to(3)
|
429
|
+
(subject * rhs).to_s.should == "(> 0)"
|
430
|
+
end
|
431
|
+
|
432
|
+
it "* (== 0) should be (== 0)" do
|
433
|
+
rhs = ValueDomain.equal_to(0)
|
434
|
+
(subject * rhs).to_s.should == "(== 0)"
|
435
|
+
end
|
436
|
+
|
437
|
+
it "* (== -3) should be (< 0)" do
|
438
|
+
rhs = ValueDomain.equal_to(-3)
|
439
|
+
(subject * rhs).to_s.should == "(< 0)"
|
440
|
+
end
|
441
|
+
|
442
|
+
it "* (< 3) should be (== Unlimited)" do
|
443
|
+
rhs = ValueDomain.less_than(3)
|
444
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
445
|
+
end
|
446
|
+
|
447
|
+
it "* (< 0) should be (< 0)" do
|
448
|
+
rhs = ValueDomain.less_than(0)
|
449
|
+
(subject * rhs).to_s.should == "(< 0)"
|
450
|
+
end
|
451
|
+
|
452
|
+
it "* (< -3) should be (< 0)" do
|
453
|
+
rhs = ValueDomain.less_than(-3)
|
454
|
+
(subject * rhs).to_s.should == "(< 0)"
|
455
|
+
end
|
456
|
+
|
457
|
+
it "* (> 3) should be (> 0)" do
|
458
|
+
rhs = ValueDomain.greater_than(3)
|
459
|
+
(subject * rhs).to_s.should == "(> 0)"
|
460
|
+
end
|
461
|
+
|
462
|
+
it "* (> 0) should be (> 0)" do
|
463
|
+
rhs = ValueDomain.greater_than(0)
|
464
|
+
(subject * rhs).to_s.should == "(> 0)"
|
465
|
+
end
|
466
|
+
|
467
|
+
it "* (> -3) should be (== Unlimited)" do
|
468
|
+
rhs = ValueDomain.greater_than(-3)
|
469
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
context "(> -2)" do
|
474
|
+
subject { ValueDomain.greater_than(-2) }
|
475
|
+
|
476
|
+
it "* (== 3) should be (> -6)" do
|
477
|
+
rhs = ValueDomain.equal_to(3)
|
478
|
+
(subject * rhs).to_s.should == "(> -6)"
|
479
|
+
end
|
480
|
+
|
481
|
+
it "* (== 0) should be (== 0)" do
|
482
|
+
rhs = ValueDomain.equal_to(0)
|
483
|
+
(subject * rhs).to_s.should == "(== 0)"
|
484
|
+
end
|
485
|
+
|
486
|
+
it "* (== -3) should be (< 6)" do
|
487
|
+
rhs = ValueDomain.equal_to(-3)
|
488
|
+
(subject * rhs).to_s.should == "(< 6)"
|
489
|
+
end
|
490
|
+
|
491
|
+
it "* (< 3) should be (== Unlimited)" do
|
492
|
+
rhs = ValueDomain.less_than(3)
|
493
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
494
|
+
end
|
495
|
+
|
496
|
+
it "* (< 0) should be (== Unlimited)" do
|
497
|
+
rhs = ValueDomain.less_than(0)
|
498
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
499
|
+
end
|
500
|
+
|
501
|
+
it "* (< -3) should be (== Unlimited)" do
|
502
|
+
rhs = ValueDomain.less_than(-3)
|
503
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
504
|
+
end
|
505
|
+
|
506
|
+
it "* (> 3) should be (== Unlimited)" do
|
507
|
+
rhs = ValueDomain.greater_than(3)
|
508
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
509
|
+
end
|
510
|
+
|
511
|
+
it "* (> 0) should be (== Unlimited)" do
|
512
|
+
rhs = ValueDomain.greater_than(0)
|
513
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
514
|
+
end
|
515
|
+
|
516
|
+
it "* (> -3) should be (== Unlimited)" do
|
517
|
+
rhs = ValueDomain.greater_than(-3)
|
518
|
+
(subject * rhs).to_s.should == "(== Unlimited)"
|
519
|
+
end
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
describe CompositeValueDomain do
|
524
|
+
context "(== (((< 10) || (== 10)) && ((== -10) || (> -10))))" do
|
525
|
+
subject do
|
526
|
+
tmp = ValueDomain.greater_than_or_equal_to(-10)
|
527
|
+
tmp.intersection(ValueDomain.less_than_or_equal_to(10))
|
528
|
+
end
|
529
|
+
|
530
|
+
it "should contain ((== -5) || (== 5))" do
|
531
|
+
rhs = ValueDomain.equal_to(-5).union(ValueDomain.equal_to(5))
|
532
|
+
subject.contain?(rhs).should be_true
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
context "((== -5) || (== 5))" do
|
537
|
+
subject { ValueDomain.equal_to(-5).union(ValueDomain.equal_to(5)) }
|
538
|
+
|
539
|
+
it "should not contain " +
|
540
|
+
"(((< 10) || (== 10)) && ((== -10) || (> -10)))" do
|
541
|
+
rhs = ValueDomain.greater_than_or_equal_to(-10)
|
542
|
+
rhs = rhs.intersection(ValueDomain.less_than_or_equal_to(10))
|
543
|
+
subject.contain?(rhs).should be_false
|
544
|
+
end
|
545
|
+
|
546
|
+
it "should be contained by " +
|
547
|
+
"(((< 10) || (== 10)) && ((== -10) || (> -10)))" do
|
548
|
+
lhs = ValueDomain.greater_than_or_equal_to(-10)
|
549
|
+
lhs = lhs.intersection(ValueDomain.less_than_or_equal_to(10))
|
550
|
+
lhs.contain?(subject).should be_true
|
551
|
+
end
|
552
|
+
|
553
|
+
it "intersection with (< 0) should be equal to (== -5)" do
|
554
|
+
rhs = ValueDomain.less_than(0)
|
555
|
+
subject.intersection(rhs).to_s.should == "(== -5)"
|
556
|
+
end
|
557
|
+
|
558
|
+
it "intersection with (> 0) should be equal to (== 5)" do
|
559
|
+
rhs = ValueDomain.greater_than(0)
|
560
|
+
subject.intersection(rhs).to_s.should == "(== 5)"
|
561
|
+
end
|
562
|
+
|
563
|
+
it "intersection with ((== -10) || (> -10)) " +
|
564
|
+
"should be equal to the subject domain" do
|
565
|
+
rhs = ValueDomain.greater_than_or_equal_to(-10)
|
566
|
+
subject.intersection(rhs).should == subject
|
567
|
+
end
|
568
|
+
|
569
|
+
it "intersection with ((== 10) || (< 10)) " +
|
570
|
+
"should be equal to the subject domain" do
|
571
|
+
rhs = ValueDomain.less_than_or_equal_to(10)
|
572
|
+
subject.intersection(rhs).should == subject
|
573
|
+
end
|
574
|
+
|
575
|
+
it "should not contain (((< 0) && (> -10)) || (== -10))" do
|
576
|
+
rhs = ValueDomain.greater_than_or_equal_to(-10)
|
577
|
+
rhs = rhs.intersection(ValueDomain.less_than_or_equal_to(10))
|
578
|
+
rhs = rhs.intersection(ValueDomain.less_than(0))
|
579
|
+
subject.contain?(rhs).should be_false
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
context "(((< 0) && (> -10)) || (== -10))" do
|
584
|
+
subject do
|
585
|
+
tmp = ValueDomain.greater_than_or_equal_to(-10)
|
586
|
+
tmp = tmp.intersection(ValueDomain.less_than_or_equal_to(10))
|
587
|
+
tmp.intersection(ValueDomain.less_than(0))
|
588
|
+
end
|
589
|
+
|
590
|
+
it "should not contain ((== -5) || (== 5))" do
|
591
|
+
rhs = ValueDomain.equal_to(-5).union(ValueDomain.equal_to(5))
|
592
|
+
subject.contain?(rhs).should be_false
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
context "(((< 0) && (> -2147483647)) || (== 0))" do
|
597
|
+
subject do
|
598
|
+
tmp = ValueDomain.less_than_or_equal_to(0)
|
599
|
+
tmp.intersection(ValueDomain.greater_than_or_equal_to(-2147483647))
|
600
|
+
end
|
601
|
+
|
602
|
+
it "union with ((== -2147483647) || (== 0)) should be " +
|
603
|
+
"((((< 0) && (> -2147483647)) || (== -2147483647)) || (== 0))" do
|
604
|
+
rhs = ValueDomain.equal_to(-2147483647)
|
605
|
+
rhs = rhs.union(ValueDomain.equal_to(0))
|
606
|
+
subject.union(rhs).to_s.should ==
|
607
|
+
"((((< 0) && (> -2147483647)) || (== -2147483647)) || (== 0))"
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
context "((== -2147483647) || (== 0))" do
|
612
|
+
subject do
|
613
|
+
ValueDomain.equal_to(-2147483647).union(ValueDomain.equal_to(0))
|
614
|
+
end
|
615
|
+
|
616
|
+
it "should contain ((== -2147483647) || (== 0))" do
|
617
|
+
rhs = ValueDomain.equal_to(-2147483647)
|
618
|
+
rhs = rhs.union(ValueDomain.equal_to(0))
|
619
|
+
subject.contain?(rhs).should be_true
|
620
|
+
end
|
621
|
+
|
622
|
+
it "should contain (== -2147483647)" do
|
623
|
+
subject.contain?(ValueDomain.equal_to(-2147483647)).should be_true
|
624
|
+
end
|
625
|
+
|
626
|
+
it "should contain (== 0)" do
|
627
|
+
subject.contain?(ValueDomain.equal_to(0)).should be_true
|
628
|
+
end
|
629
|
+
end
|
630
|
+
|
631
|
+
context "(((< 2147483647) && (> -2147483648)) || (== 2147483647))" do
|
632
|
+
subject do
|
633
|
+
tmp = ValueDomain.greater_than(-2147483648)
|
634
|
+
tmp = tmp.intersection(ValueDomain.less_than(2147483647))
|
635
|
+
tmp.union(ValueDomain.equal_to(2147483647))
|
636
|
+
end
|
637
|
+
|
638
|
+
it "cloned should be " +
|
639
|
+
"(((< 2147483647) && (> -2147483648)) || (== 2147483647))" do
|
640
|
+
subject.dup.to_s.should ==
|
641
|
+
"(((< 2147483647) && (> -2147483648)) || (== 2147483647))"
|
642
|
+
end
|
643
|
+
|
644
|
+
it "intersection with its cloned should be " +
|
645
|
+
"(((< 2147483647) && (> -2147483648)) || (== 2147483647))" do
|
646
|
+
subject.intersection(subject.dup).to_s.should ==
|
647
|
+
"(((< 2147483647) && (> -2147483648)) || (== 2147483647))"
|
648
|
+
end
|
649
|
+
|
650
|
+
it "union with its cloned should be " +
|
651
|
+
"(((< 2147483647) && (> -2147483648)) || (== 2147483647))" do
|
652
|
+
subject.union(subject.dup).to_s.should ==
|
653
|
+
"(((< 2147483647) && (> -2147483648)) || (== 2147483647))"
|
654
|
+
end
|
655
|
+
end
|
656
|
+
|
657
|
+
context "(((< 2147483647) && (> 1)) || (== 1))" do
|
658
|
+
subject do
|
659
|
+
tmp = ValueDomain.greater_than(1)
|
660
|
+
tmp = tmp.intersection(ValueDomain.less_than(2147483647))
|
661
|
+
tmp.union(ValueDomain.equal_to(1))
|
662
|
+
end
|
663
|
+
|
664
|
+
it "union with ((== 1) || (== 2147483647)) should be " +
|
665
|
+
"(((< 2147483647) && (> 1)) || ((== 1) || (== 2147483647)))" do
|
666
|
+
rhs = ValueDomain.equal_to(1)
|
667
|
+
rhs = rhs.union(ValueDomain.equal_to(2147483647))
|
668
|
+
subject.union(rhs).to_s.should ==
|
669
|
+
"(((< 2147483647) && (> 1)) || ((== 1) || (== 2147483647)))"
|
670
|
+
end
|
671
|
+
end
|
672
|
+
|
673
|
+
context "(((< 429) && (> 0)) || (== 429))" do
|
674
|
+
subject do
|
675
|
+
tmp = ValueDomain.greater_than(0)
|
676
|
+
tmp = tmp.intersection(ValueDomain.less_than(429))
|
677
|
+
tmp.union(ValueDomain.equal_to(429))
|
678
|
+
end
|
679
|
+
|
680
|
+
it "intersection with (== 0) should be (== Nil)" do
|
681
|
+
subject.intersection(ValueDomain.equal_to(0)).to_s.should ==
|
682
|
+
"(== Nil)"
|
683
|
+
end
|
684
|
+
end
|
685
|
+
|
686
|
+
context "(((< 10) || (== 10)) && ((== 0) || (> 0)))" do
|
687
|
+
subject do
|
688
|
+
ValueDomain.of_intersection(ValueDomain.greater_than_or_equal_to(0),
|
689
|
+
ValueDomain.less_than_or_equal_to(10))
|
690
|
+
end
|
691
|
+
|
692
|
+
it "+ (((< 10) || (== 10)) && ((== 0) || (> 0))) " +
|
693
|
+
"should be ((((< 20) && (> 0)) || (== 0)) || (== 20))" do
|
694
|
+
(subject + subject.dup).to_s.should ==
|
695
|
+
"((((< 20) && (> 0)) || (== 0)) || (== 20))"
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
context "((((< 10) && (> -10)) || (== 10)) || (== -10))" do
|
700
|
+
subject do
|
701
|
+
tmp = ValueDomain.greater_than_or_equal_to(-10)
|
702
|
+
tmp.intersection(ValueDomain.less_than_or_equal_to(10))
|
703
|
+
end
|
704
|
+
|
705
|
+
it "should intersect with (== 0)" do
|
706
|
+
subject.intersect?(ValueDomain.equal_to(0)).should be_true
|
707
|
+
end
|
708
|
+
|
709
|
+
it "< (== 0) should be (== Unlimited)" do
|
710
|
+
(subject < ValueDomain.equal_to(0)).to_s.should == "(== Unlimited)"
|
711
|
+
end
|
712
|
+
|
713
|
+
it "> (== 0) should be (== Unlimited)" do
|
714
|
+
(subject > ValueDomain.equal_to(0)).to_s.should == "(== Unlimited)"
|
715
|
+
end
|
716
|
+
|
717
|
+
it "== (== 0) should be (== Unlimited)" do
|
718
|
+
(subject == ValueDomain.equal_to(0)).to_s.should == "(== Unlimited)"
|
719
|
+
end
|
720
|
+
|
721
|
+
it "!= (== 0) should be (== Unlimited)" do
|
722
|
+
(subject != ValueDomain.equal_to(0)).to_s.should == "(== Unlimited)"
|
723
|
+
end
|
724
|
+
|
725
|
+
it "< (== 20) should be ((< 0) || (> 0))" do
|
726
|
+
(subject < ValueDomain.equal_to(20)).to_s.should ==
|
727
|
+
"((< 0) || (> 0))"
|
728
|
+
end
|
729
|
+
|
730
|
+
it "> (== 20) should be (== 0)" do
|
731
|
+
(subject > ValueDomain.equal_to(20)).to_s.should == "(== 0)"
|
732
|
+
end
|
733
|
+
end
|
734
|
+
|
735
|
+
context "(((< 11) && (> 1)) || (== 11))" do
|
736
|
+
subject do
|
737
|
+
tmp = ValueDomain.greater_than(1)
|
738
|
+
tmp = tmp.intersection(ValueDomain.less_than(11))
|
739
|
+
tmp.union(ValueDomain.equal_to(11))
|
740
|
+
end
|
741
|
+
|
742
|
+
it "narrowed by == ((((< 10) && (> 0)) || (== 10)) || (== 0)) " +
|
743
|
+
"should be (((< 10) && (> 1)) || (== 10))" do
|
744
|
+
rhs = ValueDomain.greater_than(0)
|
745
|
+
rhs = rhs.intersection(ValueDomain.less_than(10))
|
746
|
+
rhs = rhs.union(ValueDomain.equal_to(0))
|
747
|
+
rhs = rhs.union(ValueDomain.equal_to(10))
|
748
|
+
subject.narrow(Operator::EQ, rhs).to_s.should ==
|
749
|
+
"(((< 10) && (> 1)) || (== 10))"
|
750
|
+
end
|
751
|
+
end
|
752
|
+
|
753
|
+
context "((< 128) && (> -129))" do
|
754
|
+
subject do
|
755
|
+
tmp = ValueDomain.greater_than(-129)
|
756
|
+
tmp.intersection(ValueDomain.less_than(128))
|
757
|
+
end
|
758
|
+
|
759
|
+
it "should intersect with (== -128)" do
|
760
|
+
subject.intersect?(ValueDomain.equal_to(-128)).should be_true
|
761
|
+
end
|
762
|
+
|
763
|
+
it "should intersect with (== 127)" do
|
764
|
+
subject.intersect?(ValueDomain.equal_to(127)).should be_true
|
765
|
+
end
|
766
|
+
end
|
767
|
+
|
768
|
+
context "((((< 2147483647) && (> -2147483648)) || " +
|
769
|
+
"(== 2147483647)) || (== -2147483648))" do
|
770
|
+
subject do
|
771
|
+
tmp = ValueDomain.greater_than_or_equal_to(-2147483648)
|
772
|
+
tmp.intersection(ValueDomain.less_than_or_equal_to(2147483647))
|
773
|
+
end
|
774
|
+
|
775
|
+
it "narrowed by != (== 1) should be " +
|
776
|
+
"(((((< 1) && (> -2147483648)) || ((< 2147483647) && (> 1))) || " +
|
777
|
+
"(== 2147483647)) || (== -2147483648))" do
|
778
|
+
subject.narrow(Operator::NE, ValueDomain.equal_to(1)).to_s.should ==
|
779
|
+
"(((((< 1) && (> -2147483648)) || ((< 2147483647) && (> 1))) || " +
|
780
|
+
"(== 2147483647)) || (== -2147483648))"
|
781
|
+
end
|
782
|
+
end
|
783
|
+
|
784
|
+
context "(((< 10) && (> 0)) || (== 0))" do
|
785
|
+
subject do
|
786
|
+
tmp = ValueDomain.greater_than_or_equal_to(0)
|
787
|
+
tmp.intersection(ValueDomain.less_than(10))
|
788
|
+
end
|
789
|
+
|
790
|
+
it "narrowed by != its cloned should be (== Nil)" do
|
791
|
+
subject.narrow(Operator::NE, subject.dup).to_s.should == "(== Nil)"
|
792
|
+
end
|
793
|
+
end
|
794
|
+
|
795
|
+
context "((< 10) && (> 0))" do
|
796
|
+
subject do
|
797
|
+
tmp = ValueDomain.greater_than(0)
|
798
|
+
tmp.intersection(ValueDomain.less_than(10))
|
799
|
+
end
|
800
|
+
|
801
|
+
it "+ ((< 10) && (> 0)) should be ((< 10) && (> 0))" do
|
802
|
+
rhs = ValueDomain.greater_than(0)
|
803
|
+
rhs = rhs.intersection(ValueDomain.less_than(10))
|
804
|
+
(subject + rhs).to_s.should == "((< 20) && (> 0))"
|
805
|
+
end
|
806
|
+
|
807
|
+
it "* (== 2) should be ((< 20) && (> 0))" do
|
808
|
+
rhs = ValueDomain.equal_to(2)
|
809
|
+
(subject * rhs).to_s.should == "((< 20) && (> 0))"
|
810
|
+
end
|
811
|
+
|
812
|
+
it "* ((< 10) && (> 0)) should be ((< 100) && (> 0))" do
|
813
|
+
rhs = ValueDomain.greater_than(0)
|
814
|
+
rhs = rhs.intersection(ValueDomain.less_than(10))
|
815
|
+
(subject * rhs).to_s.should == "((< 100) && (> 0))"
|
816
|
+
end
|
817
|
+
|
818
|
+
it "/ (== 2) should be ((< 5) && (> 0))" do
|
819
|
+
rhs = ValueDomain.equal_to(2)
|
820
|
+
(subject / rhs).to_s.should == "((< 5) && (> 0))"
|
821
|
+
end
|
822
|
+
|
823
|
+
# TODO: Fix bad value-domain division before 1.14.0 GA release.
|
824
|
+
#it "/ ((< 10) && (> 0)) should be ((< 10) && (> 0))" do
|
825
|
+
# rhs = ValueDomain.greater_than(0)
|
826
|
+
# rhs = rhs.intersection(ValueDomain.less_than(10))
|
827
|
+
# File.open("dump", "w") { |io| PP.pp(subject / rhs, io) }
|
828
|
+
# (subject / rhs).to_s.should == "((< 10) && (> 0))"
|
829
|
+
#end
|
830
|
+
end
|
831
|
+
end
|
832
|
+
end
|
833
|
+
|
834
|
+
end
|
835
|
+
end
|