sqlpostgres 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.md +23 -0
- data/README.rdoc +59 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/doc/BUGS +2 -0
- data/doc/examples/README +6 -0
- data/doc/examples/connection.rb +16 -0
- data/doc/examples/connection_auto.rb +22 -0
- data/doc/examples/connection_ctor.rb +18 -0
- data/doc/examples/connection_default.rb +15 -0
- data/doc/examples/connection_exec.rb +18 -0
- data/doc/examples/connection_manual.rb +12 -0
- data/doc/examples/connection_wrapped_new.rb +13 -0
- data/doc/examples/connection_wrapped_open.rb +13 -0
- data/doc/examples/cursor.rb +38 -0
- data/doc/examples/include_module.rb +9 -0
- data/doc/examples/include_module2.rb +12 -0
- data/doc/examples/insert.rb +30 -0
- data/doc/examples/insert2.rb +36 -0
- data/doc/examples/insert_bytea.rb +16 -0
- data/doc/examples/insert_bytea_array.rb +17 -0
- data/doc/examples/insert_default_values.rb +16 -0
- data/doc/examples/insert_insert.rb +16 -0
- data/doc/examples/insert_insert_default.rb +16 -0
- data/doc/examples/insert_insert_select.rb +20 -0
- data/doc/examples/insert_select.rb +20 -0
- data/doc/examples/interval.rb +17 -0
- data/doc/examples/savepoint.rb +38 -0
- data/doc/examples/select.rb +33 -0
- data/doc/examples/select2.rb +36 -0
- data/doc/examples/select_cross_join.rb +18 -0
- data/doc/examples/select_distinct.rb +18 -0
- data/doc/examples/select_distinct_on +19 -0
- data/doc/examples/select_for_update.rb +18 -0
- data/doc/examples/select_from.rb +17 -0
- data/doc/examples/select_from_subselect.rb +20 -0
- data/doc/examples/select_group_by.rb +19 -0
- data/doc/examples/select_having.rb +20 -0
- data/doc/examples/select_join_on.rb +18 -0
- data/doc/examples/select_join_using.rb +18 -0
- data/doc/examples/select_limit.rb +19 -0
- data/doc/examples/select_natural_join.rb +18 -0
- data/doc/examples/select_offset.rb +19 -0
- data/doc/examples/select_order_by.rb +20 -0
- data/doc/examples/select_select.rb +30 -0
- data/doc/examples/select_select_alias.rb +30 -0
- data/doc/examples/select_select_expression.rb +31 -0
- data/doc/examples/select_select_literal.rb +24 -0
- data/doc/examples/select_union.rb +21 -0
- data/doc/examples/select_where_array.rb +18 -0
- data/doc/examples/select_where_in.rb +18 -0
- data/doc/examples/select_where_string.rb +18 -0
- data/doc/examples/simple.rb +34 -0
- data/doc/examples/transaction.rb +30 -0
- data/doc/examples/transaction_abort.rb +30 -0
- data/doc/examples/transaction_commit.rb +34 -0
- data/doc/examples/translate_substitute_values.rb +17 -0
- data/doc/examples/update.rb +32 -0
- data/doc/examples/update2.rb +44 -0
- data/doc/examples/update_only.rb +17 -0
- data/doc/examples/update_set.rb +17 -0
- data/doc/examples/update_set_array.rb +16 -0
- data/doc/examples/update_set_bytea.rb +16 -0
- data/doc/examples/update_set_expression.rb +16 -0
- data/doc/examples/update_set_subselect.rb +20 -0
- data/doc/examples/update_where.rb +17 -0
- data/doc/examples/use_prefix.rb +8 -0
- data/doc/examples/use_prefix2.rb +11 -0
- data/doc/index.html +31 -0
- data/doc/insertexamples.rb +9 -0
- data/doc/makemanual +4 -0
- data/doc/makerdoc +5 -0
- data/doc/manual.dbk +622 -0
- data/lib/sqlpostgres/Connection.rb +198 -0
- data/lib/sqlpostgres/Cursor.rb +157 -0
- data/lib/sqlpostgres/Delete.rb +67 -0
- data/lib/sqlpostgres/Exceptions.rb +15 -0
- data/lib/sqlpostgres/Insert.rb +279 -0
- data/lib/sqlpostgres/NullConnection.rb +22 -0
- data/lib/sqlpostgres/PgBit.rb +73 -0
- data/lib/sqlpostgres/PgBox.rb +37 -0
- data/lib/sqlpostgres/PgCidr.rb +21 -0
- data/lib/sqlpostgres/PgCircle.rb +75 -0
- data/lib/sqlpostgres/PgInet.rb +21 -0
- data/lib/sqlpostgres/PgInterval.rb +208 -0
- data/lib/sqlpostgres/PgLineSegment.rb +37 -0
- data/lib/sqlpostgres/PgMacAddr.rb +21 -0
- data/lib/sqlpostgres/PgPath.rb +64 -0
- data/lib/sqlpostgres/PgPoint.rb +65 -0
- data/lib/sqlpostgres/PgPolygon.rb +56 -0
- data/lib/sqlpostgres/PgTime.rb +77 -0
- data/lib/sqlpostgres/PgTimeWithTimeZone.rb +98 -0
- data/lib/sqlpostgres/PgTimestamp.rb +93 -0
- data/lib/sqlpostgres/PgTwoPoints.rb +54 -0
- data/lib/sqlpostgres/PgType.rb +34 -0
- data/lib/sqlpostgres/PgWrapper.rb +41 -0
- data/lib/sqlpostgres/Savepoint.rb +98 -0
- data/lib/sqlpostgres/Select.rb +855 -0
- data/lib/sqlpostgres/Transaction.rb +120 -0
- data/lib/sqlpostgres/Translate.rb +436 -0
- data/lib/sqlpostgres/Update.rb +188 -0
- data/lib/sqlpostgres.rb +67 -0
- data/test/Assert.rb +72 -0
- data/test/Connection.test.rb +246 -0
- data/test/Cursor.test.rb +190 -0
- data/test/Delete.test.rb +68 -0
- data/test/Insert.test.rb +123 -0
- data/test/MockPGconn.rb +62 -0
- data/test/NullConnection.test.rb +32 -0
- data/test/PgBit.test.rb +98 -0
- data/test/PgBox.test.rb +108 -0
- data/test/PgCidr.test.rb +61 -0
- data/test/PgCircle.test.rb +107 -0
- data/test/PgInet.test.rb +61 -0
- data/test/PgInterval.test.rb +180 -0
- data/test/PgLineSegment.test.rb +108 -0
- data/test/PgMacAddr.test.rb +61 -0
- data/test/PgPath.test.rb +106 -0
- data/test/PgPoint.test.rb +100 -0
- data/test/PgPolygon.test.rb +95 -0
- data/test/PgTime.test.rb +120 -0
- data/test/PgTimeWithTimeZone.test.rb +117 -0
- data/test/PgTimestamp.test.rb +134 -0
- data/test/RandomThings.rb +25 -0
- data/test/Savepoint.test.rb +286 -0
- data/test/Select.test.rb +930 -0
- data/test/Test.rb +62 -0
- data/test/TestConfig.rb +21 -0
- data/test/TestSetup.rb +13 -0
- data/test/TestUtil.rb +92 -0
- data/test/Transaction.test.rb +275 -0
- data/test/Translate.test.rb +354 -0
- data/test/Update.test.rb +227 -0
- data/test/roundtrip.test.rb +565 -0
- data/test/test +34 -0
- data/tools/exampleinserter/ExampleInserter.rb +177 -0
- data/tools/rdoc/ChangeLog +796 -0
- data/tools/rdoc/EXAMPLE.rb +48 -0
- data/tools/rdoc/MANIFEST +58 -0
- data/tools/rdoc/Makefile +27 -0
- data/tools/rdoc/NEW_FEATURES +226 -0
- data/tools/rdoc/README +390 -0
- data/tools/rdoc/ToDo +6 -0
- data/tools/rdoc/contrib/Index +6 -0
- data/tools/rdoc/contrib/xslfo/ChangeLog +181 -0
- data/tools/rdoc/contrib/xslfo/README +106 -0
- data/tools/rdoc/contrib/xslfo/TODO +10 -0
- data/tools/rdoc/contrib/xslfo/convert.xsl +151 -0
- data/tools/rdoc/contrib/xslfo/demo/README +21 -0
- data/tools/rdoc/contrib/xslfo/demo/rdocfo +99 -0
- data/tools/rdoc/contrib/xslfo/fcm.xsl +54 -0
- data/tools/rdoc/contrib/xslfo/files.xsl +62 -0
- data/tools/rdoc/contrib/xslfo/labeled-lists.xsl +66 -0
- data/tools/rdoc/contrib/xslfo/lists.xsl +44 -0
- data/tools/rdoc/contrib/xslfo/modules.xsl +152 -0
- data/tools/rdoc/contrib/xslfo/rdoc.xsl +75 -0
- data/tools/rdoc/contrib/xslfo/source.xsl +66 -0
- data/tools/rdoc/contrib/xslfo/styles.xsl +69 -0
- data/tools/rdoc/contrib/xslfo/tables.xsl +67 -0
- data/tools/rdoc/contrib/xslfo/utils.xsl +21 -0
- data/tools/rdoc/debian/changelog +33 -0
- data/tools/rdoc/debian/compat +1 -0
- data/tools/rdoc/debian/control +20 -0
- data/tools/rdoc/debian/copyright +10 -0
- data/tools/rdoc/debian/dirs +2 -0
- data/tools/rdoc/debian/docs +2 -0
- data/tools/rdoc/debian/rdoc.1 +252 -0
- data/tools/rdoc/debian/rdoc.manpages +1 -0
- data/tools/rdoc/debian/rdoc.pod +149 -0
- data/tools/rdoc/debian/rules +9 -0
- data/tools/rdoc/dot/dot.rb +255 -0
- data/tools/rdoc/etc/rdoc.dtd +203 -0
- data/tools/rdoc/install.rb +137 -0
- data/tools/rdoc/markup/install.rb +43 -0
- data/tools/rdoc/markup/sample/sample.rb +42 -0
- data/tools/rdoc/markup/simple_markup/fragments.rb +323 -0
- data/tools/rdoc/markup/simple_markup/inline.rb +348 -0
- data/tools/rdoc/markup/simple_markup/lines.rb +147 -0
- data/tools/rdoc/markup/simple_markup/preprocess.rb +68 -0
- data/tools/rdoc/markup/simple_markup/to_html.rb +281 -0
- data/tools/rdoc/markup/simple_markup.rb +474 -0
- data/tools/rdoc/markup/test/AllTests.rb +2 -0
- data/tools/rdoc/markup/test/TestInline.rb +151 -0
- data/tools/rdoc/markup/test/TestParse.rb +411 -0
- data/tools/rdoc/rdoc/code_objects.rb +536 -0
- data/tools/rdoc/rdoc/diagram.rb +331 -0
- data/tools/rdoc/rdoc/generators/chm_generator.rb +112 -0
- data/tools/rdoc/rdoc/generators/html_generator.rb +1268 -0
- data/tools/rdoc/rdoc/generators/template/chm/chm.rb +86 -0
- data/tools/rdoc/rdoc/generators/template/html/html.rb +705 -0
- data/tools/rdoc/rdoc/generators/template/html/kilmer.rb +377 -0
- data/tools/rdoc/rdoc/generators/template/xml/rdf.rb +110 -0
- data/tools/rdoc/rdoc/generators/template/xml/xml.rb +110 -0
- data/tools/rdoc/rdoc/generators/xml_generator.rb +130 -0
- data/tools/rdoc/rdoc/options.rb +451 -0
- data/tools/rdoc/rdoc/parsers/parse_c.rb +287 -0
- data/tools/rdoc/rdoc/parsers/parse_f95.rb +118 -0
- data/tools/rdoc/rdoc/parsers/parse_rb.rb +2311 -0
- data/tools/rdoc/rdoc/parsers/parse_simple.rb +37 -0
- data/tools/rdoc/rdoc/parsers/parserfactory.rb +75 -0
- data/tools/rdoc/rdoc/rdoc.rb +219 -0
- data/tools/rdoc/rdoc/template.rb +234 -0
- data/tools/rdoc/rdoc/tokenstream.rb +25 -0
- data/tools/rdoc/rdoc.rb +9 -0
- metadata +291 -0
data/test/PgCidr.test.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
$:.unshift(File.dirname(__FILE__))
|
6
|
+
require 'TestSetup'
|
7
|
+
require 'RandomThings'
|
8
|
+
|
9
|
+
class PgCidrTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test
|
15
|
+
ipAndMask = randomString
|
16
|
+
assertEquals(PgCidr.from_sql(ipAndMask), PgCidr.new(ipAndMask))
|
17
|
+
assertEquals(PgCidr.new(ipAndMask).to_s, ipAndMask)
|
18
|
+
assertEquals(PgCidr.new(ipAndMask).to_sql, "cidr '#{ipAndMask}'")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_equality
|
22
|
+
testCases = [
|
23
|
+
["a", "a", true],
|
24
|
+
["a", "b", false],
|
25
|
+
["b", "a", false],
|
26
|
+
]
|
27
|
+
for testCase in testCases
|
28
|
+
assertInfo("For test case #{testCase.inspect}") do
|
29
|
+
argA, argB, equal = *testCase
|
30
|
+
a = PgCidr.new(argA)
|
31
|
+
b = PgCidr.new(argB)
|
32
|
+
assertEquals(a == b, equal)
|
33
|
+
assertEquals(a.eql?(b), equal)
|
34
|
+
assertEquals(a != b, !equal)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_hash
|
40
|
+
count = 0
|
41
|
+
hashes = Hash.new(0)
|
42
|
+
testHash = proc { |*args|
|
43
|
+
assertEquals(PgCidr.new(*args).hash, PgCidr.new(*args).hash)
|
44
|
+
hashes[PgCidr.new(*args).hash] += 1
|
45
|
+
count += 1
|
46
|
+
}
|
47
|
+
for i in (0...10)
|
48
|
+
testHash.call(i.to_s)
|
49
|
+
end
|
50
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
PgCidrTest.new.run if $0 == __FILE__
|
56
|
+
|
57
|
+
# Local Variables:
|
58
|
+
# tab-width: 2
|
59
|
+
# ruby-indent-level: 2
|
60
|
+
# indent-tabs-mode: nil
|
61
|
+
# End:
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
$:.unshift(File.dirname(__FILE__))
|
6
|
+
require 'TestSetup'
|
7
|
+
require 'RandomThings'
|
8
|
+
|
9
|
+
class PgCircleTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test_ctor_defaults
|
15
|
+
assertEquals(PgCircle.new, PgCircle.new(0, 0, 0))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ctor_and_accessors
|
19
|
+
x = randomFloat
|
20
|
+
y = randomFloat
|
21
|
+
radius = randomFloat
|
22
|
+
circle = PgCircle.new(x, y, radius)
|
23
|
+
assertEquals(circle.center, PgPoint.new(x, y))
|
24
|
+
assertEquals(circle.radius, radius)
|
25
|
+
circle = PgCircle.new(PgPoint.new(x, y), radius)
|
26
|
+
assertEquals(circle.center, PgPoint.new(x, y))
|
27
|
+
assertEquals(circle.radius, radius)
|
28
|
+
assertException(ArgumentError, "Incorrect number of arguments: 1") do
|
29
|
+
PgCircle.new(1)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_from_sql
|
34
|
+
testCases = [
|
35
|
+
["<(1,2),3>", [1, 2, 3]],
|
36
|
+
["<(1,2.3),1e+30>", [1, 2.3, 1e30]],
|
37
|
+
]
|
38
|
+
for testCase in testCases
|
39
|
+
sql, args = *testCase
|
40
|
+
assertInfo("For sql #{sql.inspect}") do
|
41
|
+
assertEquals(PgCircle.from_sql(sql), PgCircle.new(*args))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
assertException(ArgumentError, 'Invalid circle: "foo"') do
|
45
|
+
PgCircle.from_sql("foo")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_equality
|
50
|
+
fields = ["center", "radius"]
|
51
|
+
for field in fields
|
52
|
+
assertInfo("For field #{field}") do
|
53
|
+
circle1 = PgCircle.new
|
54
|
+
circle2 = PgCircle.new
|
55
|
+
assertEquals(circle1.eql?(circle2), true)
|
56
|
+
assertEquals(circle1 == circle2, true)
|
57
|
+
assertEquals(circle1 != circle2, false)
|
58
|
+
args = fields.collect do |f|
|
59
|
+
if f == field then 1 else 0 end
|
60
|
+
end
|
61
|
+
circle2 = PgCircle.new(*args)
|
62
|
+
assertEquals(circle1 == circle2, false)
|
63
|
+
assertEquals(circle1 != circle2, true)
|
64
|
+
assertEquals(circle1.eql?(Object.new), false)
|
65
|
+
assertEquals(circle1 == Object.new, false)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_hash
|
71
|
+
count = 0
|
72
|
+
hashes = Hash.new(0)
|
73
|
+
testHash = proc { |*args|
|
74
|
+
assertEquals(PgCircle.new(*args).hash, PgCircle.new(*args).hash)
|
75
|
+
hashes[PgCircle.new(*args).hash] += 1
|
76
|
+
count += 1
|
77
|
+
}
|
78
|
+
for i in (0...10)
|
79
|
+
testHash.call(i, 0, 0)
|
80
|
+
testHash.call(0, i, 0)
|
81
|
+
testHash.call(0, 0, i)
|
82
|
+
end
|
83
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_to_s
|
87
|
+
testCases = [
|
88
|
+
[[0, 0, 0], "<(0, 0), 0>"],
|
89
|
+
[[1.2, -2, 1e10], "<(1.2, -2), 1e+10>"],
|
90
|
+
]
|
91
|
+
for testCase in testCases
|
92
|
+
args, expected = *testCase
|
93
|
+
circle = PgCircle.new(*args)
|
94
|
+
assertEquals(circle.to_s, expected)
|
95
|
+
assertEquals(circle.to_sql, "circle '#{expected}'")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
PgCircleTest.new.run if $0 == __FILE__
|
102
|
+
|
103
|
+
# Local Variables:
|
104
|
+
# tab-width: 2
|
105
|
+
# ruby-indent-level: 2
|
106
|
+
# indent-tabs-mode: nil
|
107
|
+
# End:
|
data/test/PgInet.test.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
$:.unshift(File.dirname(__FILE__))
|
6
|
+
require 'TestSetup'
|
7
|
+
require 'RandomThings'
|
8
|
+
|
9
|
+
class PgInetTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test
|
15
|
+
ipAndMask = randomString
|
16
|
+
assertEquals(PgInet.new(ipAndMask), PgInet.from_sql(ipAndMask))
|
17
|
+
assertEquals(PgInet.new(ipAndMask).to_s, ipAndMask)
|
18
|
+
assertEquals(PgInet.new(ipAndMask).to_sql, "inet '#{ipAndMask}'")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_equality
|
22
|
+
testCases = [
|
23
|
+
["a", "a", true],
|
24
|
+
["a", "b", false],
|
25
|
+
["b", "a", false],
|
26
|
+
]
|
27
|
+
for testCase in testCases
|
28
|
+
assertInfo("For test case #{testCase.inspect}") do
|
29
|
+
argA, argB, equal = *testCase
|
30
|
+
a = PgInet.new(argA)
|
31
|
+
b = PgInet.new(argB)
|
32
|
+
assertEquals(a == b, equal)
|
33
|
+
assertEquals(a.eql?(b), equal)
|
34
|
+
assertEquals(a != b, !equal)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_hash
|
40
|
+
count = 0
|
41
|
+
hashes = Hash.new(0)
|
42
|
+
testHash = proc { |*args|
|
43
|
+
assertEquals(PgInet.new(*args).hash, PgInet.new(*args).hash)
|
44
|
+
hashes[PgInet.new(*args).hash] += 1
|
45
|
+
count += 1
|
46
|
+
}
|
47
|
+
for i in (0...10)
|
48
|
+
testHash.call(i.to_s)
|
49
|
+
end
|
50
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
PgInetTest.new.run if $0 == __FILE__
|
56
|
+
|
57
|
+
# Local Variables:
|
58
|
+
# tab-width: 2
|
59
|
+
# ruby-indent-level: 2
|
60
|
+
# indent-tabs-mode: nil
|
61
|
+
# End:
|
@@ -0,0 +1,180 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
$:.unshift(File.dirname(__FILE__))
|
6
|
+
require 'TestSetup'
|
7
|
+
require 'RandomThings'
|
8
|
+
|
9
|
+
class PgIntervalTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
FIELDS = [
|
15
|
+
"millennia", "centuries", "decades",
|
16
|
+
"years", "months", "days", "weeks",
|
17
|
+
"hours", "minutes", "seconds",
|
18
|
+
"ago"
|
19
|
+
]
|
20
|
+
|
21
|
+
def test_ctor_and_accessors
|
22
|
+
for ago in [false, true]
|
23
|
+
args = Hash[*FIELDS.collect do |field|
|
24
|
+
[field, randomInteger]
|
25
|
+
end.flatten]
|
26
|
+
args['ago'] = ago
|
27
|
+
interval = PgInterval.new(args)
|
28
|
+
assertInfo("For ago=#{ago}") do
|
29
|
+
for field, value in args
|
30
|
+
assertInfo("For field=#{field}") do
|
31
|
+
assertEquals(interval.send(field), value)
|
32
|
+
end
|
33
|
+
assertEquals(interval.ago, ago)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_ctor_invlaid_args
|
40
|
+
assertException(ArgumentError, '{"foo"=>1}') do
|
41
|
+
PgInterval.new('foo'=>1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_ctor_defaults
|
46
|
+
args = Hash[*FIELDS.collect do |field|
|
47
|
+
[field, field == 'ago' ? false : 0]
|
48
|
+
end.flatten]
|
49
|
+
assertEquals(PgInterval.new, PgInterval.new(args))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_equality
|
53
|
+
for field in FIELDS
|
54
|
+
assertInfo("For field #{field}") do
|
55
|
+
time1 = PgInterval.new
|
56
|
+
time2 = PgInterval.new
|
57
|
+
assertEquals(time1.eql?(time2), true)
|
58
|
+
assertEquals(time1 == time2, true)
|
59
|
+
assertEquals(time1 != time2, false)
|
60
|
+
time2 = PgInterval.new(field=>1)
|
61
|
+
assertEquals(time1 == time2, false)
|
62
|
+
assertEquals(time1 != time2, true)
|
63
|
+
assertEquals(time1.eql?(Object.new), false)
|
64
|
+
assertEquals(time1 == Object.new, false)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_hash
|
70
|
+
count = 0
|
71
|
+
hashes = Hash.new(0)
|
72
|
+
for i in (0...9)
|
73
|
+
for field in FIELDS
|
74
|
+
args = {field=>i}
|
75
|
+
assertEquals(PgInterval.new(args).hash, PgInterval.new(args).hash)
|
76
|
+
hashes[PgInterval.new(args).hash] += 1
|
77
|
+
count += 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_to_s
|
84
|
+
testCases = [
|
85
|
+
[{}, "0 days"],
|
86
|
+
[{"seconds"=>2}, "00:00:02"],
|
87
|
+
[{"minutes"=>2}, "00:02"],
|
88
|
+
[{"hours"=>2}, "02:00"],
|
89
|
+
[{"hours"=>1, "minutes"=>2, "seconds"=>3}, "01:02:03"],
|
90
|
+
[{"days"=>2}, "2 days"],
|
91
|
+
[{"weeks"=>2}, "2 weeks"],
|
92
|
+
[{"months"=>2}, "2 months"],
|
93
|
+
[{"years"=>2}, "2 years"],
|
94
|
+
[{"decades"=>2}, "2 decades"],
|
95
|
+
[{"centuries"=>2}, "2 centuries"],
|
96
|
+
[{"millennia"=>2}, "2 millennia"],
|
97
|
+
[{"seconds"=>1}, "00:00:01"],
|
98
|
+
[{"minutes"=>1}, "00:01"],
|
99
|
+
[{"hours"=>1}, "01:00"],
|
100
|
+
[{"days"=>1}, "1 day"],
|
101
|
+
[{"weeks"=>1}, "1 week"],
|
102
|
+
[{"months"=>1}, "1 month"],
|
103
|
+
[{"years"=>1}, "1 year"],
|
104
|
+
[{"decades"=>1}, "1 decade"],
|
105
|
+
[{"centuries"=>1}, "1 century"],
|
106
|
+
[{"millennia"=>1}, "1 millennium"],
|
107
|
+
[{"years"=>1, "days"=>2}, "1 year 2 days"],
|
108
|
+
[ {
|
109
|
+
'centuries'=>2, 'decades'=>3, 'years'=>4, 'months'=>5,
|
110
|
+
'weeks'=>6, 'days'=>7, 'hours'=>8, 'minutes'=>9, 'seconds'=>10
|
111
|
+
},
|
112
|
+
"2 centuries 3 decades 4 years 5 months 6 weeks 7 days 08:09:10"
|
113
|
+
],
|
114
|
+
[{"days"=>1, "ago"=>false}, "1 day"],
|
115
|
+
[{"days"=>1, "ago"=>true}, "1 day ago"],
|
116
|
+
[{"days"=>-1}, "-1 days"],
|
117
|
+
[{"days"=>-1, "ago"=>true}, "-1 days ago"],
|
118
|
+
[{"ago"=>true}, "0 days ago"],
|
119
|
+
[{"seconds"=>1.123456}, "00:00:01.123456"],
|
120
|
+
[{"seconds"=>59.999999}, "00:00:59.999999"],
|
121
|
+
[{"hours"=>1, "minutes"=>1, "seconds"=>1}, "01:01:01"],
|
122
|
+
[{"hours"=>-1, "minutes"=>-1, "seconds"=>-1}, "-01:01:01"],
|
123
|
+
[
|
124
|
+
{"hours"=>1, "minutes"=>-1, "seconds"=>1},
|
125
|
+
"1 hour -1 minutes 1 second"
|
126
|
+
],
|
127
|
+
]
|
128
|
+
for args, expected in testCases
|
129
|
+
assertInfo("For args=#{args.inspect}") do
|
130
|
+
assertEquals(PgInterval.new(args).to_s, expected)
|
131
|
+
assertEquals(PgInterval.new(args).to_sql, "interval '#{expected}'")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_from_sql
|
137
|
+
testCases = [
|
138
|
+
["00:00", PgInterval.new],
|
139
|
+
["01:02", PgInterval.new('hours'=>1, 'minutes'=>2)],
|
140
|
+
["01:02:03", PgInterval.new('hours'=>1, 'minutes'=>2, 'seconds'=>3)],
|
141
|
+
["-01:02:03", PgInterval.new('hours'=>-1, 'minutes'=>-2, 'seconds'=>-3)],
|
142
|
+
["1 day", PgInterval.new('days'=>1)],
|
143
|
+
["2 days", PgInterval.new('days'=>2)],
|
144
|
+
["2 days 03:00", PgInterval.new('days'=>2, 'hours'=>3)],
|
145
|
+
["1 mon", PgInterval.new('months'=>1)],
|
146
|
+
["2 mons", PgInterval.new('months'=>2)],
|
147
|
+
["00:00:01.100000", PgInterval.new('seconds'=>1.1)],
|
148
|
+
]
|
149
|
+
for sql, interval in testCases
|
150
|
+
assertInfo("For sql=#{sql.inspect}") do
|
151
|
+
assertEquals(PgInterval.from_sql(sql), interval)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_from_sql_exceptions
|
157
|
+
testCases = [
|
158
|
+
"",
|
159
|
+
"1 foo",
|
160
|
+
"foo",
|
161
|
+
]
|
162
|
+
for sql in testCases
|
163
|
+
assertInfo("For sql=#{sql.inspect}") do
|
164
|
+
message = "Syntax error in interval: #{sql.inspect}"
|
165
|
+
assertException(ArgumentError, message) do
|
166
|
+
PgInterval.from_sql(sql)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
PgIntervalTest.new.run if $0 == __FILE__
|
175
|
+
|
176
|
+
# Local Variables:
|
177
|
+
# tab-width: 2
|
178
|
+
# ruby-indent-level: 2
|
179
|
+
# indent-tabs-mode: nil
|
180
|
+
# End:
|
@@ -0,0 +1,108 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
$:.unshift(File.dirname(__FILE__))
|
6
|
+
require 'TestSetup'
|
7
|
+
require 'RandomThings'
|
8
|
+
|
9
|
+
class PgLineSegmentTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test_ctor_defaults
|
15
|
+
assertEquals(PgLineSegment.new, PgLineSegment.new(PgPoint.new, PgPoint.new))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ctor_and_accessors
|
19
|
+
p1 = randomWhatever
|
20
|
+
p2 = randomWhatever
|
21
|
+
line = PgLineSegment.new(p1, p2)
|
22
|
+
assertEquals(line.p1, p1)
|
23
|
+
assertEquals(line.p2, p2)
|
24
|
+
|
25
|
+
x1 = randomFloat
|
26
|
+
x2 = randomFloat
|
27
|
+
y1 = randomFloat
|
28
|
+
y2 = randomFloat
|
29
|
+
line = PgLineSegment.new(x1, y1, x2, y2)
|
30
|
+
assertEquals(line.p1, PgPoint.new(x1, y1))
|
31
|
+
assertEquals(line.p2, PgPoint.new(x2, y2))
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_from_sql
|
35
|
+
testCases = [
|
36
|
+
["[(0,0),(0,0)]", [0, 0, 0, 0]],
|
37
|
+
["[(1.2,-3),(1e+20,-1e20)]", [1.2, -3, 1e+20, -1e20]],
|
38
|
+
]
|
39
|
+
for testCase in testCases
|
40
|
+
sql, args = *testCase
|
41
|
+
assertInfo("For sql #{sql.inspect}") do
|
42
|
+
assertEquals(PgLineSegment.from_sql(sql), PgLineSegment.new(*args))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
assertException(ArgumentError, 'Invalid lseg: "foo"') do
|
46
|
+
PgLineSegment.from_sql("foo")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_equality
|
51
|
+
fields = ["p1", "p2"]
|
52
|
+
for field in fields
|
53
|
+
assertInfo("For field #{field}") do
|
54
|
+
line1 = PgLineSegment.new
|
55
|
+
line2 = PgLineSegment.new
|
56
|
+
assertEquals(line1.eql?(line2), true)
|
57
|
+
assertEquals(line1 == line2, true)
|
58
|
+
assertEquals(line1 != line2, false)
|
59
|
+
args = fields.collect do |f|
|
60
|
+
if f == field then 1 else 0 end
|
61
|
+
end
|
62
|
+
line2 = PgLineSegment.new(*args)
|
63
|
+
assertEquals(line1 == line2, false)
|
64
|
+
assertEquals(line1 != line2, true)
|
65
|
+
assertEquals(line1.eql?(Object.new), false)
|
66
|
+
assertEquals(line1 == Object.new, false)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_hash
|
72
|
+
count = 0
|
73
|
+
hashes = Hash.new(0)
|
74
|
+
testHash = proc { |*args|
|
75
|
+
assertEquals(PgLineSegment.new(*args).hash, PgLineSegment.new(*args).hash)
|
76
|
+
hashes[PgLineSegment.new(*args).hash] += 1
|
77
|
+
count += 1
|
78
|
+
}
|
79
|
+
for i in (0...10)
|
80
|
+
testHash.call(i, 0, 0, 0)
|
81
|
+
testHash.call(0, i, 0, 0)
|
82
|
+
testHash.call(0, 0, i, 0)
|
83
|
+
testHash.call(0, 0, 0, i)
|
84
|
+
end
|
85
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_to_s
|
89
|
+
testCases = [
|
90
|
+
[[0, 0, 0, 0], "((0, 0), (0, 0))"],
|
91
|
+
[[1.2, -2, 1e10, -1e10], "((1.2, -2), (1e+10, -1e+10))"],
|
92
|
+
]
|
93
|
+
for testCase in testCases
|
94
|
+
args, expected = *testCase
|
95
|
+
assertEquals(PgLineSegment.new(*args).to_s, expected)
|
96
|
+
assertEquals(PgLineSegment.new(*args).to_sql, "lseg '#{expected}'")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
PgLineSegmentTest.new.run if $0 == __FILE__
|
103
|
+
|
104
|
+
# Local Variables:
|
105
|
+
# tab-width: 2
|
106
|
+
# ruby-indent-level: 2
|
107
|
+
# indent-tabs-mode: nil
|
108
|
+
# End:
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
$:.unshift(File.dirname(__FILE__))
|
6
|
+
require 'TestSetup'
|
7
|
+
require 'RandomThings'
|
8
|
+
|
9
|
+
class PgMacAddrTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test
|
15
|
+
ipAndMask = randomString
|
16
|
+
assertEquals(PgMacAddr.from_sql(ipAndMask), PgMacAddr.new(ipAndMask))
|
17
|
+
assertEquals(PgMacAddr.new(ipAndMask).to_s, ipAndMask)
|
18
|
+
assertEquals(PgMacAddr.new(ipAndMask).to_sql, "macaddr '#{ipAndMask}'")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_equality
|
22
|
+
testCases = [
|
23
|
+
["a", "a", true],
|
24
|
+
["a", "b", false],
|
25
|
+
["b", "a", false],
|
26
|
+
]
|
27
|
+
for testCase in testCases
|
28
|
+
assertInfo("For test case #{testCase.inspect}") do
|
29
|
+
argA, argB, equal = *testCase
|
30
|
+
a = PgMacAddr.new(argA)
|
31
|
+
b = PgMacAddr.new(argB)
|
32
|
+
assertEquals(a == b, equal)
|
33
|
+
assertEquals(a.eql?(b), equal)
|
34
|
+
assertEquals(a != b, !equal)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_hash
|
40
|
+
count = 0
|
41
|
+
hashes = Hash.new(0)
|
42
|
+
testHash = proc { |*args|
|
43
|
+
assertEquals(PgMacAddr.new(*args).hash, PgMacAddr.new(*args).hash)
|
44
|
+
hashes[PgMacAddr.new(*args).hash] += 1
|
45
|
+
count += 1
|
46
|
+
}
|
47
|
+
for i in (0...10)
|
48
|
+
testHash.call(i.to_s)
|
49
|
+
end
|
50
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
PgMacAddrTest.new.run if $0 == __FILE__
|
56
|
+
|
57
|
+
# Local Variables:
|
58
|
+
# tab-width: 2
|
59
|
+
# ruby-indent-level: 2
|
60
|
+
# indent-tabs-mode: nil
|
61
|
+
# End:
|
data/test/PgPath.test.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
$:.unshift(File.dirname(__FILE__))
|
6
|
+
require 'TestSetup'
|
7
|
+
require 'RandomThings'
|
8
|
+
|
9
|
+
class PgPathTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test_ctor_defaults
|
15
|
+
path = PgPath.new
|
16
|
+
assertEquals(path.closed, true)
|
17
|
+
assertEquals(path.points, [])
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_ctor
|
21
|
+
testCases = [
|
22
|
+
[false, []],
|
23
|
+
[true, []],
|
24
|
+
[false, [PgPoint.new(1, 1)]],
|
25
|
+
[false, [PgPoint.new(1, 1), PgPoint.new(2, 2)]],
|
26
|
+
]
|
27
|
+
for testCase in testCases
|
28
|
+
assertInfo("For test case #{testCase.inspect}") do
|
29
|
+
closed, points = *testCase
|
30
|
+
path = PgPath.new(closed, *points)
|
31
|
+
assertEquals(path.points, points)
|
32
|
+
assertEquals(path.closed, closed)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_from_sql
|
38
|
+
testCases = [
|
39
|
+
["[(0,0)]", [false, PgPoint.new(0, 0)]],
|
40
|
+
["((1,2),(3,4))", [true, PgPoint.new(1, 2), PgPoint.new(3, 4)]],
|
41
|
+
]
|
42
|
+
for sql, args in testCases
|
43
|
+
assertInfo("For sql #{sql.inspect}") do
|
44
|
+
assertEquals(PgPath.from_sql(sql), PgPath.new(*args))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
assertException(ArgumentError, 'Invalid path: "foo"') do
|
48
|
+
PgPath.from_sql("foo")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_to_s
|
53
|
+
testCases = [
|
54
|
+
[[false, PgPoint.new(1, 1)], "[(1, 1)]"],
|
55
|
+
[[true, PgPoint.new(1, 1), PgPoint.new(2, 2)], "((1, 1), (2, 2))"],
|
56
|
+
]
|
57
|
+
for args, expected in testCases
|
58
|
+
assertInfo("For args #{args.inspect}") do
|
59
|
+
assertEquals(PgPath.new(*args).to_s, expected)
|
60
|
+
assertEquals(PgPath.new(*args).to_sql, "path '#{expected}'")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_equality
|
66
|
+
path1 = PgPath.new(false)
|
67
|
+
path2 = PgPath.new(false)
|
68
|
+
assertEquals(path1.eql?(path2), true)
|
69
|
+
assertEquals(path1 == path2, true)
|
70
|
+
assertEquals(path1 != path2, false)
|
71
|
+
for path2 in [PgPath.new(true), PgPath.new(false, PgPoint.new(1, 2))]
|
72
|
+
assertEquals(path1 == path2, false)
|
73
|
+
assertEquals(path1 != path2, true)
|
74
|
+
assertEquals(path1.eql?(Object.new), false)
|
75
|
+
assertEquals(path1 == Object.new, false)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_hash
|
80
|
+
count = 0
|
81
|
+
hashes = Hash.new(0)
|
82
|
+
testHash = proc { |*args|
|
83
|
+
assertEquals(PgPath.new(*args).hash, PgPath.new(*args).hash)
|
84
|
+
hashes[PgPath.new(*args).hash] += 1
|
85
|
+
count += 1
|
86
|
+
}
|
87
|
+
for i in (1...10)
|
88
|
+
testHash.call(false, PgPoint.new(0, 0), PgPoint.new(0, 0))
|
89
|
+
testHash.call(true, PgPoint.new(0, 0), PgPoint.new(0, 0))
|
90
|
+
testHash.call(false, PgPoint.new(i, 0), PgPoint.new(0, 0))
|
91
|
+
testHash.call(false, PgPoint.new(0, i), PgPoint.new(0, 0))
|
92
|
+
testHash.call(false, PgPoint.new(0, 0), PgPoint.new(i, 0))
|
93
|
+
testHash.call(false, PgPoint.new(0, 0), PgPoint.new(0, i))
|
94
|
+
end
|
95
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
PgPathTest.new.run if $0 == __FILE__
|
101
|
+
|
102
|
+
# Local Variables:
|
103
|
+
# tab-width: 2
|
104
|
+
# ruby-indent-level: 2
|
105
|
+
# indent-tabs-mode: nil
|
106
|
+
# End:
|