strongtyping 2.0.6 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,34 +1,34 @@
1
- /*
2
- StrongTyping - Method parameter checking for Ruby
3
- Copyright (C) 2003 Ryan Pavlik
4
-
5
- This library is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU Lesser General Public
7
- License as published by the Free Software Foundation; either
8
- version 2.1 of the License, or (at your option) any later version.
9
-
10
- This library is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- Lesser General Public License for more details.
14
-
15
- You should have received a copy of the GNU Lesser General Public
16
- License along with this library; if not, write to the Free Software
17
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
- */
19
-
20
- #ifndef __GNUC__
21
- /* We can use this extension to get rid of some superfluous warnings */
22
- # define __attribute__(x)
23
- # define MAXARGS (128)
24
- #else
25
- # define MAXARGS (argc/2)
26
- #endif
27
-
28
- #define UNUSED __attribute__ ((unused))
29
-
30
- VALUE mStrongTyping;
31
- VALUE cQueryParams;
32
- VALUE eArgumentTypeError, eOverloadError, eArgList;
33
- ID id_isa, id_class, id_inspect;
34
-
1
+ /*
2
+ StrongTyping - Method parameter checking for Ruby
3
+ Copyright (C) 2003 Ryan Pavlik
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
+ */
19
+
20
+ #ifndef __GNUC__
21
+ /* We can use this extension to get rid of some superfluous warnings */
22
+ # define __attribute__(x)
23
+ # define MAXARGS (128)
24
+ #else
25
+ # define MAXARGS (argc/2)
26
+ #endif
27
+
28
+ #define UNUSED __attribute__ ((unused))
29
+
30
+ VALUE mStrongTyping;
31
+ VALUE cQueryParams;
32
+ VALUE eArgumentTypeError, eOverloadError, eArgList;
33
+ ID id_isa, id_class, id_inspect;
34
+
@@ -1,28 +1,28 @@
1
- require 'strongtyping'
2
- include StrongTyping
3
-
4
- def timeblock(msg = nil)
5
- start = Time::now.to_f
6
- yield
7
- finish = Time::now.to_f
8
-
9
- print "[#{msg}] " if msg
10
- print "Total time: #{finish - start}\n"
11
-
12
- return finish - start
13
- end
14
-
15
- iterations = 100000
16
-
17
- time_0 = timeblock("Base Time") {
18
- (1..iterations).each do |i| end
19
- }
20
-
21
- time_1 = timeblock("Expect") {
22
- (1..iterations).each do
23
- |i|
24
- expect(1, Integer, "abc", String)
25
- end
26
- }
27
-
28
- print "Difference for #{iterations} iterations: #{time_1 - time_0}\n"
1
+ require 'strongtyping'
2
+ include StrongTyping
3
+
4
+ def timeblock(msg = nil)
5
+ start = Time::now.to_f
6
+ yield
7
+ finish = Time::now.to_f
8
+
9
+ print "[#{msg}] " if msg
10
+ print "Total time: #{finish - start}\n"
11
+
12
+ return finish - start
13
+ end
14
+
15
+ iterations = 100000
16
+
17
+ time_0 = timeblock("Base Time") {
18
+ (1..iterations).each do |i| end
19
+ }
20
+
21
+ time_1 = timeblock("Expect") {
22
+ (1..iterations).each do
23
+ |i|
24
+ expect(1, Integer, "abc", String)
25
+ end
26
+ }
27
+
28
+ print "Difference for #{iterations} iterations: #{time_1 - time_0}\n"
@@ -1,24 +1,22 @@
1
- require 'rubygems'
2
-
3
- spec = Gem::Specification.new do |gem|
4
- gem.name = 'strongtyping'
5
- gem.version = '2.0.6'
6
- gem.author = 'Ryan Pavlik'
7
- gem.email = 'rpav@mephle.com'
8
- gem.homepage = 'http://mephle.org/StrongTyping/'
9
- gem.platform = Gem::Platform::RUBY
10
- gem.summary = 'Ruby module that provides type checking and method overloading'
11
- gem.description = 'Ruby module that provides type checking and method overloading'
12
- gem.test_files = Dir['t/*.rb']
13
- gem.has_rdoc = false
14
- gem.extra_rdoc_files = ['LGPL', 'README.en', 'MANIFEST']
15
- gem.rubyforge_project = 'shards'
16
- gem.files = Dir['*']
17
- gem.required_ruby_version = '>= 1.8.0'
18
- gem.extensions = ['extconf.rb']
19
- end
20
-
21
- if $0 == __FILE__
22
- Gem.manage_gems
23
- Gem::Builder.new(spec).build
24
- end
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'strongtyping'
5
+ spec.version = '2.0.7'
6
+ spec.authors = ['Ryan Pavlik', 'Daniel Berger']
7
+ spec.email = 'rpav@mephle.com'
8
+ spec.license = 'LGPL'
9
+ spec.homepage = 'http://mephle.org/StrongTyping/'
10
+ spec.summary = 'A Ruby library that provides type checking and method overloading'
11
+ spec.test_files = Dir['test/*.rb']
12
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
+ spec.extensions = ['ext/extconf.rb']
14
+
15
+ spec.extra_rdoc_files = ['LGPL', 'README', 'MANIFEST']
16
+ spec.rubyforge_project = 'shards'
17
+
18
+ spec.description = %Q{
19
+ The strongtyping gem is a Ruby library that provides type checking and
20
+ method overloading.
21
+ }
22
+ end
@@ -1,100 +1,104 @@
1
- require 'test/unit'
2
- require 'strongtyping'
3
- include StrongTyping
4
-
5
- class TS_StrongTyping < Test::Unit::TestCase
6
- def test_expect
7
- assert_raises(ArgumentTypeError) {
8
- foo("hello", 2, 3)
9
- }
10
-
11
- assert_nothing_raised {
12
- optional(1)
13
- optional(1, 2)
14
- }
15
-
16
- assert_raises(ArgumentTypeError) {
17
- optional(1, "abc")
18
- }
19
-
20
- assert_raises(ArgumentTypeError) {
21
- optional2(nil, "abc")
22
- }
23
- end #m:test_expect
24
-
25
- def test_overload
26
- assert_nothing_raised {
27
- add
28
- add 1, 2
29
- add "a", "b"
30
- }
31
-
32
- assert_raises(RuntimeError) {
33
- add "a", 2
34
- }
35
-
36
- assert_raises(OverloadError) {
37
- add 2, "a"
38
- }
39
- end #m:test_overload
40
-
41
-
42
- def test_get_arg_types
43
- assert_equal([[]], get_arg_types(method(:blank)))
44
-
45
- assert_equal([[String, Integer, String]],
46
- get_arg_types(method(:foo)))
47
-
48
- assert_equal([[Integer, [Integer, NilClass]]],
49
- get_arg_types(method(:optional)))
50
-
51
- assert_equal([[], [Integer, Integer], [String, String]],
52
- get_arg_types(method(:add)))
53
- end #m:test_get_arg_types
54
-
55
-
56
- def test_verify_args_for
57
- a1 = [1, 2]
58
- a2 = ["a", 2]
59
-
60
- assert(verify_args_for(method(:add), a1))
61
- assert(!verify_args_for(method(:add), a2))
62
- end #m:test_verify_args_for
63
- end #c:TS_StrongTyping
64
-
65
-
66
- ##
67
- ## Helpers
68
- ##
69
-
70
- def blank
71
- end #m:blank
72
-
73
- def foo(a, b, c)
74
- expect(a, String, b, Integer, c, String)
75
- print "#{a} found #{b} #{c}\n"
76
- end
77
-
78
- def optional(a, b = nil)
79
- expect(a, Integer, b, [Integer, NilClass])
80
- return a + b if b
81
- return a
82
- end
83
-
84
- def optional2(a, b)
85
- expect(a, [Integer, NilClass], b, Integer)
86
- end
87
-
88
- # useful, but demonstrates it works
89
- def add (*args)
90
- overload(args) { return }
91
- overload(args, Integer, Integer) { | a, b | return }
92
- overload(args, String, String) { | a, b | return }
93
-
94
- overload_exception(args, String, Integer) {
95
- | a, b |
96
- raise "I'm not going there."
97
- }
98
-
99
- overload_default args
100
- end
1
+ require 'test/unit'
2
+ require 'strongtyping'
3
+ include StrongTyping
4
+
5
+ class TS_StrongTyping < Test::Unit::TestCase
6
+ def test_version
7
+ assert_equal('2.0.7', StrongTyping::VERSION)
8
+ end
9
+
10
+ def test_expect
11
+ assert_raises(ArgumentTypeError) {
12
+ foo("hello", 2, 3)
13
+ }
14
+
15
+ assert_nothing_raised {
16
+ optional(1)
17
+ optional(1, 2)
18
+ }
19
+
20
+ assert_raises(ArgumentTypeError) {
21
+ optional(1, "abc")
22
+ }
23
+
24
+ assert_raises(ArgumentTypeError) {
25
+ optional2(nil, "abc")
26
+ }
27
+ end #m:test_expect
28
+
29
+ def test_overload
30
+ assert_nothing_raised {
31
+ add
32
+ add 1, 2
33
+ add "a", "b"
34
+ }
35
+
36
+ assert_raises(RuntimeError) {
37
+ add "a", 2
38
+ }
39
+
40
+ assert_raises(OverloadError) {
41
+ add 2, "a"
42
+ }
43
+ end #m:test_overload
44
+
45
+
46
+ def test_get_arg_types
47
+ assert_equal([[]], get_arg_types(method(:blank)))
48
+
49
+ assert_equal([[String, Integer, String]],
50
+ get_arg_types(method(:foo)))
51
+
52
+ assert_equal([[Integer, [Integer, NilClass]]],
53
+ get_arg_types(method(:optional)))
54
+
55
+ assert_equal([[], [Integer, Integer], [String, String]],
56
+ get_arg_types(method(:add)))
57
+ end #m:test_get_arg_types
58
+
59
+
60
+ def test_verify_args_for
61
+ a1 = [1, 2]
62
+ a2 = ["a", 2]
63
+
64
+ assert(verify_args_for(method(:add), a1))
65
+ assert(!verify_args_for(method(:add), a2))
66
+ end #m:test_verify_args_for
67
+ end #c:TS_StrongTyping
68
+
69
+
70
+ ##
71
+ ## Helpers
72
+ ##
73
+
74
+ def blank
75
+ end #m:blank
76
+
77
+ def foo(a, b, c)
78
+ expect(a, String, b, Integer, c, String)
79
+ print "#{a} found #{b} #{c}\n"
80
+ end
81
+
82
+ def optional(a, b = nil)
83
+ expect(a, Integer, b, [Integer, NilClass])
84
+ return a + b if b
85
+ return a
86
+ end
87
+
88
+ def optional2(a, b)
89
+ expect(a, [Integer, NilClass], b, Integer)
90
+ end
91
+
92
+ # useful, but demonstrates it works
93
+ def add (*args)
94
+ overload(args) { return }
95
+ overload(args, Integer, Integer) { | a, b | return }
96
+ overload(args, String, String) { | a, b | return }
97
+
98
+ overload_exception(args, String, Integer) {
99
+ | a, b |
100
+ raise "I'm not going there."
101
+ }
102
+
103
+ overload_default args
104
+ end
metadata CHANGED
@@ -1,64 +1,67 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strongtyping
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ prerelease:
5
+ version: 2.0.7
5
6
  platform: ruby
