strongtyping 2.0.6 → 2.0.7
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/CHANGES +58 -0
- data/LGPL +515 -515
- data/MANIFEST +11 -9
- data/README +330 -0
- data/Rakefile +48 -0
- data/{extconf.rb → ext/extconf.rb} +3 -3
- data/ext/strongtyping.c +283 -0
- data/{strongtyping.h → ext/strongtyping.h} +34 -34
- data/{t/timetest.rb → samples/sample_strongtyping.rb} +28 -28
- data/strongtyping.gemspec +22 -24
- data/{t/test.rb → test/test_strongtyping.rb} +104 -100
- metadata +24 -21
- data/README.en +0 -420
- data/strongtyping.c +0 -247
- data/strongtyping.gemspec~ +0 -24
@@ -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"
|
data/strongtyping.gemspec
CHANGED
@@ -1,24 +1,22 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
optional(1,
|
18
|
-
}
|
19
|
-
|
20
|
-
assert_raises(ArgumentTypeError) {
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
add "a",
|
34
|
-
}
|
35
|
-
|
36
|
-
assert_raises(
|
37
|
-
add
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
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:
|
13
|
-
default_executable:
|
14
|
+
date: 2011-09-01 00:00:00 Z
|
14
15
|
dependencies: []
|
15
16
|
|
16
|
-
description: Ruby
|
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
|
25
|
+
- README
|
25
26
|
- MANIFEST
|
26
27
|
files:
|
27
|
-
-
|
28
|
+
- CHANGES
|
29
|
+
- ext/extconf.rb
|
30
|
+
- ext/strongtyping.c
|
31
|
+
- ext/strongtyping.h
|
28
32
|
- LGPL
|
29
33
|
- MANIFEST
|
30
|
-
-
|
31
|
-
-
|
34
|
+
- Rakefile
|
35
|
+
- README
|
36
|
+
- samples/sample_strongtyping.rb
|
32
37
|
- strongtyping.gemspec
|
33
|
-
-
|
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:
|
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.
|
62
|
+
rubygems_version: 1.8.10
|
59
63
|
signing_key:
|
60
|
-
specification_version:
|
61
|
-
summary: Ruby
|
64
|
+
specification_version: 3
|
65
|
+
summary: A Ruby library that provides type checking and method overloading
|
62
66
|
test_files:
|
63
|
-
-
|
64
|
-
- t/timetest.rb
|
67
|
+
- test/test_strongtyping.rb
|