haskell 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4091853a74cb3916531770c015d74a1846249825
4
- data.tar.gz: abacdf2cda587ffc59f0103163ce1bda1e235f79
3
+ metadata.gz: d3c9ffa1d1b36cb7926952b21760fbf551702a43
4
+ data.tar.gz: 74e7d0eefc40f2d5564b3adc4cb484f4ce9e6135
5
5
  SHA512:
6
- metadata.gz: 8688fce196d3cff82e187f6cc5979386016855cc0658aed2617861e6be3e45ea0a1cfcf1f9f32c2cd0bd6957be817efd306817b363e4826c885f2d62c8b4125e
7
- data.tar.gz: 86ee71cc6c0ccdf30763bdb58a466e0384b977468ab44532c496dbdcb8a5b783587b8d5264f3520b835962c99d7d39b85e587c5f51ded646e3a62181825e789c
6
+ metadata.gz: 013a5b1881c581a93a8075974edcf3aa3f12d175cfd4957b87948b41599181ed484579053b9b7683a4b699c30e97d94256ef333d49d8de099b339162bb388355
7
+ data.tar.gz: 16ddb4cb6b778cfad27173c79809063c9d6856d15628aac70cba9d1405a177872389f6f6551d1cb16c015d249934e12d4cebe0d5769ae2dab7007ceb16eb725d
data/README.md CHANGED
@@ -5,17 +5,19 @@ Matz has mentioned Ruby3.0 with static type at some confluences. But almost all
5
5
  But it's worth thinking more. This gem is kind of trial without so much side-effect.
6
6
 
7
7
  ```rb
8
- require 'haskell'
8
+ require 'rubype'
9
9
 
10
- # ex1: (Ruby 2.1.0+)
10
+ # ex1
11
11
  class MyClass
12
- type Numeric, Numeric >= Numeric, def sum(x, y)
12
+ def sum(x, y)
13
13
  x + y
14
14
  end
15
+ typesig sum: [Numeric, Numeric => Numeric]
15
16
 
16
- type Numeric, Numeric >= Numeric, def wrong_sum(x, y)
17
+ def wrong_sum(x, y)
17
18
  'string'
18
19
  end
20
+ typesig wrong_sum: [Numeric, Numeric => Numeric]
19
21
  end
20
22
 
21
23
  MyClass.new.sum(1, 2)
@@ -28,27 +30,19 @@ MyClass.new.wrong_sum(1, 2)
28
30
  #=> TypeError: Expected wrong_sum to return Numeric but got "str" instead
29
31
 
30
32
 
31
- # ex2: (Ruby 2.1.0+)
33
+ # ex2
32
34
  class People
33
35
  type People >= Any, def marry(people)
34
36
  # Your Ruby code as usual
35
37
  end
36
38
  end
39
+ typesig marry: [People => Any]
37
40
 
38
41
  People.new.marry(People.new)
39
42
  #=> no error
40
43
 
41
44
  People.new.marry('non people')
42
45
  #=> ArgumentError: Wrong type of argument, type of "non people" should be People
43
-
44
-
45
- # ex3: (Ruby 1.8.0+)
46
- class MyClass
47
- def sum(x, y)
48
- x + y
49
- end
50
- type Numeric, Numeric >= Numeric, :sum
51
- end
52
46
  ```
53
47
 
54
48
  ## Feature
@@ -57,11 +51,12 @@ end
57
51
  ```ruby
58
52
  # It's totally OK!!
59
53
  class MyClass
60
- type Numeric, Numeric >= Numeric, def sum(x, y)
54
+ def sum(x, y)
61
55
  x + y
62
56
  end
57
+ typesig sum: [Numeric, Numeric => Numeric]
63
58
 
64
- def wrong_sum(x, y)
59
+ def sum_without_type(x, y)
65
60
  'string'
66
61
  end
67
62
  end
@@ -72,9 +67,10 @@ end
72
67
  ```ruby
73
68
 
74
69
  class MyClass