6
7
  authors:
7
8
  - Ryan Pavlik
9
+ - Daniel Berger
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
13
 
12
- date: 2008-02-06 00:00:00 -07:00
13
- default_executable:
14
+ date: 2011-09-01 00:00:00 Z
14
15
  dependencies: []
15
16
 
16
- description: Ruby module that provides type checking and method overloading
17
+ description: "\n The strongtyping gem is a Ruby library that provides type checking and\n method overloading.\n "
17
18
  email: rpav@mephle.com
18
19
  executables: []
19
20
 
20
21
  extensions:
21
- - extconf.rb
22
+ - ext/extconf.rb
22
23
  extra_rdoc_files:
23
24
  - LGPL
24
- - README.en
25
+ - README
25
26
  - MANIFEST
26
27
  files:
27
- - extconf.rb
28
+ - CHANGES
29
+ - ext/extconf.rb
30
+ - ext/strongtyping.c
31
+ - ext/strongtyping.h
28
32
  - LGPL
29
33
  - MANIFEST
30
- - README.en
31
- - strongtyping.c
34
+ - Rakefile
35
+ - README
36
+ - samples/sample_strongtyping.rb
32
37
  - strongtyping.gemspec
33
- - strongtyping.gemspec~
34
- - strongtyping.h
35
- - t
36
- has_rdoc: false
38
+ - test/test_strongtyping.rb
37
39
  homepage: http://mephle.org/StrongTyping/
40
+ licenses:
41
+ - LGPL
38
42
  post_install_message:
39
43
  rdoc_options: []
40
44
 
41
45
  require_paths:
42
46
  - lib
43
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
44
49
  requirements:
45
50
  - - ">="
46
51
  - !ruby/object:Gem::Version
47
- version: 1.8.0
48
- version:
52
+ version: "0"
49
53
  required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
50
55
  requirements:
51
56
  - - ">="
52
57
  - !ruby/object:Gem::Version
53
58
  version: "0"
54
- version:
55
59
  requirements: []
56
60
 
57
61
  rubyforge_project: shards
58
- rubygems_version: 1.0.1
62
+ rubygems_version: 1.8.10
59
63
  signing_key:
60
- specification_version: 2
61
- summary: Ruby module that provides type checking and method overloading
64
+ specification_version: 3
65
+ summary: A Ruby library that provides type checking and method overloading
62
66
  test_files:
63
- - t/test.rb
64
- - t/timetest.rb
67
+ - test/test_strongtyping.rb