rtype-java 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c76537dff4a7ccee1fa77da9c10e7097919dfeb
4
- data.tar.gz: 6f67d948e8827f5f656affbeb09a8e8bdec40777
3
+ metadata.gz: c8580ec5d359d6dcd395a437bc94ed40b25b486c
4
+ data.tar.gz: 5289c039445424a7e0281df85005fca8cebba108
5
5
  SHA512:
6
- metadata.gz: 9b5801ef42df2010d681e96bc8409cbf1eb70999ce5b888bba6921138c6b549b4d8458fdfd4ee6b5d98783c84cfa424471875090b43b3f60235c77702afdfbf1
7
- data.tar.gz: e1ebae61666ebfa0305c5992772e3fe8bcb0db11c96fb25b5eda491bca8d1d84c4295a6782f07230f6a5bf86e18dffd357ee72a47397b8267b144a5f2156dcd5
6
+ metadata.gz: ecf925fec3898c4ff928e570877ec5c5ad5ba54c87ec14c28711a7e6eaacfdd5384d0d4444f1a2f5602a2cd52c3476955f42e4590552d527f21ac38a20675618
7
+ data.tar.gz: e1a0e23fcfe6b918103cd2df0ebea7847aeb370c2b395dd35f153e06928700c4f2b9360abad766a8839319a9128dd8475b0953fb4c8ac395bf080a1aacd960c6
data/README.md CHANGED
@@ -37,9 +37,8 @@ Test::invert(state: 0)
37
37
  - If Java extension is used, otherwise it is not required
38
38
 
39
39
  ## Features
