linkage 0.0.8 → 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.yardopts +1 -0
- data/Gemfile +1 -19
- data/Gemfile-java +3 -0
- data/README.markdown +88 -34
- data/Rakefile +16 -15
- data/TODO +4 -0
- data/lib/linkage/comparator.rb +139 -144
- data/lib/linkage/comparators/compare.rb +236 -29
- data/lib/linkage/comparators/strcompare.rb +85 -0
- data/lib/linkage/comparators/within.rb +24 -20
- data/lib/linkage/configuration.rb +44 -466
- data/lib/linkage/dataset.rb +28 -127
- data/lib/linkage/exceptions.rb +5 -0
- data/lib/linkage/field.rb +6 -37
- data/lib/linkage/field_set.rb +3 -3
- data/lib/linkage/match_recorder.rb +22 -0
- data/lib/linkage/match_set.rb +34 -0
- data/lib/linkage/match_sets/csv.rb +39 -0
- data/lib/linkage/match_sets/database.rb +45 -0
- data/lib/linkage/matcher.rb +30 -0
- data/lib/linkage/result_set.rb +25 -110
- data/lib/linkage/result_sets/csv.rb +54 -0
- data/lib/linkage/result_sets/database.rb +42 -0
- data/lib/linkage/runner.rb +57 -16
- data/lib/linkage/score_recorder.rb +30 -0
- data/lib/linkage/score_set.rb +49 -0
- data/lib/linkage/score_sets/csv.rb +64 -0
- data/lib/linkage/score_sets/database.rb +77 -0
- data/lib/linkage/version.rb +1 -1
- data/lib/linkage.rb +14 -17
- data/linkage.gemspec +13 -1
- data/linkage.gemspec-java +32 -0
- data/test/helper.rb +30 -23
- data/test/integration/test_cross_linkage.rb +46 -25
- data/test/integration/test_database_result_set.rb +55 -0
- data/test/integration/test_dual_linkage.rb +19 -94
- data/test/integration/test_self_linkage.rb +100 -203
- data/test/integration/test_within_comparator.rb +24 -77
- data/test/unit/comparators/test_compare.rb +254 -50
- data/test/unit/comparators/test_strcompare.rb +45 -0
- data/test/unit/comparators/test_within.rb +14 -26
- data/test/unit/match_sets/test_csv.rb +78 -0
- data/test/unit/match_sets/test_database.rb +63 -0
- data/test/unit/result_sets/test_csv.rb +111 -0
- data/test/unit/result_sets/test_database.rb +68 -0
- data/test/unit/score_sets/test_csv.rb +151 -0
- data/test/unit/score_sets/test_database.rb +149 -0
- data/test/unit/test_comparator.rb +46 -83
- data/test/unit/test_comparators.rb +4 -0
- data/test/unit/test_configuration.rb +99 -145
- data/test/unit/test_dataset.rb +52 -73
- data/test/unit/test_field.rb +4 -55
- data/test/unit/test_field_set.rb +6 -6
- data/test/unit/test_match_recorder.rb +23 -0
- data/test/unit/test_match_set.rb +23 -0
- data/test/unit/test_match_sets.rb +4 -0
- data/test/unit/test_matcher.rb +44 -0
- data/test/unit/test_result_set.rb +24 -223
- data/test/unit/test_result_sets.rb +4 -0
- data/test/unit/test_runner.rb +122 -17
- data/test/unit/test_runners.rb +4 -0
- data/test/unit/test_score_recorder.rb +25 -0
- data/test/unit/test_score_set.rb +37 -0
- data/test/unit/test_score_sets.rb +4 -0
- metadata +183 -90
- data/Gemfile.lock +0 -92
- data/lib/linkage/comparators/binary.rb +0 -12
- data/lib/linkage/data.rb +0 -175
- data/lib/linkage/decollation.rb +0 -93
- data/lib/linkage/expectation.rb +0 -21
- data/lib/linkage/expectations/exhaustive.rb +0 -63
- data/lib/linkage/expectations/simple.rb +0 -168
- data/lib/linkage/function.rb +0 -148
- data/lib/linkage/functions/binary.rb +0 -30
- data/lib/linkage/functions/cast.rb +0 -54
- data/lib/linkage/functions/length.rb +0 -29
- data/lib/linkage/functions/strftime.rb +0 -33
- data/lib/linkage/functions/trim.rb +0 -30
- data/lib/linkage/group.rb +0 -55
- data/lib/linkage/meta_object.rb +0 -139
- data/lib/linkage/runner/single_threaded.rb +0 -187
- data/lib/linkage/utils.rb +0 -164
- data/lib/linkage/warnings.rb +0 -5
- data/test/integration/test_collation.rb +0 -45
- data/test/integration/test_configuration.rb +0 -268
- data/test/integration/test_dataset.rb +0 -116
- data/test/integration/test_functions.rb +0 -88
- data/test/integration/test_result_set.rb +0 -85
- data/test/integration/test_scoring.rb +0 -84
- data/test/unit/expectations/test_exhaustive.rb +0 -111
- data/test/unit/expectations/test_simple.rb +0 -303
- data/test/unit/functions/test_binary.rb +0 -54
- data/test/unit/functions/test_cast.rb +0 -98
- data/test/unit/functions/test_length.rb +0 -52
- data/test/unit/functions/test_strftime.rb +0 -60
- data/test/unit/functions/test_trim.rb +0 -43
- data/test/unit/runner/test_single_threaded.rb +0 -12
- data/test/unit/test_data.rb +0 -445
- data/test/unit/test_decollation.rb +0 -201
- data/test/unit/test_function.rb +0 -233
- data/test/unit/test_group.rb +0 -38
- data/test/unit/test_meta_object.rb +0 -208
- data/test/unit/test_utils.rb +0 -341
@@ -1,201 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
class UnitTests::TestDecollation < Test::Unit::TestCase
|
5
|
-
include Linkage::Decollation
|
6
|
-
|
7
|
-
test "mysql's latin1_swedish_ci handles 'A' letters" do
|
8
|
-
# MySQL 6.0.4 collation (http://www.collation-charts.org/mysql60/mysql604.latin1_swedish_ci.html)
|
9
|
-
["A", "a", "À", "Á", "Â", "Ã", "à", "á", "â", "ã"].each do |chr|
|
10
|
-
assert_equal "A", decollate(chr, :mysql, "latin1_swedish_ci")
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
test "mysql's latin1_swedish_ci handles 'B' letters" do
|
15
|
-
["B", "b"].each do |chr|
|
16
|
-
assert_equal "B", decollate(chr, :mysql, "latin1_swedish_ci")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
test "mysql's latin1_swedish_ci handles 'C' letters" do
|
21
|
-
["C", "c", "Ç", "ç"].each do |chr|
|
22
|
-
assert_equal "C", decollate(chr, :mysql, "latin1_swedish_ci")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
test "mysql's latin1_swedish_ci handles 'D' letters" do
|
27
|
-
["D", "d", "Ð", "ð"].each do |chr|
|
28
|
-
assert_equal "D", decollate(chr, :mysql, "latin1_swedish_ci")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
test "mysql's latin1_swedish_ci handles 'E' letters" do
|
33
|
-
["E", "e", "È", "É", "Ê", "Ë", "è", "é", "ê", "ë"].each do |chr|
|
34
|
-
assert_equal "E", decollate(chr, :mysql, "latin1_swedish_ci")
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
test "mysql's latin1_swedish_ci handles 'F' letters" do
|
39
|
-
["F", "f"].each do |chr|
|
40
|
-
assert_equal "F", decollate(chr, :mysql, "latin1_swedish_ci")
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
test "mysql's latin1_swedish_ci handles 'G' letters" do
|
45
|
-
["G", "g"].each do |chr|
|
46
|
-
assert_equal "G", decollate(chr, :mysql, "latin1_swedish_ci")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
test "mysql's latin1_swedish_ci handles 'H' letters" do
|
51
|
-
["H", "h"].each do |chr|
|
52
|
-
assert_equal "H", decollate(chr, :mysql, "latin1_swedish_ci")
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
test "mysql's latin1_swedish_ci handles 'I' letters" do
|
57
|
-
["I", "i", "Ì", "Í", "Î", "Ï", "ì", "í", "î", "ï"].each do |chr|
|
58
|
-
assert_equal "I", decollate(chr, :mysql, "latin1_swedish_ci")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
test "mysql's latin1_swedish_ci handles 'J' letters" do
|
63
|
-
["J", "j"].each do |chr|
|
64
|
-
assert_equal "J", decollate(chr, :mysql, "latin1_swedish_ci")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
test "mysql's latin1_swedish_ci handles 'K' letters" do
|
69
|
-
["K", "k"].each do |chr|
|
70
|
-
assert_equal "K", decollate(chr, :mysql, "latin1_swedish_ci")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
test "mysql's latin1_swedish_ci handles 'L' letters" do
|
75
|
-
["L", "l"].each do |chr|
|
76
|
-
assert_equal "L", decollate(chr, :mysql, "latin1_swedish_ci")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
test "mysql's latin1_swedish_ci handles 'M' letters" do
|
81
|
-
["M", "m"].each do |chr|
|
82
|
-
assert_equal "M", decollate(chr, :mysql, "latin1_swedish_ci")
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
test "mysql's latin1_swedish_ci handles 'N' letters" do
|
87
|
-
["N", "n", "Ñ", "ñ"].each do |chr|
|
88
|
-
assert_equal "N", decollate(chr, :mysql, "latin1_swedish_ci")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
test "mysql's latin1_swedish_ci handles 'O' letters" do
|
93
|
-
["O", "o", "Ò", "Ó", "Ô", "Õ", "ò", "ó", "ô", "õ"].each do |chr|
|
94
|
-
assert_equal "O", decollate(chr, :mysql, "latin1_swedish_ci")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
test "mysql's latin1_swedish_ci handles 'P' letters" do
|
99
|
-
["P", "p"].each do |chr|
|
100
|
-
assert_equal "P", decollate(chr, :mysql, "latin1_swedish_ci")
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
test "mysql's latin1_swedish_ci handles 'Q' letters" do
|
105
|
-
["Q", "q"].each do |chr|
|
106
|
-
assert_equal "Q", decollate(chr, :mysql, "latin1_swedish_ci")
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
test "mysql's latin1_swedish_ci handles 'R' letters" do
|
111
|
-
["R", "r"].each do |chr|
|
112
|
-
assert_equal "R", decollate(chr, :mysql, "latin1_swedish_ci")
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
test "mysql's latin1_swedish_ci handles 'S' letters" do
|
117
|
-
["S", "s"].each do |chr|
|
118
|
-
assert_equal "S", decollate(chr, :mysql, "latin1_swedish_ci")
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
test "mysql's latin1_swedish_ci handles 'T' letters" do
|
123
|
-
["T", "t"].each do |chr|
|
124
|
-
assert_equal "T", decollate(chr, :mysql, "latin1_swedish_ci")
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
test "mysql's latin1_swedish_ci handles 'U' letters" do
|
129
|
-
["U", "u", "Ù", "Ú", "Û", "ù", "ú", "û"].each do |chr|
|
130
|
-
assert_equal "U", decollate(chr, :mysql, "latin1_swedish_ci")
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
test "mysql's latin1_swedish_ci handles 'V' letters" do
|
135
|
-
["V", "v"].each do |chr|
|
136
|
-
assert_equal "V", decollate(chr, :mysql, "latin1_swedish_ci")
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
test "mysql's latin1_swedish_ci handles 'W' letters" do
|
141
|
-
["W", "w"].each do |chr|
|
142
|
-
assert_equal "W", decollate(chr, :mysql, "latin1_swedish_ci")
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
test "mysql's latin1_swedish_ci handles 'X' letters" do
|
147
|
-
["X", "x"].each do |chr|
|
148
|
-
assert_equal "X", decollate(chr, :mysql, "latin1_swedish_ci")
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
test "mysql's latin1_swedish_ci handles 'Y' letters" do
|
153
|
-
["Y", "y", "Ü", "Ý", "ü", "ý"].each do |chr|
|
154
|
-
assert_equal "Y", decollate(chr, :mysql, "latin1_swedish_ci")
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
test "mysql's latin1_swedish_ci handles 'Z' letters" do
|
159
|
-
["Z", "z"].each do |chr|
|
160
|
-
assert_equal "Z", decollate(chr, :mysql, "latin1_swedish_ci")
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
test "mysql's latin1_swedish_ci handles '[' letters" do
|
165
|
-
["[", "Å", "å"].each do |chr|
|
166
|
-
assert_equal "[", decollate(chr, :mysql, "latin1_swedish_ci")
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
test "mysql's latin1_swedish_ci handles '\\' letters" do
|
171
|
-
["\\", "Ä", "Æ", "ä", "æ"].each do |chr|
|
172
|
-
assert_equal "\\", decollate(chr, :mysql, "latin1_swedish_ci")
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
test "mysql's latin1_swedish_ci handles ']' letters" do
|
177
|
-
["]", "Ö", "ö"].each do |chr|
|
178
|
-
assert_equal "]", decollate(chr, :mysql, "latin1_swedish_ci")
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
test "mysql's latin1_swedish_ci handles 'Ø' letters" do
|
183
|
-
["Ø", "ø"].each do |chr|
|
184
|
-
assert_equal "Ø", decollate(chr, :mysql, "latin1_swedish_ci")
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
test "mysql's latin1_swedish_ci handles 'Þ' letters" do
|
189
|
-
["Þ", "þ"].each do |chr|
|
190
|
-
assert_equal "Þ", decollate(chr, :mysql, "latin1_swedish_ci")
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
test "mysql's latin1_swedish_ci ignores trailing spaces" do
|
195
|
-
assert_equal "FOO", decollate("foo ", :mysql, "latin1_swedish_ci")
|
196
|
-
end
|
197
|
-
|
198
|
-
test "unknown collation" do
|
199
|
-
assert_equal "fOo", decollate("fOo", :foo, :bar)
|
200
|
-
end
|
201
|
-
end
|
data/test/unit/test_function.rb
DELETED
@@ -1,233 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestFunction < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
@_functions = Linkage::Function.instance_variable_get("@functions")
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
Linkage::Function.instance_variable_set("@functions", @_functions)
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
test "subclass of data" do
|
16
|
-
assert_equal Linkage::Data, Linkage::Function.superclass
|
17
|
-
end
|
18
|
-
|
19
|
-
test "function_name returns nil in base class" do
|
20
|
-
assert_raises(NotImplementedError) { Linkage::Function.function_name }
|
21
|
-
end
|
22
|
-
|
23
|
-
test "ruby_type raises not implemented error in base class" do
|
24
|
-
klass = Class.new(Linkage::Function)
|
25
|
-
klass.send(:define_singleton_method, :function_name) { "foo" }
|
26
|
-
dataset = stub('dataset')
|
27
|
-
f = klass.new(:dataset => dataset)
|
28
|
-
assert_raises(NotImplementedError) { f.ruby_type }
|
29
|
-
end
|
30
|
-
|
31
|
-
test "registering subclass requires non-nil function_name" do
|
32
|
-
klass = Class.new(Linkage::Function)
|
33
|
-
assert_raises(ArgumentError) { Linkage::Function.register(klass) }
|
34
|
-
end
|
35
|
-
|
36
|
-
test "registering subclass requires ruby_type" do
|
37
|
-
klass = new_function('foo')
|
38
|
-
assert_raises(ArgumentError) { Linkage::Function.register(klass) }
|
39
|
-
end
|
40
|
-
|
41
|
-
test "function with no arguments" do
|
42
|
-
klass = new_function('foo', {:type => String})
|
43
|
-
f = klass.new(:dataset => stub('dataset'))
|
44
|
-
assert_equal :foo, f.name
|
45
|
-
assert_equal :foo.sql_function, f.to_expr
|
46
|
-
assert f.static?
|
47
|
-
end
|
48
|
-
|
49
|
-
test "function with static value" do
|
50
|
-
klass = new_function('foo', {:type => String})
|
51
|
-
f = klass.new(123, :dataset => stub('dataset'))
|
52
|
-
assert_equal :foo.sql_function(123), f.to_expr
|
53
|
-
assert_equal :foo_123, f.name
|
54
|
-
assert f.static?
|
55
|
-
end
|
56
|
-
|
57
|
-
test "function with field" do
|
58
|
-
klass = new_function('foo', {:type => String})
|
59
|
-
|
60
|
-
dataset = stub('dataset')
|
61
|
-
field = stub_field('field', {
|
62
|
-
:name => :bar, :to_expr => :bar,
|
63
|
-
:ruby_type => {:type => String}, :dataset => dataset
|
64
|
-
})
|
65
|
-
f = klass.new(field)
|
66
|
-
assert_equal :foo_bar, f.name
|
67
|
-
assert_equal :foo.sql_function(:bar), f.to_expr
|
68
|
-
assert_equal dataset, f.dataset
|
69
|
-
assert !f.static?
|
70
|
-
end
|
71
|
-
|
72
|
-
test "creating function with conflicting datasets raises exception" do
|
73
|
-
klass = new_function('foo', {:type => String}, [[String], [String]])
|
74
|
-
|
75
|
-
dataset_1 = stub('dataset')
|
76
|
-
field_1 = stub_field('field 1', {
|
77
|
-
:name => :foo, :to_expr => :foo,
|
78
|
-
:ruby_type => {:type => String}, :dataset => dataset_1
|
79
|
-
})
|
80
|
-
dataset_2 = stub('dataset')
|
81
|
-
field_2 = stub_field('field 2', {
|
82
|
-
:name => :bar, :to_expr => :bar,
|
83
|
-
:ruby_type => {:type => String}, :dataset => dataset_2
|
84
|
-
})
|
85
|
-
|
86
|
-
assert_raises(ArgumentError) { klass.new(field_1, field_2) }
|
87
|
-
end
|
88
|
-
|
89
|
-
test "getting dataset for a static function without dataset raises exception" do
|
90
|
-
klass = new_function('foo', {:type => String})
|
91
|
-
func = klass.new
|
92
|
-
assert_raises(RuntimeError) { func.dataset }
|
93
|
-
end
|
94
|
-
|
95
|
-
test "function with dynamic function" do
|
96
|
-
klass_1 = new_function('foo', {:type => String})
|
97
|
-
klass_2 = new_function('bar', {:type => String})
|
98
|
-
|
99
|
-
field = stub_field('field', :name => :baz, :to_expr => :baz, :ruby_type => {:type => String}, :dataset => stub('dataset'))
|
100
|
-
func_1 = klass_1.new(field)
|
101
|
-
assert_equal :foo_baz, func_1.name
|
102
|
-
assert !func_1.static?
|
103
|
-
|
104
|
-
func_2 = klass_2.new(func_1)
|
105
|
-
assert_equal :bar_foo_baz, func_2.name
|
106
|
-
assert !func_2.static?
|
107
|
-
assert_equal :bar.sql_function(:foo.sql_function(:baz)), func_2.to_expr
|
108
|
-
end
|
109
|
-
|
110
|
-
test "function with static function" do
|
111
|
-
klass_1 = new_function('foo', {:type => String})
|
112
|
-
klass_2 = new_function('bar', {:type => String})
|
113
|
-
|
114
|
-
func_1 = klass_1.new(123, :dataset => stub('dataset'))
|
115
|
-
assert_equal :foo_123, func_1.name
|
116
|
-
assert func_1.static?
|
117
|
-
|
118
|
-
func_2 = klass_2.new(func_1)
|
119
|
-
assert_equal :bar_foo_123, func_2.name
|
120
|
-
assert_equal :bar.sql_function(:foo.sql_function(123)), func_2.to_expr
|
121
|
-
assert func_2.static?
|
122
|
-
end
|
123
|
-
|
124
|
-
test "function with mixed function arguments" do
|
125
|
-
klass_1 = new_function('foo', {:type => String})
|
126
|
-
klass_2 = new_function('bar', {:type => String})
|
127
|
-
klass_3 = new_function('baz', {:type => String})
|
128
|
-
|
129
|
-
dataset = stub('dataset')
|
130
|
-
func_1 = klass_1.new(123, :dataset => dataset)
|
131
|
-
assert_equal :foo_123, func_1.name
|
132
|
-
assert func_1.static?
|
133
|
-
|
134
|
-
field = stub_field('field', :name => :quux, :to_expr => :quux, :ruby_type => {:type => String}, :dataset => dataset)
|
135
|
-
func_2 = klass_2.new(field)
|
136
|
-
assert_equal :bar_quux, func_2.name
|
137
|
-
assert !func_2.static?
|
138
|
-
|
139
|
-
func_3 = klass_3.new(func_2, func_1)
|
140
|
-
assert_equal :baz_bar_quux_foo_123, func_3.name
|
141
|
-
assert !func_3.static?
|
142
|
-
assert_equal :baz.sql_function(:bar.sql_function(:quux), :foo.sql_function(123)), func_3.to_expr
|
143
|
-
end
|
144
|
-
|
145
|
-
test "function with multiple fields" do
|
146
|
-
klass = new_function('foo', {:type => String})
|
147
|
-
dataset = stub('dataset')
|
148
|
-
field_1 = stub_field('field', :name => :bar, :to_expr => :bar, :ruby_type => {:type => String}, :dataset => dataset)
|
149
|
-
field_2 = stub_field('field', :name => :baz, :to_expr => :baz, :ruby_type => {:type => String}, :dataset => dataset)
|
150
|
-
func = klass.new(field_1, field_2)
|
151
|
-
assert_equal :foo_bar_baz, func.name
|
152
|
-
assert_equal :foo.sql_function(:bar, :baz), func.to_expr
|
153
|
-
assert !func.static?
|
154
|
-
end
|
155
|
-
|
156
|
-
test "function with multiple mixed arguments" do
|
157
|
-
klass = new_function('foo', {:type => String})
|
158
|
-
field = stub_field('field', :name => :bar, :to_expr => :bar, :ruby_type => {:type => String}, :dataset => stub('dataset'))
|
159
|
-
f = klass.new(field, 123, 'abc')
|
160
|
-
assert_equal :foo_bar_123_abc, f.name
|
161
|
-
assert_equal :foo.sql_function(:bar, 123, 'abc'), f.to_expr
|
162
|
-
end
|
163
|
-
|
164
|
-
test "fetching registered function" do
|
165
|
-
klass = new_function('foo', {:type => String})
|
166
|
-
Linkage::Function.register(klass)
|
167
|
-
assert_equal klass, Linkage::Function['foo']
|
168
|
-
end
|
169
|
-
|
170
|
-
test "valid parameters" do
|
171
|
-
klass = new_function('foo', {:type => String}, [[String]])
|
172
|
-
dataset = stub('dataset')
|
173
|
-
assert_equal :foo.sql_function("foo"), klass.new("foo", :dataset => dataset).to_expr
|
174
|
-
field = stub_field('field', :name => :bar, :to_expr => :bar, :ruby_type => {:type => String})
|
175
|
-
assert_equal :foo.sql_function(:bar), klass.new(field, :dataset => dataset).to_expr
|
176
|
-
assert_equal :foo.sql_function(:foo.sql_function("hey")), klass.new(klass.new("hey", :dataset => dataset)).to_expr
|
177
|
-
end
|
178
|
-
|
179
|
-
test "invalid parameters" do
|
180
|
-
func = new_function('foo', {:type => String}, [[String]])
|
181
|
-
assert_raises(TypeError) do
|
182
|
-
func.new(123)
|
183
|
-
end
|
184
|
-
field = stub_field('field', :name => :bar, :to_expr => :bar, :ruby_type => {:type => Integer})
|
185
|
-
assert_raises(TypeError) do
|
186
|
-
func.new(field)
|
187
|
-
end
|
188
|
-
func2 = new_function('bar', {:type => Integer})
|
189
|
-
dataset = stub('dataset')
|
190
|
-
assert_raises(TypeError) do
|
191
|
-
func.new(func2.new(:dataset => dataset))
|
192
|
-
end
|
193
|
-
assert_raises(ArgumentError) do
|
194
|
-
func.new("123", "456")
|
195
|
-
end
|
196
|
-
assert_raises(ArgumentError) do
|
197
|
-
func.new
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
test "two functions with the same name and arguments and datasets are equal" do
|
202
|
-
klass = new_function('foo', {:type => String}, [[String]])
|
203
|
-
dataset = stub('dataset')
|
204
|
-
field = stub_field('field', :dataset => dataset, :ruby_type => {:type => String})
|
205
|
-
|
206
|
-
func_1 = klass.new(field)
|
207
|
-
func_2 = klass.new(field)
|
208
|
-
assert func_1 == func_2
|
209
|
-
end
|
210
|
-
|
211
|
-
test "#== with two static functions" do
|
212
|
-
klass = new_function('foo', {:type => String}, [[String]])
|
213
|
-
dataset = stub('dataset')
|
214
|
-
func_1 = klass.new('foo', :dataset => dataset)
|
215
|
-
func_2 = klass.new('foo', :dataset => dataset)
|
216
|
-
assert func_1 == func_2
|
217
|
-
end
|
218
|
-
|
219
|
-
test "collation returns nil by default" do
|
220
|
-
klass = new_function('foo', {:type => String}, [[String]])
|
221
|
-
dataset = stub('dataset')
|
222
|
-
func = klass.new('foo', :dataset => dataset)
|
223
|
-
assert_nil func.collation
|
224
|
-
end
|
225
|
-
|
226
|
-
test "special :any parameter" do
|
227
|
-
klass = new_function('foo', {:type => String}, [[:any]])
|
228
|
-
dataset = stub('dataset')
|
229
|
-
assert_nothing_raised do
|
230
|
-
klass.new('foo', :dataset => dataset)
|
231
|
-
end
|
232
|
-
end
|
233
|
-
end
|
data/test/unit/test_group.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestGroup < Test::Unit::TestCase
|
4
|
-
test "initialize" do
|
5
|
-
g = Linkage::Group.new({:test => 'test'}, {:count => 1, :id => 456})
|
6
|
-
assert_equal({:test => 'test'}, g.values)
|
7
|
-
assert_equal 1, g.count
|
8
|
-
assert_equal 456, g.id
|
9
|
-
end
|
10
|
-
|
11
|
-
test "decollate strings" do
|
12
|
-
test_ruby_type = { :type => String, :opts => { :collate => "latin1_swedish_ci" } }
|
13
|
-
group = Linkage::Group.new({:test => 'TeSt '}, {
|
14
|
-
:count => 1, :id => 456, :ruby_types => { :test => test_ruby_type },
|
15
|
-
:database_type => :mysql
|
16
|
-
})
|
17
|
-
assert_equal({:test => "TEST"}, group.decollated_values)
|
18
|
-
end
|
19
|
-
|
20
|
-
test "don't decollate non-strings or strings without collation information" do
|
21
|
-
ruby_types = {
|
22
|
-
:foo => {
|
23
|
-
:type => String, :opts => { :collate => "latin1_swedish_ci" }
|
24
|
-
},
|
25
|
-
:bar => {
|
26
|
-
:type => Fixnum
|
27
|
-
},
|
28
|
-
:baz => {
|
29
|
-
:type => String
|
30
|
-
}
|
31
|
-
}
|
32
|
-
group = Linkage::Group.new({:foo => 'foO', :bar => 123, :baz => "foO"}, {
|
33
|
-
:count => 1, :id => 456, :ruby_types => ruby_types,
|
34
|
-
:database_type => :mysql
|
35
|
-
})
|
36
|
-
assert_equal({:foo => "FOO", :bar => 123, :baz => "foO"}, group.decollated_values)
|
37
|
-
end
|
38
|
-
end
|
@@ -1,208 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class UnitTests::TestMetaObject < Test::Unit::TestCase
|
4
|
-
test "initialize with static string" do
|
5
|
-
meta_object = Linkage::MetaObject.new("foo")
|
6
|
-
assert meta_object.static?
|
7
|
-
assert_equal "foo", meta_object.object
|
8
|
-
assert_nil meta_object.side
|
9
|
-
end
|
10
|
-
|
11
|
-
test "initialize with static function" do
|
12
|
-
function = stub_function("foo", :static? => true)
|
13
|
-
meta_object = Linkage::MetaObject.new(function)
|
14
|
-
assert meta_object.static?
|
15
|
-
assert_equal function, meta_object.object
|
16
|
-
assert_nil meta_object.side
|
17
|
-
end
|
18
|
-
|
19
|
-
test "initialize with field" do
|
20
|
-
field = stub_field("foo")
|
21
|
-
meta_object = Linkage::MetaObject.new(field, :lhs)
|
22
|
-
assert !meta_object.static?
|
23
|
-
assert_equal field, meta_object.object
|
24
|
-
assert_equal :lhs, meta_object.side
|
25
|
-
end
|
26
|
-
|
27
|
-
test "getting side for dynamic object without setting it raises error" do
|
28
|
-
meta_object = Linkage::MetaObject.new(stub_field('foo'))
|
29
|
-
assert_raises(RuntimeError) { meta_object.side }
|
30
|
-
end
|
31
|
-
|
32
|
-
test "getting dataset calls #dataset on object" do
|
33
|
-
field = stub_field('foo')
|
34
|
-
meta_object = Linkage::MetaObject.new(field)
|
35
|
-
|
36
|
-
dataset = stub('dataset')
|
37
|
-
field.expects(:dataset).returns(dataset)
|
38
|
-
assert_equal dataset, meta_object.dataset
|
39
|
-
end
|
40
|
-
|
41
|
-
test "setting dataset sets object's dataset" do
|
42
|
-
func = stub_function('foo')
|
43
|
-
meta_object = Linkage::MetaObject.new(func)
|
44
|
-
|
45
|
-
dataset = stub('dataset')
|
46
|
-
func.expects(:dataset=).with(dataset)
|
47
|
-
meta_object.dataset = dataset
|
48
|
-
end
|
49
|
-
|
50
|
-
test "setting dataset on non-data object raises exception" do
|
51
|
-
meta_object = Linkage::MetaObject.new(123)
|
52
|
-
dataset = stub('dataset')
|
53
|
-
assert_raises(RuntimeError) { meta_object.dataset = dataset }
|
54
|
-
end
|
55
|
-
|
56
|
-
test "objects_equal? compares only objects, not sides" do
|
57
|
-
field = stub_field("foo")
|
58
|
-
object_1 = Linkage::MetaObject.new(field, :lhs)
|
59
|
-
object_2 = Linkage::MetaObject.new(field, :rhs)
|
60
|
-
object_3 = Linkage::MetaObject.new(123)
|
61
|
-
assert object_1.objects_equal?(object_2)
|
62
|
-
assert !object_1.objects_equal?("foo")
|
63
|
-
assert !object_2.objects_equal?(object_3)
|
64
|
-
end
|
65
|
-
|
66
|
-
test "dataset reader for field" do
|
67
|
-
dataset = stub('dataset')
|
68
|
-
field = stub_field("foo", :dataset => dataset)
|
69
|
-
object = Linkage::MetaObject.new(field, :lhs)
|
70
|
-
|
71
|
-
assert_equal dataset, object.dataset
|
72
|
-
end
|
73
|
-
|
74
|
-
test "dataset reader for function" do
|
75
|
-
dataset = stub('dataset')
|
76
|
-
function = stub_function("foo", :dataset => dataset)
|
77
|
-
object = Linkage::MetaObject.new(function, :lhs)
|
78
|
-
|
79
|
-
assert_equal dataset, object.dataset
|
80
|
-
end
|
81
|
-
|
82
|
-
test "datasets_equal?" do
|
83
|
-
dataset_1 = stub('dataset 1')
|
84
|
-
field_1 = stub_field('field 1', :dataset => dataset_1)
|
85
|
-
object_1 = Linkage::MetaObject.new(field_1, :lhs)
|
86
|
-
|
87
|
-
dataset_2 = stub('dataset 2')
|
88
|
-
field_2 = stub_field('field 2', :dataset => dataset_2)
|
89
|
-
object_2 = Linkage::MetaObject.new(field_2, :rhs)
|
90
|
-
|
91
|
-
field_3 = stub_field('field 3', :dataset => dataset_2)
|
92
|
-
object_3 = Linkage::MetaObject.new(field_3, :rhs)
|
93
|
-
|
94
|
-
object_4 = Linkage::MetaObject.new(123)
|
95
|
-
|
96
|
-
assert object_1.datasets_equal?(object_1)
|
97
|
-
assert object_2.datasets_equal?(object_3)
|
98
|
-
assert !object_1.datasets_equal?(object_2)
|
99
|
-
assert !object_1.datasets_equal?("foo")
|
100
|
-
assert !object_1.datasets_equal?(object_4)
|
101
|
-
end
|
102
|
-
|
103
|
-
test "to_expr for non-data object returns object" do
|
104
|
-
object = Linkage::MetaObject.new(123)
|
105
|
-
assert_equal 123, object.to_expr
|
106
|
-
end
|
107
|
-
|
108
|
-
test "to_expr for data object returns object.to_expr" do
|
109
|
-
field = stub_field('field')
|
110
|
-
object = Linkage::MetaObject.new(field, :lhs)
|
111
|
-
|
112
|
-
field.expects(:to_expr).returns(:foo)
|
113
|
-
assert_equal :foo, object.to_expr
|
114
|
-
end
|
115
|
-
|
116
|
-
test "to_identifier for non-data object returns object" do
|
117
|
-
object = Linkage::MetaObject.new(123)
|
118
|
-
assert_equal 123, object.to_identifier
|
119
|
-
end
|
120
|
-
|
121
|
-
test "to_identifer for data object returns identifier object" do
|
122
|
-
field = stub_field('field')
|
123
|
-
object = Linkage::MetaObject.new(field, :lhs)
|
124
|
-
|
125
|
-
field.expects(:to_expr).returns(:foo)
|
126
|
-
assert_equal(Sequel::SQL::Identifier.new(:foo), object.to_identifier)
|
127
|
-
end
|
128
|
-
|
129
|
-
test "merge with data object" do
|
130
|
-
field_1 = stub_field('field 1')
|
131
|
-
object_1 = Linkage::MetaObject.new(field_1, :lhs)
|
132
|
-
field_2 = stub_field('field 2')
|
133
|
-
object_2 = Linkage::MetaObject.new(field_2, :rhs)
|
134
|
-
|
135
|
-
merged_field = stub('merged field')
|
136
|
-
field_1.expects(:merge).with(field_2).returns(merged_field)
|
137
|
-
assert_equal merged_field, object_1.merge(object_2)
|
138
|
-
end
|
139
|
-
|
140
|
-
test "merge with non-data object raises exception" do
|
141
|
-
field_1 = stub_field('field 1')
|
142
|
-
object_1 = Linkage::MetaObject.new(field_1, :lhs)
|
143
|
-
object_2 = Linkage::MetaObject.new(123)
|
144
|
-
assert_raises(ArgumentError) { object_1.merge(object_2) }
|
145
|
-
assert_raises(ArgumentError) { object_2.merge(object_1) }
|
146
|
-
end
|
147
|
-
|
148
|
-
test "ruby_type calls Field#ruby_type" do
|
149
|
-
field = stub_field('field')
|
150
|
-
object = Linkage::MetaObject.new(field, :lhs)
|
151
|
-
field.expects(:ruby_type).returns(:type => String)
|
152
|
-
assert_equal({:type => String}, object.ruby_type)
|
153
|
-
end
|
154
|
-
|
155
|
-
test "ruby_type calls Function#ruby_type" do
|
156
|
-
function = stub_function("foo")
|
157
|
-
object = Linkage::MetaObject.new(function, :lhs)
|
158
|
-
function.expects(:ruby_type).returns(:type => String)
|
159
|
-
assert_equal({:type => String}, object.ruby_type)
|
160
|
-
end
|
161
|
-
|
162
|
-
test "ruby_type returns object class for non-data object" do
|
163
|
-
object = Linkage::MetaObject.new(123)
|
164
|
-
assert_equal({:type => Fixnum}, object.ruby_type)
|
165
|
-
end
|
166
|
-
|
167
|
-
test "database_type" do
|
168
|
-
dataset = mock('dataset')
|
169
|
-
field = stub_field('field', :dataset => dataset)
|
170
|
-
object = Linkage::MetaObject.new(field, :lhs)
|
171
|
-
dataset.expects(:database_type).returns(:mysql)
|
172
|
-
assert_equal :mysql, object.database_type
|
173
|
-
end
|
174
|
-
|
175
|
-
test "#collation returns Data#collation" do
|
176
|
-
dataset = mock('dataset')
|
177
|
-
field = stub_field('field', :dataset => dataset, :collation => 'foo')
|
178
|
-
object = Linkage::MetaObject.new(field, :lhs)
|
179
|
-
assert_equal 'foo', object.collation
|
180
|
-
end
|
181
|
-
|
182
|
-
test "#collation returns nil when underlying object is not a Data object" do
|
183
|
-
object = Linkage::MetaObject.new(123, :lhs)
|
184
|
-
assert_nil object.collation
|
185
|
-
end
|
186
|
-
|
187
|
-
test "#name for data object" do
|
188
|
-
field = stub_field('foo', :name => :foo)
|
189
|
-
object = Linkage::MetaObject.new(field, :lhs)
|
190
|
-
assert_equal :foo, object.name
|
191
|
-
end
|
192
|
-
|
193
|
-
test "#name for non-data object returns nil" do
|
194
|
-
object = Linkage::MetaObject.new(123)
|
195
|
-
assert_nil object.name
|
196
|
-
end
|
197
|
-
|
198
|
-
test "#raw? returns true for non-data object" do
|
199
|
-
object = Linkage::MetaObject.new(123)
|
200
|
-
assert object.raw?
|
201
|
-
end
|
202
|
-
|
203
|
-
test "#raw? returns false for data object" do
|
204
|
-
field = stub_field('foo', :name => :foo)
|
205
|
-
object = Linkage::MetaObject.new(field, :lhs)
|
206
|
-
assert !object.raw?
|
207
|
-
end
|
208
|
-
end
|