75
- type Any >= Numeric, def foo(any_obj)
70
+ def foo(any_obj)
76
71
  1
77
72
  end
73
+ typesig sum: [Any => Numeric]
78
74
  end
79
75
 
80
76
  # It's totally OK!!
@@ -85,24 +81,13 @@ MyClass.new.foo('str')
85
81
 
86
82
  ## Installation
87
83
 
88
- Add this line to your application's Gemfile:
89
-
90
- ```ruby
91
- gem 'haskell'
92
- ```
93
-
94
- And then execute:
95
-
96
- $ bundle
97
-
98
- Or install it yourself as:
99
-
100
- $ gem install haskell
84
+ gem install rubype or add gem 'rubype' to your Gemfile.
101
85
 
86
+ This gem requires Ruby 2.0.0+.
102
87
 
103
88
  ### Contributing
104
89
 
105
- Fork it ( https://github.com/[my-github-username]/haskell/fork )
90
+ Fork it ( https://github.com/[my-github-username]/rubype/fork )
106
91
 
107
92
  Create your feature branch (`git checkout -b my-new-feature`)
108
93
 
data/Rakefile CHANGED
@@ -5,10 +5,15 @@ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test"
6
6
  end
7
7
 
8
- task :default => :test
9
-
10
8
  require "rake/extensiontask"
11
9
 
12
- Rake::ExtensionTask.new("haskell") do |ext|
13
- ext.lib_dir = "lib/haskell"
10
+ Rake::ExtensionTask.new("rubype") do |ext|
11
+ ext.lib_dir = "lib/rubype"
12
+ end
13
+
14
+ task :compile_and_test do
15
+ Rake::Task['compile'].invoke
16
+ Rake::Task['test'].invoke
14
17
  end
18
+
19
+ task default: :compile_and_test
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'haskell'
3
+ require 'rubype'
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile("rubype/rubype")
@@ -0,0 +1,38 @@
1
+ #include "rubype.h"
2
+
3
+ VALUE rb_mRubype, rb_cAny, rb_mBoolean, rb_cTypePair;
4
+
5
+ #define STR2SYM(x) ID2SYM(rb_intern(x))
6
+
7
+ static VALUE
8
+ rb_mod_prepend(int argc, VALUE *argv, VALUE module)
9
+ {
10
+ int i;
11
+ ID id_prepend_features, id_prepended;
12
+
13
+ CONST_ID(id_prepend_features, "prepend_features");
14
+ CONST_ID(id_prepended, "prepended");
15
+ for (i = 0; i < argc; i++)
16
+ Check_Type(argv[i], T_MODULE);
17
+ while (argc--) {
18
+ rb_funcall(argv[argc], id_prepend_features, 1, module);
19
+ rb_funcall(argv[argc], id_prepended, 1, module);
20
+ }
21
+
22
+ return module;
23
+ }
24
+
25
+ void
26
+ Init_rubype(void)
27
+ {
28
+ // rb_mRubype = rb_define_module("Rubype");
29
+ // rb_cAny = rb_define_class("Any", rb_cObject);
30
+ // rb_mBoolean = rb_define_module("Boolean");
31
+ // rb_include_module(rb_cTrueClass, rb_mBoolean);
32
+ // rb_include_module(rb_cFalseClass, rb_mBoolean);
33
+ // rb_define_class(
34
+ // "TypePair",
35
+ // rb_funcall(rb_cStruct, rb_intern("new"), 2, STR2SYM("last_arg_type"), STR2SYM("rtn_type"))
36
+ // );
37
+ rb_define_method(rb_cModule, "prepend", rb_mod_prepend, -1);
38
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef RUBYPE_H
2
+ #define RUBYPE_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* RUBYPE_H */
@@ -0,0 +1,3 @@
1
+ module Rubype
2
+ VERSION = "0.2.0"
3
+ end
@@ -1,4 +1,4 @@
1
- require 'haskell/type_pair'
1
+ require "rubype/rubype"
2
2
 
3
3
  # Builtin Contracts
4
4
  class Any; end
@@ -8,25 +8,26 @@ FalseClass.send(:include, Boolean)
8
8
 
9
9
  class Module
10
10
  private
11
- def __haskell__
12
- prepend (@__haskell__ = Module.new) unless @__haskell__
13
- @__haskell__
11
+ def __rubype__
12
+ prepend (@__rubype__ = Module.new) unless @__rubype__
13
+ @__rubype__
14
14
  end
15
15
 
16
- def type(*arguments)
17
- *arg_types, type_pair, meth = arguments
16
+ def typesig(hash)
17
+ meth = hash.keys.first
18
+ *arg_types, type_pair = hash.values.first
18
19
 
19
- __haskell__.send(:define_method, meth) do |*args, &block|
20
- ::Haskell.assert_arg_type(meth, args, arg_types << type_pair.last_arg_type)
20
+ __rubype__.send(:define_method, meth) do |*args, &block|
21
+ ::Rubype.assert_arg_type(meth, args, arg_types << type_pair.keys.first)
21
22
  rtn = super(*args, &block)
22
- ::Haskell.assert_trn_type(meth, rtn, type_pair.rtn_type)
23
+ ::Rubype.assert_trn_type(meth, rtn, type_pair.values.first)
23
24
  rtn
24
25
  end
25
26
  self
26
27
  end
27
28
  end
28
29
 
29
- module Haskell
30
+ module Rubype
30
31
  class << self
31
32
  def assert_arg_type(meth, args, klasses)
32
33
  args.each_with_index do |arg, i|
@@ -1,17 +1,17 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'haskell/version'
4
+ require 'rubype/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "haskell"
8
- spec.version = Haskell::VERSION
8
+ spec.version = Rubype::VERSION
9
9
  spec.authors = ["gogotanaka"]
10
10
  spec.email = ["mail@tanakakazuki.com"]
11
- spec.extensions = ["ext/haskell/extconf.rb"]
11
+ spec.extensions = ["ext/rubype/extconf.rb"]
12
12
  spec.summary = %q{Ruby with type.}
13
13
  spec.description = %q{Ruby with type.}
14
- spec.homepage = "http://azabuhs.org/"
14
+ spec.homepage = "http://gogotanaka.me/"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,4 +1,4 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'haskell'
2
+ require 'rubype'
3
3
 
4
4
  require 'minitest/autorun'
@@ -0,0 +1,107 @@
1
+ require 'minitest_helper'
2
+ class TypePair
3
+ def to_s
4
+ "#{last_arg_type} => #{rtn_type}"
5
+ end
6
+ end
7
+ class TestRubype < MiniTest::Unit::TestCase
8
+ def setup
9
+ @string = 'str'
10
+ @numeric = 1
11
+ @symbol = :test
12
+ @array = [1, 2, 3]
13
+ @hash = { test: :hash }
14
+ end
15
+
16
+ def test_correct_type
17
+ assert_correct_type [Numeric => Numeric], [@numeric], @numeric
18
+ assert_correct_type [Numeric => Array ], [@numeric], @array
19
+ assert_correct_type [Numeric => String ], [@numeric], @string
20
+ assert_correct_type [Numeric => Hash ], [@numeric], @hash
21
+ assert_correct_type [Numeric => Symbol ], [@numeric], @symbol
22
+ assert_correct_type [Numeric => Boolean], [@numeric], true
23
+ assert_correct_type [Numeric => Boolean], [@numeric], false
24
+
25
+ assert_correct_type [Boolean, Numeric => Numeric], [true, @numeric], @numeric
26
+ assert_correct_type [Boolean, Array => Array ], [true, @array ], @array
27
+ assert_correct_type [Boolean, String => String ], [true, @string ], @string
28
+ assert_correct_type [Boolean, Hash => Hash ], [true, @hash ], @hash
29
+ assert_correct_type [Boolean, Symbol => Symbol ], [true, @symbol ], @symbol
30
+ end
31
+
32
+ def test_wrong_return_type
33
+ assert_wrong_rtn [Numeric => Numeric], [@numeric], @array
34
+ assert_wrong_rtn [Numeric => Numeric], [@numeric], @string
35
+ assert_wrong_rtn [Numeric => Numeric], [@numeric], @hash
36
+ assert_wrong_rtn [Numeric => Numeric], [@numeric], @symbol
37
+ assert_wrong_rtn [Numeric => Numeric], [@numeric], true
38
+
39
+ assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], @array
40
+ assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], @string
41
+ assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], @hash
42
+ assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], @symbol
43
+ assert_wrong_rtn [Numeric, Numeric => Numeric], [@numeric, @numeric], true
44
+ end
45
+
46
+ def test_wrong_args_type
47
+ assert_wrong_arg [Numeric => Numeric], [@array ], @numeric
48
+ assert_wrong_arg [Numeric => Numeric], [@string], @numeric
49
+ assert_wrong_arg [Numeric => Numeric], [@hash ], @numeric
50
+ assert_wrong_arg [Numeric => Numeric], [@symbol], @numeric
51
+ assert_wrong_arg [Numeric => Numeric], [true ], @numeric
52
+
53
+ assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, @array ], @numeric
54
+ assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, @string], @numeric
55
+ assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, @hash ], @numeric
56
+ assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, @symbol], @numeric
57
+ assert_wrong_arg [Numeric, Numeric => Numeric], [@numeric, true ], @numeric
58
+ end
59
+
60
+ def test_any
61
+ assert_correct_type [Any => Any], [@array ], @numeric
62
+ assert_correct_type [Any => Any], [@string], @numeric
63
+ assert_correct_type [Any => Any], [@hash ], @numeric
64
+ assert_correct_type [Any => Any], [@symbol], @numeric
65
+
66
+ assert_correct_type [Any, Any => Any], [@numeric, @array ], @numeric
67
+ assert_correct_type [Any, Any => Any], [@numeric, @string], @numeric
68
+ assert_correct_type [Any, Any => Any], [@numeric, @hash ], @numeric
69
+ assert_correct_type [Any, Any => Any], [@numeric, @symbol], @numeric
70
+ end
71
+
72
+ private
73
+ def assert_equal_to_s(str, val)
74
+ assert_equal str, val.to_s
75
+ end
76
+
77
+ def assert_correct_type(type_list, args, val)
78
+ assert_equal val, define_test_method(type_list, args, val).call(*args)
79
+ end
80
+
81
+ def assert_wrong_arg(type_list, args, val)
82
+ assert_raises(ArgumentError) { define_test_method(type_list, args, val).call(*args) }
83
+ end
84
+
85
+ def assert_wrong_rtn(type_list, args, val)
86
+ assert_raises(TypeError) { define_test_method(type_list, args, val).call(*args) }
87
+ end
88
+
89
+ def define_test_method(type_list, args, val)
90
+ klass = Class.new.class_eval <<-RUBY_CODE
91
+ def call(#{arg_literal(args.count)})
92
+ #{obj_literal(val)}
93
+ end
94
+ typesig call: #{obj_literal(type_list)}
95
+ RUBY_CODE
96
+
97
+ klass.new
98
+ end
99
+
100
+ def obj_literal(obj)
101
+ "ObjectSpace._id2ref(#{obj.__id__})"
102
+ end
103
+
104
+ def arg_literal(count)
105
+ ('a'..'z').to_a[0..count-1].join(',')
106
+ end
107
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haskell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-06 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,9 +70,9 @@ description: Ruby with type.
70
70
  email:
71
71
  - mail@tanakakazuki.com
72
72
  executables:
73
- - haskell
73
+ - rubype
74
74
  extensions:
75
- - ext/haskell/extconf.rb
75
+ - ext/rubype/extconf.rb
76
76
  extra_rdoc_files: []
77
77
  files:
78
78
  - ".gitignore"
@@ -81,17 +81,16 @@ files:
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
- - bin/haskell
85
- - ext/haskell/extconf.rb
86
- - ext/haskell/haskell.c
87
- - ext/haskell/haskell.h
88
- - haskell.gemspec
89
- - lib/haskell.rb
90
- - lib/haskell/type_pair.rb
91
- - lib/haskell/version.rb
84
+ - bin/rubype
85
+ - ext/rubype/extconf.rb
86
+ - ext/rubype/rubype.c
87
+ - ext/rubype/rubype.h
88
+ - lib/rubype.rb
89
+ - lib/rubype/version.rb
90
+ - rubype.gemspec
92
91
  - test/minitest_helper.rb
93
- - test/test_haskell.rb
94
- homepage: http://azabuhs.org/
92
+ - test/test_rubype.rb
93
+ homepage: http://gogotanaka.me/
95
94
  licenses:
96
95
  - MIT
97
96
  metadata: {}
@@ -117,4 +116,4 @@ specification_version: 4
117
116
  summary: Ruby with type.
118
117
  test_files:
119
118
  - test/minitest_helper.rb
120
- - test/test_haskell.rb
119
+ - test/test_rubype.rb
@@ -1,3 +0,0 @@
1
- require "mkmf"
2
-
3
- create_makefile("haskell/haskell")
@@ -1,9 +0,0 @@
1
- #include "haskell.h"
2
-
3
- VALUE rb_mHaskell;
4
-
5
- void
6
- Init_haskell(void)
7
- {
8
- rb_mHaskell = rb_define_module("Haskell");
9
- }
@@ -1,6 +0,0 @@
1
- #ifndef HASKELL_H
2
- #define HASKELL_H 1
3
-
4
- #include "ruby.h"
5
-
6
- #endif /* HASKELL_H */
@@ -1,7 +0,0 @@
1
- class TypePair < Struct.new(:last_arg_type, :rtn_type); end
2
-
3
- class Module
4
- def >=(r)
5
- TypePair.new(self, r)
6
- end
7
- end
@@ -1,3 +0,0 @@
1
- module Haskell
2
- VERSION = "0.1.0"
3
- end
data/test/test_haskell.rb DELETED
@@ -1,113 +0,0 @@
1
- require 'minitest_helper'
2
- class TypePair
3
- def to_s
4
- "#{last_arg_type} >= #{rtn_type}"
5
- end
6
- end
7
- class TestHaskell < MiniTest::Unit::TestCase
8
- def setup
9
- @string = 'str'
10
- @numeric = 1
11
- @symbol = :test
12
- @array = [1, 2, 3]
13
- @hash = { test: :hash }
14
- end
15
-
16
- def test_type_list
17
- assert_equal_to_s "Numeric >= Numeric", Numeric >= Numeric
18
- assert_equal_to_s "Numeric >= Array", Numeric >= Array
19
- assert_equal_to_s "Array >= String", Array >= String
20
- end
21
-
22
- def test_correct_type
23
- assert_correct_type [Numeric >= Numeric], [@numeric], @numeric
24
- assert_correct_type [Numeric >= Array ], [@numeric], @array
25
- assert_correct_type [Numeric >= String ], [@numeric], @string
26
- assert_correct_type [Numeric >= Hash ], [@numeric], @hash
27
- assert_correct_type [Numeric >= Symbol ], [@numeric], @symbol
28
- assert_correct_type [Numeric >= Boolean], [@numeric], true
29
- assert_correct_type [Numeric >= Boolean], [@numeric], false
30
-
31
- assert_correct_type [Boolean, Numeric >= Numeric], [true, @numeric], @numeric
32
- assert_correct_type [Boolean, Array >= Array ], [true, @array ], @array
33
- assert_correct_type [Boolean, String >= String ], [true, @string ], @string
34
- assert_correct_type [Boolean, Hash >= Hash ], [true, @hash ], @hash
35
- assert_correct_type [Boolean, Symbol >= Symbol ], [true, @symbol ], @symbol
36
- end
37
-
38
- def test_wrong_return_type
39
- assert_wrong_rtn [Numeric >= Numeric], [@numeric], @array
40
- assert_wrong_rtn [Numeric >= Numeric], [@numeric], @string
41
- assert_wrong_rtn [Numeric >= Numeric], [@numeric], @hash
42
- assert_wrong_rtn [Numeric >= Numeric], [@numeric], @symbol
43
- assert_wrong_rtn [Numeric >= Numeric], [@numeric], true
44
-
45
- assert_wrong_rtn [Numeric, Numeric >= Numeric], [@numeric, @numeric], @array
46
- assert_wrong_rtn [Numeric, Numeric >= Numeric], [@numeric, @numeric], @string
47
- assert_wrong_rtn [Numeric, Numeric >= Numeric], [@numeric, @numeric], @hash
48
- assert_wrong_rtn [Numeric, Numeric >= Numeric], [@numeric, @numeric], @symbol
49
- assert_wrong_rtn [Numeric, Numeric >= Numeric], [@numeric, @numeric], true
50
- end
51
-
52
- def test_wrong_args_type
53
- assert_wrong_arg [Numeric >= Numeric], [@array ], @numeric
54
- assert_wrong_arg [Numeric >= Numeric], [@string], @numeric
55
- assert_wrong_arg [Numeric >= Numeric], [@hash ], @numeric
56
- assert_wrong_arg [Numeric >= Numeric], [@symbol], @numeric
57
- assert_wrong_arg [Numeric >= Numeric], [true ], @numeric
58
-
59
- assert_wrong_arg [Numeric, Numeric >= Numeric], [@numeric, @array ], @numeric
60
- assert_wrong_arg [Numeric, Numeric >= Numeric], [@numeric, @string], @numeric
61
- assert_wrong_arg [Numeric, Numeric >= Numeric], [@numeric, @hash ], @numeric
62
- assert_wrong_arg [Numeric, Numeric >= Numeric], [@numeric, @symbol], @numeric
63
- assert_wrong_arg [Numeric, Numeric >= Numeric], [@numeric, true ], @numeric
64
- end
65
-
66
- def test_any
67
- assert_correct_type [Any >= Any], [@array ], @numeric
68
- assert_correct_type [Any >= Any], [@string], @numeric
69
- assert_correct_type [Any >= Any], [@hash ], @numeric
70
- assert_correct_type [Any >= Any], [@symbol], @numeric
71
-
72
- assert_correct_type [Any, Any >= Any], [@numeric, @array ], @numeric
73
- assert_correct_type [Any, Any >= Any], [@numeric, @string], @numeric
74
- assert_correct_type [Any, Any >= Any], [@numeric, @hash ], @numeric
75
- assert_correct_type [Any, Any >= Any], [@numeric, @symbol], @numeric
76
- end
77
-
78
- private
79
- def assert_equal_to_s(str, val)
80
- assert_equal str, val.to_s
81
- end
82
-
83
- def assert_correct_type(type_list, args, val)
84
- assert_equal val, define_test_method(type_list, args, val).call(*args)
85
- end
86
-
87
- def assert_wrong_arg(type_list, args, val)
88
- assert_raises(ArgumentError) { define_test_method(type_list, args, val).call(*args) }
89
- end
90
-
91
- def assert_wrong_rtn(type_list, args, val)
92
- assert_raises(TypeError) { define_test_method(type_list, args, val).call(*args) }
93
- end
94
-
95
- def define_test_method(type_list, args, val)
96
- klass = Class.new.class_eval <<-RUBY_CODE
97
- def call(#{arg_literal(args.count)})
98
- #{obj_literal(val)}
99
- end
100
- type #{type_list.map(&:to_s).join(',')}, :call
101
- RUBY_CODE
102
-
103
- klass.new
104
- end
105
-
106
- def obj_literal(obj)
107
- "ObjectSpace._id2ref(#{obj.__id__})"
108
- end
109
-
110
- def arg_literal(count)
111
- ('a'..'z').to_a[0..count-1].join(',')
112
- end
113
- end