40
- - Provide type checking for arguments and return
41
- - Support type checking for [keyword argument](#keyword-argument)
42
- - [Type checking for array elements](#array)
40
+ - Provides type checking for arguments and return
41
+ - Supports type checking for [keyword argument](#keyword-argument)
43
42
  - [Type checking for hash elements](#hash)
44
43
  - [Duck typing](#duck-typing)
45
44
  - Custom type behavior
@@ -81,28 +80,23 @@ then, Rtype use it. (Do not `require 'rtype-java'`)
81
80
 
82
81
  ### Supported Type Behaviors
83
82
  - `Module`
84
- - Value must be an instance of this module/class or one of its superclasses
83
+ - Value must be an instance of the module/class or one of its superclasses
85
84
  - `Any` : An alias for `BasicObject` (means Any Object)
86
85
  - `Boolean` : `true` or `false`
87
86
  - `Symbol`
88
- - Value must have(respond to) a method with this name
87
+ - Value must have(respond to) a method with the name
89
88
  - `Regexp`
90
- - Value must match this regexp pattern
89
+ - Value must match the regexp pattern
91
90
  - `Range`
92
- - Value must be included in this range
93
- - `Array` (tuple)
94
- - Value must be an array
95
- - Each of value's elements must be valid
96
- - Value's length must be equal to the array's length
97
- - Of course, nested array works
98
- - Example: [Array](#array)
99
- - This can be used as a tuple
91
+ - Value must be included in the range
92
+ - `Array`
93
+ - Value can be any type in the array
100
94
  - `Hash`
101
95
  - Value must be an hash
102
96
  - Each of value’s elements must be valid
103
97
  - Value's key list must be equal to the hash's key list
104
98
  - **String** key is **different** from **symbol** key
105
- - vs Keyword arguments
99
+ - vs Keyword arguments (e.g.)
106
100
  - `[{}]` is **not** hash type argument. it is keyword argument because its position is last
107
101
  - `[{}, {}]` is empty hash type argument (first) and one empty keyword argument (second)
108
102
  - `[{}, {}, {}]` is two empty hash type argument (first, second) and empty keyword argument (last)
@@ -110,44 +104,31 @@ then, Rtype use it. (Do not `require 'rtype-java'`)
110
104
  - Of course, nested hash works
111
105
  - Example: [Hash](#hash)
112
106
  - `Proc`
113
- - Value must return a truthy value for this proc
107
+ - Value must return a truthy value for the proc
114
108
  - `true`
115
109
  - Value must be **truthy**
116
110
  - `false`
117
111
  - Value must be **falsy**
118
112
  - `nil`
119
- - Only available for **return type**. void return type in other languages
113
+ - Value must be nil
120
114
  - Special Behaviors
121
115
  - `Rtype::and(*types)` : Ensure value is valid for all the types
122
- - `Rtype::and(*types)`
123
- - `Rtype::Behavior::And[*types]`
124
- - `include Rtype::Behavior; And[...]`
125
- - `obj.and(*others)` (core extension)
126
-
127
- - `Rtype::or(*types)` : Ensure value is valid for at least one of the types
128
- - `Rtype::or(*types)`
129
- - `Rtype::Behavior::Or[*types]`
130
- - `include Rtype::Behavior; Or[...]`
131
- - `obj.or(*others)` (core extension)
132
-
116
+ - `Rtype::and(*types)`, `Rtype::Behavior::And[*types]`, `include Rtype::Behavior; And[...]`
117
+ - `Array#comb`
118
+ - `Object#and(*others)`
119
+
133
120
  - `Rtype::xor(*types)` : Ensure value is valid for only one of the types
134
- - `Rtype::xor(*types)`
135
- - `Rtype::Behavior::Xor[*types]`
136
- - `include Rtype::Behavior; Xor[...]`
137
- - `obj.xor(*others)` (core extension)
121
+ - `Rtype::xor(*types)`, `Rtype::Behavior::Xor[*types]`, `include Rtype::Behavior; Xor[...]`
122
+ - `Object#xor(*others)`
138
123
 
139
124
  - `Rtype::not(*types)` : Ensure value is not valid for all the types
140
- - `Rtype::not(*types)`
141
- - `Rtype::Behavior::Not[*types]`
142
- - `include Rtype::Behavior; Not[...]`
143
- - `obj.not` (core extension)
125
+ - `Rtype::not(*types)`, `Rtype::Behavior::Not[*types]`, `include Rtype::Behavior; Not[...]`
126
+ - `Object#not`
144
127
 
145
128
  - `Rtype::nilable(type)` : Ensure value can be nil
146
- - `Rtype::nilable(type)`
147
- - `Rtype::Behavior::Nilable[type]`
148
- - `include Rtype::Behavior; Nilable[...]`
149
- - `obj.nilable` (core extension)
150
- - `obj.or_nil` (core extension)
129
+ - `Rtype::nilable(type)`, `Rtype::Behavior::Nilable[type]`, `include Rtype::Behavior; Nilable[...]`
130
+ - `Object#nilable`
131
+ - `Object#or_nil`
151
132
 
152
133
  - You can create custom behavior by extending `Rtype::Behavior::Base`
153
134
 
@@ -224,33 +205,19 @@ Duck.new.says("2") # duck: quack quack
224
205
  ```
225
206
 
226
207
  #### Array
227
- This can be used as a tuple.
228
-
229
208
  ```ruby
230
- rtype :func, [[Numeric, Numeric]] => Any
231
- def func(arr)
232
- puts "Your location is (#{arr[0]}, #{arr[1]}). I will look for you. I will find you"
209
+ rtype :ruby!, [[String, Integer]] => Any
210
+ def ruby!(arg)
211
+ puts "ruby!"
233
212
  end
234
213
 
235
- func [1, "str"]
236
- # (Rtype::ArgumentTypeError) for 1st argument:
237
- # Expected [1, "str"] to be an array with 2 elements:
238
- # - [0] index : Expected 1 to be a Numeric
239
- # - [1] index : Expected "str" to be a Numeric
240
-
241
- func [1, 2, 3]
242
- # (Rtype::ArgumentTypeError) for 1st argument:
243
- # Expected [1, 2, 3] to be an array with 2 elements:
244
- # - [0] index : Expected 1 to be a Numeric
245
- # - [1] index : Expected 2 to be a Numeric
214
+ func("str") # ruby!
215
+ func(123) # ruby!
246
216
 
247
- func [1]
217
+ func(nil)
248
218
  # (Rtype::ArgumentTypeError) for 1st argument:
249
- # Expected [1] to be an array with 2 elements:
250
- # - [0] index : Expected 1 to be a Numeric
251
- # - [1] index : Expected nil to be a Numeric
252
-
253
- func [1, 2] # Your location is (1, 2). I will look for you. I will find you
219
+ # Expected nil to be a String
220
+ # OR Expected nil to be a Integer
254
221
  ```
255
222
 
256
223
  #### Hash
@@ -316,7 +283,7 @@ Example.new.value
316
283
  require 'rtype'
317
284
 
318
285
  class Example
319
- rtype [String.and(:func)] => Any
286
+ rtype [[String, :func].comb] => Any
320
287
  # also works:
321
288
  # rtype [Rtype::and(String, :func)] => Any
322
289
  def and_test(arg)
@@ -349,12 +316,12 @@ module Game
349
316
  ENEMY = [
350
317
  :name,
351
318
  :level
352
- ]
319
+ ].comb
353
320
 
354
321
  class Player < Entity
355
322
  include Rtype::Behavior
356
323
 
357
- rtype [And[*ENEMY]] => Any
324
+ rtype [ENEMY] => Any
358
325
  def attacks(enemy)
359
326
  "Player attacks '#{enemy.name}' (level #{enemy.level})!"
360
327
  end
@@ -565,4 +532,4 @@ Sputnik Gugja (sputnikgugja@gmail.com)
565
532
  ## License
566
533
  MIT license (@ Sputnik Gugja)
567
534
 
568
- See `LICENSE` file.
535
+ See `LICENSE` file.
Binary file
data/spec/rtype_spec.rb CHANGED
@@ -237,31 +237,30 @@ describe Rtype do
237
237
 
238
238
  describe 'Array' do
239
239
  it "is right" do
240
- klass.send :rtype, :return_arg, [[:to_i, :to_i]] => Any
241
- instance.return_arg([123, 456])
240
+ klass.send :rtype, :return_arg, [[:to_i]] => Any
241
+ instance.return_arg(123)
242
242
 
243
- klass.send :rtype, :two_args, [[:to_i], [:to_i]] => Any
244
- instance.two_args([123], [456])
243
+ klass.send :rtype, :return_arg, [[String, Integer]] => Any
244
+ instance.return_arg("str")
245
+ instance.return_arg(123)
246
+
247
+ klass.send :rtype, :return_arg, [] => [String, Integer]
248
+ instance.return_arg("str")
249
+ instance.return_arg(123)
245
250
  end
246
251
  it "is wrong args" do
247
- klass.send :rtype, :return_arg, [[:to_i, :to_i]] => Any
248
- expect {
249
- instance.return_arg([123, [true]])
250
- }.to raise_error Rtype::ArgumentTypeError
252
+ klass.send :rtype, :return_arg, [[String, Integer]] => Any
251
253
  expect {
252
- instance.return_arg([123, true])
254
+ instance.return_arg(nil)
253
255
  }.to raise_error Rtype::ArgumentTypeError
254
256
 
255
- klass.send :rtype, :two_args, [[:to_i], [:to_i]] => Any
257
+ klass.send :rtype, :return_arg, [[String]] => Any
256
258
  expect {
257
- instance.two_args([123, 123], [123])
258
- }.to raise_error Rtype::ArgumentTypeError
259
- expect {
260
- instance.two_args([123], 123)
259
+ instance.return_arg(123)
261
260
  }.to raise_error Rtype::ArgumentTypeError
262
261
  end
263
262
  it "is wrong result" do
264
- klass.send :rtype, :return_arg, [Any] => [:to_i, :to_i]
263
+ klass.send :rtype, :return_arg, [Any] => [String, Integer]
265
264
  expect {instance.return_arg(true)}.to raise_error Rtype::ReturnTypeError
266
265
  end
267
266
  end
@@ -335,17 +334,19 @@ describe Rtype do
335
334
  end
336
335
 
337
336
  describe 'nil' do
338
- it "is only for return" do
337
+ it "for return" do
339
338
  klass.send :rtype, :return_nil, [] => nil
340
339
  instance.return_nil(123)
341
340
 
342
341
  klass.send :rtype, :return_arg, [] => nil
343
342
  expect {instance.return_arg(123)}.to raise_error Rtype::ReturnTypeError
344
343
  end
345
- it "could not be used for args" do
344
+ it "for args" do
345
+ klass.send :rtype, :return_arg, [nil] => Any
346
+ instance.return_arg(nil)
346
347
  expect {
347
- klass.send :rtype, :return_arg, [nil] => Any
348
- }.to raise_error Rtype::TypeSignatureError
348
+ instance.return_arg(123)
349
+ }.to raise_error Rtype::ArgumentTypeError
349
350
  end
350
351
  end
351
352
 
@@ -370,29 +371,6 @@ describe Rtype do
370
371
  end
371
372
  end
372
373
 
373
- describe 'Rtype::Behavior::Or' do
374
- it 'module singleton method' do
375
- klass.send :rtype, :return_nil, [Rtype::or(Integer, String)] => nil
376
- instance.return_nil(123)
377
- instance.return_nil("abc")
378
- expect {instance.return_nil(nil)}.to raise_error Rtype::ArgumentTypeError
379
- end
380
-
381
- it 'class singleton [] method' do
382
- klass.send :rtype, :return_nil, [ Rtype::Behavior::Or[Integer, String] ] => nil
383
- instance.return_nil(123)
384
- instance.return_nil("abc")
385
- expect {instance.return_nil(nil)}.to raise_error Rtype::ArgumentTypeError
386
- end
387
-
388
- it 'core extension method' do
389
- klass.send :rtype, :return_nil, [ Integer.or(String) ] => nil
390
- instance.return_nil(123)
391
- instance.return_nil("abc")
392
- expect {instance.return_nil(nil)}.to raise_error Rtype::ArgumentTypeError
393
- end
394
- end
395
-
396
374
  describe 'Rtype::Behavior::Nilable' do
397
375
  it 'module singleton method' do
398
376
  klass.send :rtype, :return_nil, [Rtype::nilable(Integer)] => nil
@@ -480,13 +458,6 @@ describe Rtype do
480
458
  expect {instance.sum(1, 2.0)}.to raise_error Rtype::ArgumentTypeError
481
459
  end
482
460
 
483
- it 'two array' do
484
- klass.send :rtype, :sum, [[Integer], [Integer]] => Any
485
- instance.sum([1], [2])
486
- expect {instance.sum([1], 2)}.to raise_error Rtype::ArgumentTypeError
487
- expect {instance.sum([1], ["str"])}.to raise_error Rtype::ArgumentTypeError
488
- end
489
-
490
461
  it 'two hash' do
491
462
  klass.send :rtype, :two_args, [{k: Integer}, {k: Integer}, {}] => Any
492
463
  instance.two_args({k: 123}, {k: 456}, {})
@@ -564,9 +535,9 @@ describe Rtype do
564
535
  instance.return_arg("str")
565
536
  end
566
537
 
567
- it 'Array (tuple)' do
538
+ it 'Array' do
568
539
  klass.send :rtype, :return_arg, [] => [Integer, Float]
569
- expect {instance.return_arg([1, 2])}.to raise_error Rtype::ReturnTypeError
540
+ expect {instance.return_arg("str")}.to raise_error Rtype::ReturnTypeError
570
541
  end
571
542
  end
572
543
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtype-java
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
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-04-25 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rtype
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.1
19
+ version: 0.6.0
20
20
  type: :runtime
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: 0.5.1
26
+ version: 0.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement