rtype 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +56 -117
- data/Rakefile +2 -2
- data/lib/rtype/behavior/core_ext.rb +132 -0
- data/lib/rtype/version.rb +1 -1
- data/lib/rtype.rb +20 -17
- data/spec/rtype_spec.rb +62 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 272dbec168fe9d7b24c0b73b7ba9096b4567cf40
|
4
|
+
data.tar.gz: 7a3323d9bf39563681e79f058f5f35cf595a8b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f10da6933a0dec59ff8b60d026b19fa365594721a7ff1e97b0729c93e3d2f5329c085056b72d172500e13345be26b897b945951998174c2c79b596cd726d132
|
7
|
+
data.tar.gz: 75e312d85ac8f8f7a8b84b780eb1eb8f2925fef496fbf5d299959fbb8414b74d14a5dcd1a5f87ae71680b2cca68d41b32fa4e02cebcc1d2811a23ffc887d8fe6
|
data/README.md
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/sputnikgugja/rtype.svg?branch=master)](https://travis-ci.org/sputnikgugja/rtype)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/github/sputnikgugja/rtype/badge.svg?branch=master)](https://coveralls.io/github/sputnikgugja/rtype?branch=master)
|
5
5
|
|
6
|
-
You can do the type checking in Ruby with this gem!
|
7
|
-
|
8
6
|
```ruby
|
9
7
|
require 'rtype'
|
10
8
|
|
@@ -38,10 +36,12 @@ Test::invert(state: 0)
|
|
38
36
|
|
39
37
|
## Features
|
40
38
|
- Provides type checking for arguments and return
|
41
|
-
-
|
39
|
+
- Provides type checking for [Keyword Argument](#keyword-argument)
|
42
40
|
- [Type checking for hash elements](#hash)
|
43
|
-
- [Duck
|
41
|
+
- [Duck Typing](#duck-typing)
|
42
|
+
- [Typed Array](#typed-array)
|
44
43
|
- Custom type behavior
|
44
|
+
- ...
|
45
45
|
|
46
46
|
## Installation
|
47
47
|
Run `gem install rtype` or add `gem 'rtype'` to your `Gemfile`
|
@@ -55,7 +55,7 @@ require 'rtype'
|
|
55
55
|
Rtype itself is pure-ruby gem. but you can make it more faster by using native extension.
|
56
56
|
|
57
57
|
#### Native extension for MRI
|
58
|
-
|
58
|
+
Run
|
59
59
|
```ruby
|
60
60
|
gem install rtype-native
|
61
61
|
```
|
@@ -63,10 +63,10 @@ or add to your `Gemfile`:
|
|
63
63
|
```ruby
|
64
64
|
gem 'rtype-native'
|
65
65
|
```
|
66
|
-
then, Rtype
|
66
|
+
then, Rtype uses it. (**Do not** `require 'rtype-native'`)
|
67
67
|
|
68
68
|
#### Java extension for JRuby
|
69
|
-
|
69
|
+
Run
|
70
70
|
```ruby
|
71
71
|
gem install rtype-java
|
72
72
|
```
|
@@ -74,67 +74,71 @@ or add to your `Gemfile`:
|
|
74
74
|
```ruby
|
75
75
|
gem 'rtype-java'
|
76
76
|
```
|
77
|
-
then, Rtype
|
77
|
+
then, Rtype uses it. (**Do not** `require 'rtype-java'`)
|
78
78
|
|
79
79
|
## Usage
|
80
80
|
|
81
81
|
### Supported Type Behaviors
|
82
82
|
- `Module`
|
83
|
-
-
|
84
|
-
- `Any` :
|
83
|
+
- Value must be of this module (`is_a?`)
|
84
|
+
- `Any` : Alias for `BasicObject` (means Any Object)
|
85
85
|
- `Boolean` : `true` or `false`
|
86
86
|
- `Symbol`
|
87
|
-
-
|
87
|
+
- Value must respond to a method with this name
|
88
88
|
- `Regexp`
|
89
|
-
-
|
89
|
+
- Value must match this regexp pattern
|
90
90
|
- `Range`
|
91
|
-
-
|
91
|
+
- Value must be included in this range
|
92
92
|
- `Array`
|
93
|
-
-
|
93
|
+
- Value can be any type in this array
|
94
94
|
- `Hash`
|
95
|
-
-
|
96
|
-
- Each of
|
97
|
-
-
|
95
|
+
- Value must be a hash
|
96
|
+
- Each of elements must be valid
|
97
|
+
- Value's keys must be equal to this hash's keys
|
98
98
|
- **String** key is **different** from **symbol** key
|
99
99
|
- vs. Keyword arguments (e.g.)
|
100
|
-
- `[{}]` is **not** hash
|
101
|
-
- `[{}, {}]` is
|
102
|
-
- `[{}, {}, {}]` is two
|
100
|
+
- `[{}]` is **not** hash argument. it is keyword argument, because its position is last
|
101
|
+
- `[{}, {}]` is hash argument (first) and keyword argument (second)
|
102
|
+
- `[{}, {}, {}]` is two hash argument (first, second) and keyword argument (last)
|
103
103
|
- `{}` is keyword argument. non-keyword arguments must be in array.
|
104
104
|
- Of course, nested hash works
|
105
105
|
- Example: [Hash](#hash)
|
106
106
|
- `Proc`
|
107
|
-
-
|
107
|
+
- Value must return a truthy value for this proc
|
108
108
|
- `true`
|
109
|
-
-
|
109
|
+
- Value must be truthy
|
110
110
|
- `false`
|
111
|
-
-
|
111
|
+
- Value must be falsy
|
112
112
|
- `nil`
|
113
|
-
-
|
113
|
+
- Value must be nil
|
114
114
|
|
115
115
|
- Special Behaviors
|
116
|
-
- `
|
116
|
+
- `TypedArray` : Ensures value is an array with the type (type signature)
|
117
117
|
- `Array::of(type)` (recommended)
|
118
|
-
- `Rtype::Behavior::TypedArray[type]`
|
118
|
+
- or `Rtype::Behavior::TypedArray[type]`
|
119
119
|
- Example: [TypedArray](#typed-array)
|
120
|
+
|
121
|
+
- `Num, Int, Flo` : Numeric check
|
122
|
+
- `Num/Int/Flo >/>=/</<=/== x`
|
123
|
+
- e.g. `Num >= 2` means value must be a `Numeric` and >= 2
|
124
|
+
- e.g. `Int >= 2` means value must be a `Integer` and >= 2
|
125
|
+
- e.g. `Flo >= 2` means value must be a `Float` and >= 2
|
126
|
+
|
127
|
+
- `And` : Ensures value is valid for all given types
|
128
|
+
- `Rtype::and(*types)`, `Rtype::Behavior::And[*types]`
|
129
|
+
- or `Array#comb`, `Object#and(*others)`
|
120
130
|
|
121
|
-
- `
|
122
|
-
- `Rtype::
|
123
|
-
- `
|
124
|
-
- `Object#and(*others)`
|
125
|
-
|
126
|
-
- `Rtype::xor(*types)` : Ensures a value is valid for only one of the types
|
127
|
-
- `Rtype::xor(*types)`, `Rtype::Behavior::Xor[*types]`, `include Rtype::Behavior; Xor[...]`
|
128
|
-
- `Object#xor(*others)`
|
131
|
+
- `Xor` : Ensures value is valid for only one of given types
|
132
|
+
- `Rtype::xor(*types)`, `Rtype::Behavior::Xor[*types]`
|
133
|
+
- or `Object#xor(*others)`
|
129
134
|
|
130
|
-
- `
|
131
|
-
- `Rtype::not(*types)`, `Rtype::Behavior::Not[*types]
|
132
|
-
- `Object#not`
|
135
|
+
- `Not` : Ensures value is not valid for all given types
|
136
|
+
- `Rtype::not(*types)`, `Rtype::Behavior::Not[*types]`
|
137
|
+
- or `Object#not`
|
133
138
|
|
134
|
-
- `
|
135
|
-
- `Rtype::nilable(type)`, `Rtype::Behavior::Nilable[type]
|
136
|
-
- `Object#nilable`
|
137
|
-
- `Object#or_nil`
|
139
|
+
- `Nilable` : Value can be nil
|
140
|
+
- `Rtype::nilable(type)`, `Rtype::Behavior::Nilable[type]`
|
141
|
+
- or `Object#nilable`, `Object#or_nil`
|
138
142
|
|
139
143
|
- You can create custom behavior by extending `Rtype::Behavior::Base`
|
140
144
|
|
@@ -234,7 +238,7 @@ def func(hash)
|
|
234
238
|
puts hash[:msg]
|
235
239
|
end
|
236
240
|
|
237
|
-
# last hash is keyword arguments
|
241
|
+
# last hash is not hash argument but keyword arguments
|
238
242
|
func({}, {})
|
239
243
|
# (Rtype::ArgumentTypeError) for 1st argument:
|
240
244
|
# Expected {} to be a hash with 1 elements:
|
@@ -315,83 +319,18 @@ sum([1, 2, 3]) # => 6
|
|
315
319
|
sum([1.0, 2, 3]) # => 6.0
|
316
320
|
```
|
317
321
|
|
318
|
-
####
|
319
|
-
```ruby
|
320
|
-
### TEST 1 ###
|
321
|
-
require 'rtype'
|
322
|
-
|
323
|
-
class Example
|
324
|
-
rtype [[String, :func].comb] => Any
|
325
|
-
# also works:
|
326
|
-
# rtype [Rtype::and(String, :func)] => Any
|
327
|
-
def and_test(arg)
|
328
|
-
end
|
329
|
-
end
|
330
|
-
|
331
|
-
Example.new.and_test("A string")
|
332
|
-
# (Rtype::ArgumentTypeError) for 1st argument:
|
333
|
-
# Expected "A string" to be a String
|
334
|
-
# AND Expected "A string" to respond to :func
|
335
|
-
```
|
336
|
-
```ruby
|
337
|
-
### TEST 2 ###
|
338
|
-
# ... require rtype and define Example the same as above ...
|
339
|
-
|
340
|
-
class String
|
341
|
-
def func; end
|
342
|
-
end
|
343
|
-
|
344
|
-
Example.new.and_test("A string") # Works!
|
345
|
-
```
|
346
|
-
|
347
|
-
#### Combined duck type
|
348
|
-
Application of duck typing and combined type
|
349
|
-
|
350
|
-
```ruby
|
351
|
-
require 'rtype'
|
352
|
-
|
353
|
-
module Game
|
354
|
-
ENEMY = [
|
355
|
-
:name,
|
356
|
-
:level
|
357
|
-
].comb
|
358
|
-
|
359
|
-
class Player < Entity
|
360
|
-
include Rtype::Behavior
|
361
|
-
|
362
|
-
rtype [ENEMY] => Any
|
363
|
-
def attacks(enemy)
|
364
|
-
"Player attacks '#{enemy.name}' (level #{enemy.level})!"
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
class Slime < Entity
|
369
|
-
def name
|
370
|
-
"Powerful Slime"
|
371
|
-
end
|
372
|
-
|
373
|
-
def level
|
374
|
-
123
|
375
|
-
end
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
Game::Player.new.attacks Game::Slime.new
|
380
|
-
# Player attacks 'Powerful Slime' (level 123)!
|
381
|
-
```
|
382
|
-
|
383
|
-
#### Position of `rtype` && (specifying method name || annotation mode) && (symbol || string)
|
322
|
+
#### `rtype`
|
384
323
|
```ruby
|
385
324
|
require 'rtype'
|
386
325
|
|
387
326
|
class Example
|
388
|
-
# Recommended.
|
327
|
+
# Recommended. With annotation mode (no method name required)
|
389
328
|
rtype [Integer, String] => String
|
390
329
|
def hello_world(i, str)
|
391
330
|
puts "Hello? #{i} #{st
|
392
331
|
end
|
393
332
|
|
394
|
-
# Works (specifying method name)
|
333
|
+
# Works (with specifying method name)
|
395
334
|
rtype :hello_world, [Integer, String] => String
|
396
335
|
def hello_world(i, str)
|
397
336
|
puts "Hello? #{i} #{st
|
@@ -409,7 +348,7 @@ class Example
|
|
409
348
|
puts "Hello? #{i} #{str}"
|
410
349
|
end
|
411
350
|
|
412
|
-
# Doesn't work.
|
351
|
+
# Doesn't work. annotation mode works for following (next) method
|
413
352
|
def hello_world_four(i, str)
|
414
353
|
puts "Hello? #{i} #{str}"
|
415
354
|
end
|
@@ -417,8 +356,8 @@ class Example
|
|
417
356
|
end
|
418
357
|
```
|
419
358
|
|
420
|
-
####
|
421
|
-
In the outside of module, annotation mode
|
359
|
+
#### In the outside of module (root)
|
360
|
+
In the outside of module, annotation mode doesn't work. You must specify method name.
|
422
361
|
|
423
362
|
```ruby
|
424
363
|
rtype :say, [String] => Any
|
@@ -429,11 +368,11 @@ end
|
|
429
368
|
Test.new.say "Hello" # Hello
|
430
369
|
|
431
370
|
rtype [String] => Any
|
432
|
-
# (ArgumentError) Annotation mode not working
|
371
|
+
# (ArgumentError) Annotation mode not working in the outside of module
|
433
372
|
```
|
434
373
|
|
435
374
|
#### Class method
|
436
|
-
|
375
|
+
Annotation mode works for both instance method and class method
|
437
376
|
|
438
377
|
```ruby
|
439
378
|
require 'rtype'
|
@@ -463,8 +402,8 @@ end
|
|
463
402
|
Example::say_ya(3) #say ya ya ya
|
464
403
|
```
|
465
404
|
|
466
|
-
####
|
467
|
-
This is just
|
405
|
+
#### Type information
|
406
|
+
This is just 'information'
|
468
407
|
|
469
408
|
Any change of this doesn't affect type checking
|
470
409
|
|
data/Rakefile
CHANGED
@@ -3,10 +3,10 @@ require "rspec/core/rake_task"
|
|
3
3
|
# Default pattern is 'spec/**{,/*/**}/*_spec.rb'
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
|
-
task :default => :spec
|
6
|
+
task :default => [:spec]
|
7
7
|
|
8
8
|
# Benchmark
|
9
9
|
desc "Compare with pure ruby and other gems"
|
10
10
|
task :benchmark do
|
11
11
|
ruby "benchmark/benchmark.rb"
|
12
|
-
end
|
12
|
+
end
|
@@ -1,28 +1,160 @@
|
|
1
1
|
class Object
|
2
|
+
# @return [Rtype::Behavior::And]
|
2
3
|
def and(*others)
|
3
4
|
::Rtype::and(self, *others)
|
4
5
|
end
|
5
6
|
|
7
|
+
# @return [Rtype::Behavior::Nilable]
|
6
8
|
def nilable
|
7
9
|
::Rtype::nilable(self)
|
8
10
|
end
|
9
11
|
alias_method :or_nil, :nilable
|
10
12
|
|
13
|
+
# @return [Rtype::Behavior::Not]
|
11
14
|
def not
|
12
15
|
::Rtype::not(self)
|
13
16
|
end
|
14
17
|
|
18
|
+
# @return [Rtype::Behavior::Xor]
|
15
19
|
def xor(*others)
|
16
20
|
::Rtype::xor(self, *others)
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
24
|
class Array
|
25
|
+
# @return [Rtype::Behavior::TypedArray]
|
21
26
|
def self.of(type_sig)
|
22
27
|
::Rtype::Behavior::TypedArray.new(type_sig)
|
23
28
|
end
|
24
29
|
|
30
|
+
# @return [Rtype::Behavior::And]
|
25
31
|
def comb
|
26
32
|
::Rtype::Behavior::And[*self]
|
27
33
|
end
|
28
34
|
end
|
35
|
+
|
36
|
+
class Num
|
37
|
+
# @param [Numeric] x
|
38
|
+
# @return [Proc]
|
39
|
+
# @example Value must be a Numeric and > 2
|
40
|
+
# rtype [Num > 2] => Any
|
41
|
+
def self.>(x)
|
42
|
+
lambda { |obj| obj.is_a?(Numeric) && obj > x }
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param [Numeric] x
|
46
|
+
# @return [Proc]
|
47
|
+
# @example Value must be a Numeric and > 2
|
48
|
+
# rtype [Num > 2] => Any
|
49
|
+
def self.>=(x)
|
50
|
+
lambda { |obj| obj.is_a?(Numeric) && obj >= x }
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param [Numeric] x
|
54
|
+
# @return [Proc]
|
55
|
+
# @example Value must be a Numeric and > 2
|
56
|
+
# rtype [Num > 2] => Any
|
57
|
+
def self.<(x)
|
58
|
+
lambda { |obj| obj.is_a?(Numeric) && obj < x }
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param [Numeric] x
|
62
|
+
# @return [Proc]
|
63
|
+
# @example Value must be a Numeric and > 2
|
64
|
+
# rtype [Num > 2] => Any
|
65
|
+
def self.<=(x)
|
66
|
+
lambda { |obj| obj.is_a?(Numeric) && obj <= x }
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param [Numeric] x
|
70
|
+
# @return [Proc]
|
71
|
+
# @example Value must be a Numeric and > 2
|
72
|
+
# rtype [Num > 2] => Any
|
73
|
+
def self.==(x)
|
74
|
+
lambda { |obj| obj.is_a?(Numeric) && obj == x }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Int
|
79
|
+
# @param [Numeric] x
|
80
|
+
# @return [Proc]
|
81
|
+
# @example Value must be a Integer and > 2
|
82
|
+
# rtype [Int > 2] => Any
|
83
|
+
def self.>(x)
|
84
|
+
lambda { |obj| obj.is_a?(Integer) && obj > x }
|
85
|
+
end
|
86
|
+
|
87
|
+
# @param [Numeric] x
|
88
|
+
# @return [Proc]
|
89
|
+
# @example Value must be a Integer and > 2
|
90
|
+
# rtype [Int > 2] => Any
|
91
|
+
def self.>=(x)
|
92
|
+
lambda { |obj| obj.is_a?(Integer) && obj >= x }
|
93
|
+
end
|
94
|
+
|
95
|
+
# @param [Numeric] x
|
96
|
+
# @return [Proc]
|
97
|
+
# @example Value must be a Integer and > 2
|
98
|
+
# rtype [Int > 2] => Any
|
99
|
+
def self.<(x)
|
100
|
+
lambda { |obj| obj.is_a?(Integer) && obj < x }
|
101
|
+
end
|
102
|
+
|
103
|
+
# @param [Numeric] x
|
104
|
+
# @return [Proc]
|
105
|
+
# @example Value must be a Integer and > 2
|
106
|
+
# rtype [Int > 2] => Any
|
107
|
+
def self.<=(x)
|
108
|
+
lambda { |obj| obj.is_a?(Integer) && obj <= x }
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param [Numeric] x
|
112
|
+
# @return [Proc]
|
113
|
+
# @example Value must be a Integer and > 2
|
114
|
+
# rtype [Int > 2] => Any
|
115
|
+
def self.==(x)
|
116
|
+
lambda { |obj| obj.is_a?(Integer) && obj == x }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class Flo
|
121
|
+
# @param [Numeric] x
|
122
|
+
# @return [Proc]
|
123
|
+
# @example Value must be a Float and > 2
|
124
|
+
# rtype [Flo > 2] => Any
|
125
|
+
def self.>(x)
|
126
|
+
lambda { |obj| obj.is_a?(Float) && obj > x }
|
127
|
+
end
|
128
|
+
|
129
|
+
# @param [Numeric] x
|
130
|
+
# @return [Proc]
|
131
|
+
# @example Value must be a Float and > 2
|
132
|
+
# rtype [Flo > 2] => Any
|
133
|
+
def self.>=(x)
|
134
|
+
lambda { |obj| obj.is_a?(Float) && obj >= x }
|
135
|
+
end
|
136
|
+
|
137
|
+
# @param [Numeric] x
|
138
|
+
# @return [Proc]
|
139
|
+
# @example Value must be a Float and > 2
|
140
|
+
# rtype [Flo > 2] => Any
|
141
|
+
def self.<(x)
|
142
|
+
lambda { |obj| obj.is_a?(Float) && obj < x }
|
143
|
+
end
|
144
|
+
|
145
|
+
# @param [Numeric] x
|
146
|
+
# @return [Proc]
|
147
|
+
# @example Value must be a Float and > 2
|
148
|
+
# rtype [Flo > 2] => Any
|
149
|
+
def self.<=(x)
|
150
|
+
lambda { |obj| obj.is_a?(Float) && obj <= x }
|
151
|
+
end
|
152
|
+
|
153
|
+
# @param [Numeric] x
|
154
|
+
# @return [Proc]
|
155
|
+
# @example Value must be a Float and > 2
|
156
|
+
# rtype [Flo > 2] => Any
|
157
|
+
def self.==(x)
|
158
|
+
lambda { |obj| obj.is_a?(Float) && obj == x }
|
159
|
+
end
|
160
|
+
end
|
data/lib/rtype/version.rb
CHANGED
data/lib/rtype.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
|
-
if defined?(RUBY_ENGINE)
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
if defined?(RUBY_ENGINE)
|
2
|
+
case RUBY_ENGINE
|
3
|
+
when "jruby"
|
4
|
+
begin
|
5
|
+
require 'java'
|
6
|
+
require 'rtype/rtype_java'
|
7
|
+
# puts "Rtype with Java extension"
|
8
|
+
rescue LoadError
|
9
|
+
# puts "Rtype without native extension"
|
10
|
+
end
|
11
|
+
when "ruby"
|
12
|
+
begin
|
13
|
+
require "rtype/rtype_native"
|
14
|
+
# puts "Rtype with C native extension"
|
15
|
+
rescue LoadError
|
16
|
+
# puts "Rtype without native extension"
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
@@ -322,7 +325,7 @@ module Rtype
|
|
322
325
|
# Validates arguments
|
323
326
|
#
|
324
327
|
# @param [Array] expected_args A type signature for non-keyword arguments
|
325
|
-
# @param args
|
328
|
+
# @param [Array] args
|
326
329
|
# @return [void]
|
327
330
|
#
|
328
331
|
# @raise [TypeSignatureError] If expected_args is invalid
|
@@ -346,9 +349,9 @@ module Rtype
|
|
346
349
|
# Validates arguments and keyword arguments
|
347
350
|
#
|
348
351
|
# @param [Array] expected_args A type signature for non-keyword arguments
|
349
|
-
# @param args Arguments
|
352
|
+
# @param [Array] args Arguments
|
350
353
|
# @param [Hash] expected_kwargs A type signature for keyword arguments
|
351
|
-
# @param kwargs Keword arguments
|
354
|
+
# @param [Hash] kwargs Keword arguments
|
352
355
|
# @return [void]
|
353
356
|
#
|
354
357
|
# @raise [TypeSignatureError] If expected_args or expected_kwargs are invalid
|
data/spec/rtype_spec.rb
CHANGED
@@ -474,6 +474,68 @@ describe Rtype do
|
|
474
474
|
instance.return_nil([])
|
475
475
|
end
|
476
476
|
end
|
477
|
+
|
478
|
+
describe 'Numeric check' do
|
479
|
+
it 'Num (Numeric)' do
|
480
|
+
klass.send :rtype, :return_nil, [Num >= 0] => Any
|
481
|
+
expect { instance.return_nil("hello") }.to raise_error Rtype::ArgumentTypeError
|
482
|
+
expect { instance.return_nil(-1) }.to raise_error Rtype::ArgumentTypeError
|
483
|
+
instance.return_nil(2)
|
484
|
+
instance.return_nil(2.0)
|
485
|
+
|
486
|
+
klass.send :rtype, :return_nil, [Num > 0] => Any
|
487
|
+
expect { instance.return_nil("non numeric") }.to raise_error Rtype::ArgumentTypeError
|
488
|
+
expect { instance.return_nil(0) }.to raise_error Rtype::ArgumentTypeError
|
489
|
+
|
490
|
+
klass.send :rtype, :return_nil, [Num < 0] => Any
|
491
|
+
expect { instance.return_nil("non numeric") }.to raise_error Rtype::ArgumentTypeError
|
492
|
+
expect { instance.return_nil(0) }.to raise_error Rtype::ArgumentTypeError
|
493
|
+
|
494
|
+
klass.send :rtype, :return_nil, [Num <= 0] => Any
|
495
|
+
expect { instance.return_nil("non numeric") }.to raise_error Rtype::ArgumentTypeError
|
496
|
+
expect { instance.return_nil(1) }.to raise_error Rtype::ArgumentTypeError
|
497
|
+
end
|
498
|
+
|
499
|
+
it 'Int (Integer)' do
|
500
|
+
klass.send :rtype, :return_nil, [Int >= 0] => Any
|
501
|
+
expect { instance.return_nil("hello") }.to raise_error Rtype::ArgumentTypeError
|
502
|
+
expect { instance.return_nil(1.0) }.to raise_error Rtype::ArgumentTypeError
|
503
|
+
expect { instance.return_nil(-1) }.to raise_error Rtype::ArgumentTypeError
|
504
|
+
instance.return_nil(2)
|
505
|
+
|
506
|
+
klass.send :rtype, :return_nil, [Int > 0] => Any
|
507
|
+
expect { instance.return_nil(1.0) }.to raise_error Rtype::ArgumentTypeError
|
508
|
+
expect { instance.return_nil(0) }.to raise_error Rtype::ArgumentTypeError
|
509
|
+
|
510
|
+
klass.send :rtype, :return_nil, [Int < 0] => Any
|
511
|
+
expect { instance.return_nil(-1.0) }.to raise_error Rtype::ArgumentTypeError
|
512
|
+
expect { instance.return_nil(0) }.to raise_error Rtype::ArgumentTypeError
|
513
|
+
|
514
|
+
klass.send :rtype, :return_nil, [Int <= 0] => Any
|
515
|
+
expect { instance.return_nil(0.0) }.to raise_error Rtype::ArgumentTypeError
|
516
|
+
expect { instance.return_nil(1) }.to raise_error Rtype::ArgumentTypeError
|
517
|
+
end
|
518
|
+
|
519
|
+
it 'Flo (Float)' do
|
520
|
+
klass.send :rtype, :return_nil, [Flo >= 0] => Any
|
521
|
+
expect { instance.return_nil("hello") }.to raise_error Rtype::ArgumentTypeError
|
522
|
+
expect { instance.return_nil(1) }.to raise_error Rtype::ArgumentTypeError
|
523
|
+
expect { instance.return_nil(-1.0) }.to raise_error Rtype::ArgumentTypeError
|
524
|
+
instance.return_nil(2.0)
|
525
|
+
|
526
|
+
klass.send :rtype, :return_nil, [Flo > 0] => Any
|
527
|
+
expect { instance.return_nil(1) }.to raise_error Rtype::ArgumentTypeError
|
528
|
+
expect { instance.return_nil(0.0) }.to raise_error Rtype::ArgumentTypeError
|
529
|
+
|
530
|
+
klass.send :rtype, :return_nil, [Flo < 0] => Any
|
531
|
+
expect { instance.return_nil(-1) }.to raise_error Rtype::ArgumentTypeError
|
532
|
+
expect { instance.return_nil(0.0) }.to raise_error Rtype::ArgumentTypeError
|
533
|
+
|
534
|
+
klass.send :rtype, :return_nil, [Flo <= 0] => Any
|
535
|
+
expect { instance.return_nil(0) }.to raise_error Rtype::ArgumentTypeError
|
536
|
+
expect { instance.return_nil(1.0) }.to raise_error Rtype::ArgumentTypeError
|
537
|
+
end
|
538
|
+
end
|
477
539
|
end
|
478
540
|
end
|
479
541
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtype
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sputnik Gugja
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '11.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '11.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|