strongtyping 2.0.6-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/LGPL +515 -0
- data/MANIFEST +9 -0
- data/README.en +420 -0
- data/extconf.rb +3 -0
- data/lib/strongtyping.so +0 -0
- data/strongtyping.c +247 -0
- data/strongtyping.h +34 -0
- data/t/test.rb +100 -0
- data/t/timetest.rb +28 -0
- metadata +64 -0
data/strongtyping.h
ADDED
@@ -0,0 +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
|
+
|
data/t/test.rb
ADDED
@@ -0,0 +1,100 @@
|
|
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
|
data/t/timetest.rb
ADDED
@@ -0,0 +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"
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strongtyping
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.6
|
5
|
+
platform: x86-mswin32-60
|
6
|
+
authors:
|
7
|
+
- Ryan Pavlik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-02-06 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Ruby module that provides type checking and method overloading
|
17
|
+
email: rpav@mephle.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LGPL
|
24
|
+
- README.en
|
25
|
+
- MANIFEST
|
26
|
+
files:
|
27
|
+
- extconf.rb
|
28
|
+
- LGPL
|
29
|
+
- MANIFEST
|
30
|
+
- README.en
|
31
|
+
- strongtyping.c
|
32
|
+
- strongtyping.h
|
33
|
+
- t/test.rb
|
34
|
+
- t/timetest.rb
|
35
|
+
- lib/strongtyping.so
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://mephle.org/StrongTyping/
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.8.0
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: shards
|
58
|
+
rubygems_version: 1.0.1
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: Ruby module that provides type checking and method overloading
|
62
|
+
test_files:
|
63
|
+
- t/test.rb
|
64
|
+
- t/timetest.rb
|