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
@@ -0,0 +1,100 @@
|
|
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 PgPointTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test_ctor_defaults
|
15
|
+
assertEquals(PgPoint.new, PgPoint.new(0, 0))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ctor_and_accessors
|
19
|
+
x = randomFloat
|
20
|
+
y = randomFloat
|
21
|
+
point = PgPoint.new(x, y)
|
22
|
+
assertEquals(point.x, x)
|
23
|
+
assertEquals(point.y, y)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_from_sql
|
27
|
+
testCases = [
|
28
|
+
["(0,0)", [0, 0]],
|
29
|
+
["(1.2,-3)", [1.2, -3]],
|
30
|
+
["(1e+20,-1e+20)", [1e20, -1e20]],
|
31
|
+
]
|
32
|
+
for testCase in testCases
|
33
|
+
sql, args = *testCase
|
34
|
+
assertInfo("For sql #{sql.inspect}") do
|
35
|
+
assertEquals(PgPoint.from_sql(sql), PgPoint.new(*args))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
assertException(ArgumentError, 'Invalid point: "foo"') do
|
39
|
+
PgPoint.from_sql("foo")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_equality
|
44
|
+
fields = ["x", "y"]
|
45
|
+
for field in fields
|
46
|
+
assertInfo("For field #{field}") do
|
47
|
+
point1 = PgPoint.new
|
48
|
+
point2 = PgPoint.new
|
49
|
+
assertEquals(point1.eql?(point2), true)
|
50
|
+
assertEquals(point1 == point2, true)
|
51
|
+
assertEquals(point1 != point2, false)
|
52
|
+
args = fields.collect do |f|
|
53
|
+
if f == field then 1 else 0 end
|
54
|
+
end
|
55
|
+
point2 = PgPoint.new(*args)
|
56
|
+
assertEquals(point1 == point2, false)
|
57
|
+
assertEquals(point1 != point2, true)
|
58
|
+
assertEquals(point1.eql?(Object.new), false)
|
59
|
+
assertEquals(point1 == Object.new, false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_hash
|
65
|
+
count = 0
|
66
|
+
hashes = Hash.new(0)
|
67
|
+
testHash = proc { |*args|
|
68
|
+
assertEquals(PgPoint.new(*args).hash, PgPoint.new(*args).hash)
|
69
|
+
hashes[PgPoint.new(*args).hash] += 1
|
70
|
+
count += 1
|
71
|
+
}
|
72
|
+
for i in (0...10)
|
73
|
+
testHash.call(i, 0)
|
74
|
+
testHash.call(0, i)
|
75
|
+
end
|
76
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_to_s
|
80
|
+
testCases = [
|
81
|
+
[[0, 0], "(0, 0)"],
|
82
|
+
[[1.2, -2], "(1.2, -2)"],
|
83
|
+
[[1e10, -1e10], "(1e+10, -1e+10)"],
|
84
|
+
]
|
85
|
+
for testCase in testCases
|
86
|
+
args, expected = *testCase
|
87
|
+
assertEquals(PgPoint.new(*args).to_s, expected)
|
88
|
+
assertEquals(PgPoint.new(*args).to_sql, "point '#{expected}'")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
PgPointTest.new.run if $0 == __FILE__
|
95
|
+
|
96
|
+
# Local Variables:
|
97
|
+
# tab-width: 2
|
98
|
+
# ruby-indent-level: 2
|
99
|
+
# indent-tabs-mode: nil
|
100
|
+
# End:
|
@@ -0,0 +1,95 @@
|
|
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 PgPolygonTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test_ctor_defaults
|
15
|
+
assertEquals(PgPolygon.new.points, [])
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ctor
|
19
|
+
testCases = [
|
20
|
+
[],
|
21
|
+
[PgPoint.new(1, 1)],
|
22
|
+
[PgPoint.new(1, 1), PgPoint.new(2, 2)],
|
23
|
+
]
|
24
|
+
for points in testCases
|
25
|
+
assertEquals(PgPolygon.new(*points).points, points)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_from_sql
|
30
|
+
testCases = [
|
31
|
+
["((0,0))", [PgPoint.new(0, 0)]],
|
32
|
+
["((1,2),(3,4))", [PgPoint.new(1, 2), PgPoint.new(3, 4)]],
|
33
|
+
]
|
34
|
+
for sql, args in testCases
|
35
|
+
assertInfo("For sql #{sql.inspect}") do
|
36
|
+
assertEquals(PgPolygon.from_sql(sql), PgPolygon.new(*args))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
assertException(ArgumentError, 'Invalid polygon: "foo"') do
|
40
|
+
PgPolygon.from_sql("foo")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_to_s
|
45
|
+
testCases = [
|
46
|
+
[[PgPoint.new(1, 1)], "((1, 1))"],
|
47
|
+
[[PgPoint.new(1, 1), PgPoint.new(2, 2)], "((1, 1), (2, 2))"],
|
48
|
+
]
|
49
|
+
for args, expected in testCases
|
50
|
+
assertInfo("For args #{args.inspect}") do
|
51
|
+
assertEquals(PgPolygon.new(*args).to_s, expected)
|
52
|
+
assertEquals(PgPolygon.new(*args).to_sql, "polygon '#{expected}'")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_equality
|
58
|
+
polygon1 = PgPolygon.new(false)
|
59
|
+
polygon2 = PgPolygon.new(false)
|
60
|
+
assertEquals(polygon1.eql?(polygon2), true)
|
61
|
+
assertEquals(polygon1 == polygon2, true)
|
62
|
+
assertEquals(polygon1 != polygon2, false)
|
63
|
+
polygon2 = PgPolygon.new(PgPoint.new(1, 2))
|
64
|
+
assertEquals(polygon1 == polygon2, false)
|
65
|
+
assertEquals(polygon1 != polygon2, true)
|
66
|
+
assertEquals(polygon1.eql?(Object.new), false)
|
67
|
+
assertEquals(polygon1 == Object.new, false)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_hash
|
71
|
+
count = 0
|
72
|
+
hashes = Hash.new(0)
|
73
|
+
testHash = proc { |*args|
|
74
|
+
assertEquals(PgPolygon.new(*args).hash, PgPolygon.new(*args).hash)
|
75
|
+
hashes[PgPolygon.new(*args).hash] += 1
|
76
|
+
count += 1
|
77
|
+
}
|
78
|
+
for i in (0...10)
|
79
|
+
testHash.call(PgPoint.new(i, 0), PgPoint.new(0, 0))
|
80
|
+
testHash.call(PgPoint.new(0, i), PgPoint.new(0, 0))
|
81
|
+
testHash.call(PgPoint.new(0, 0), PgPoint.new(i, 0))
|
82
|
+
testHash.call(PgPoint.new(0, 0), PgPoint.new(0, i))
|
83
|
+
end
|
84
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
PgPolygonTest.new.run if $0 == __FILE__
|
90
|
+
|
91
|
+
# Local Variables:
|
92
|
+
# tab-width: 2
|
93
|
+
# ruby-indent-level: 2
|
94
|
+
# indent-tabs-mode: nil
|
95
|
+
# End:
|
data/test/PgTime.test.rb
ADDED
@@ -0,0 +1,120 @@
|
|
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 PgTimeTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test_ctor_defaults
|
15
|
+
assertEquals(PgTime.new, PgTime.new(0, 0, 0))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_ctor_and_accessors
|
19
|
+
hour = randomInteger
|
20
|
+
minute = randomInteger
|
21
|
+
second = randomInteger
|
22
|
+
time = PgTime.new(hour, minute, second)
|
23
|
+
assertEquals(time.hour, hour)
|
24
|
+
assertEquals(time.minute, minute)
|
25
|
+
assertEquals(time.second, second)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_from_sql
|
29
|
+
testCases = [
|
30
|
+
[0, 0, 0],
|
31
|
+
[23, 59, 59],
|
32
|
+
]
|
33
|
+
for testCase in testCases
|
34
|
+
sql = "%02d:%02d:%02d" % testCase
|
35
|
+
assertEquals(PgTime.from_sql(sql), PgTime.new(*testCase))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_equality
|
40
|
+
fields = ["hour", "minute", "second"]
|
41
|
+
for field in fields
|
42
|
+
assertInfo("For field #{field}") do
|
43
|
+
time1 = PgTime.new
|
44
|
+
time2 = PgTime.new
|
45
|
+
assertEquals(time1.eql?(time2), true)
|
46
|
+
assertEquals(time1 == time2, true)
|
47
|
+
assertEquals(time1 != time2, false)
|
48
|
+
args = fields.collect do |f|
|
49
|
+
if f == field then 1 else 0 end
|
50
|
+
end
|
51
|
+
time2 = PgTime.new(*args)
|
52
|
+
assertEquals(time1 == time2, false)
|
53
|
+
assertEquals(time1 != time2, true)
|
54
|
+
assertEquals(time1.eql?(Object.new), false)
|
55
|
+
assertEquals(time1 == Object.new, false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_hash
|
61
|
+
count = 0
|
62
|
+
hashes = Hash.new(0)
|
63
|
+
testHash = proc { |*args|
|
64
|
+
assertEquals(PgTime.new(*args).hash, PgTime.new(*args).hash)
|
65
|
+
hashes[PgTime.new(*args).hash] += 1
|
66
|
+
count += 1
|
67
|
+
}
|
68
|
+
for i in (0...10)
|
69
|
+
testHash.call(i, 0, 0)
|
70
|
+
testHash.call(0, i, 0)
|
71
|
+
testHash.call(0, 0, i)
|
72
|
+
end
|
73
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_to_s
|
77
|
+
testCases = [
|
78
|
+
[[0, 0, 0], "00:00:00"],
|
79
|
+
[[23, 59, 59], "23:59:59"],
|
80
|
+
]
|
81
|
+
for testCase in testCases
|
82
|
+
args, expected = *testCase
|
83
|
+
assertEquals(PgTime.new(*args).to_s, expected)
|
84
|
+
assertEquals(PgTime.new(*args).to_sql, "time '#{expected}'")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_to_local_time
|
89
|
+
testCases = [
|
90
|
+
[0, 0, 0],
|
91
|
+
[12, 13, 14],
|
92
|
+
[23, 59, 59],
|
93
|
+
]
|
94
|
+
for testCase in testCases
|
95
|
+
time = Time.local(1970, 1, 1, *testCase)
|
96
|
+
assertEquals(PgTime.new(*testCase).to_local_time, time)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_to_utc_time
|
101
|
+
testCases = [
|
102
|
+
[0, 0, 0],
|
103
|
+
[12, 13, 14],
|
104
|
+
[23, 59, 59],
|
105
|
+
]
|
106
|
+
for testCase in testCases
|
107
|
+
time = Time.utc(1970, 1, 1, *testCase)
|
108
|
+
assertEquals(PgTime.new(*testCase).to_utc_time, time)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
PgTimeTest.new.run if $0 == __FILE__
|
115
|
+
|
116
|
+
# Local Variables:
|
117
|
+
# tab-width: 2
|
118
|
+
# ruby-indent-level: 2
|
119
|
+
# indent-tabs-mode: nil
|
120
|
+
# End:
|
@@ -0,0 +1,117 @@
|
|
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 PgTimeWithTimeZoneTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test_ctor_defaults
|
15
|
+
assertEquals(PgTimeWithTimeZone.new,
|
16
|
+
PgTimeWithTimeZone.new(0, 0, 0, 0, 0))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_ctor_and_accessors
|
20
|
+
hour = randomInteger
|
21
|
+
minute = randomInteger
|
22
|
+
second = randomInteger
|
23
|
+
zone_hours = randomInteger
|
24
|
+
zone_minutes = randomInteger
|
25
|
+
time = PgTimeWithTimeZone.new(hour, minute, second,
|
26
|
+
zone_hours, zone_minutes)
|
27
|
+
assertEquals(time.hour, hour)
|
28
|
+
assertEquals(time.minute, minute)
|
29
|
+
assertEquals(time.second, second)
|
30
|
+
assertEquals(time.zone_hours, zone_hours)
|
31
|
+
assertEquals(time.zone_minutes, zone_minutes)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_from_sql
|
35
|
+
testCases = [
|
36
|
+
["12:00:00+00:30", [12, 0, 0, 0, 30]],
|
37
|
+
["00:00:00+08", [0, 0, 0, 8, 0]],
|
38
|
+
["00:00:00+08:30", [0, 0, 0, 8, 30]],
|
39
|
+
["23:59:59-08", [23, 59, 59, -8, 0]],
|
40
|
+
]
|
41
|
+
for testCase in testCases
|
42
|
+
sql, args = *testCase
|
43
|
+
assertInfo("For sql #{sql.inspect}") do
|
44
|
+
assertEquals(PgTimeWithTimeZone.from_sql(sql),
|
45
|
+
PgTimeWithTimeZone.new(*args))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
assertException(ArgumentError, 'Invalid time with time zone: "foo"') do
|
49
|
+
PgTimeWithTimeZone.from_sql("foo")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_equality
|
54
|
+
fields = ["hour", "minute", "second", "zone_hours", "zone_minutes"]
|
55
|
+
for field in fields
|
56
|
+
assertInfo("For field #{field}") do
|
57
|
+
time1 = PgTimeWithTimeZone.new
|
58
|
+
time2 = PgTimeWithTimeZone.new
|
59
|
+
assertEquals(time1.eql?(time2), true)
|
60
|
+
assertEquals(time1 == time2, true)
|
61
|
+
assertEquals(time1 != time2, false)
|
62
|
+
args = fields.collect do |f|
|
63
|
+
if f == field then 1 else 0 end
|
64
|
+
end
|
65
|
+
time2 = PgTimeWithTimeZone.new(*args)
|
66
|
+
assertEquals(time1 == time2, false)
|
67
|
+
assertEquals(time1 != time2, true)
|
68
|
+
assertEquals(time1.eql?(Object.new), false)
|
69
|
+
assertEquals(time1 == Object.new, false)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_hash
|
75
|
+
count = 0
|
76
|
+
hashes = Hash.new(0)
|
77
|
+
testHash = proc { |*args|
|
78
|
+
assertEquals(PgTimeWithTimeZone.new(*args).hash,
|
79
|
+
PgTimeWithTimeZone.new(*args).hash)
|
80
|
+
hashes[PgTimeWithTimeZone.new(*args).hash] += 1
|
81
|
+
count += 1
|
82
|
+
}
|
83
|
+
for i in (0...10)
|
84
|
+
testHash.call(i, 0, 0, 0, 0)
|
85
|
+
testHash.call(0, i, 0, 0, 0)
|
86
|
+
testHash.call(0, 0, i, 0, 0)
|
87
|
+
testHash.call(0, 0, 0, i, 0)
|
88
|
+
testHash.call(0, 0, 0, 0, i)
|
89
|
+
end
|
90
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_to_s_and_to_sql
|
94
|
+
testCases = [
|
95
|
+
[[0, 0, 0, 0, 0], "00:00:00+00:00"],
|
96
|
+
[[12, 0, 0, -8, 0], "12:00:00-08:00"],
|
97
|
+
[[23, 59, 59, 23, 0], "23:59:59+23:00"],
|
98
|
+
]
|
99
|
+
for testCase in testCases
|
100
|
+
assertInfo("for test case #{testCase.inspect}") do
|
101
|
+
args, expected = *testCase
|
102
|
+
t = PgTimeWithTimeZone.new(*args)
|
103
|
+
assertEquals(t.to_s, expected)
|
104
|
+
assertEquals(t.to_sql, "time with time zone '#{t}'")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
PgTimeWithTimeZoneTest.new.run if $0 == __FILE__
|
112
|
+
|
113
|
+
# Local Variables:
|
114
|
+
# tab-width: 2
|
115
|
+
# ruby-indent-level: 2
|
116
|
+
# indent-tabs-mode: nil
|
117
|
+
# End:
|
@@ -0,0 +1,134 @@
|
|
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 PgTimestampTest < Test
|
10
|
+
|
11
|
+
include SqlPostgres
|
12
|
+
include RandomThings
|
13
|
+
|
14
|
+
def test_ctor_and_accessors
|
15
|
+
fields = [:year, :month, :day, :hour, :minute, :second, :microseconds].collect do |field|
|
16
|
+
[field, randomInteger]
|
17
|
+
end
|
18
|
+
timestamp = PgTimestamp.new(*fields.collect do |field, value| value end)
|
19
|
+
for field, value in fields
|
20
|
+
assertInfo("For field #{field}") do
|
21
|
+
assertEquals(timestamp.send(field), value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_ctor_defaults
|
27
|
+
for number_of_args in (0..7)
|
28
|
+
assertInfo("For number_of_args=#{number_of_args}") do
|
29
|
+
assertEquals(PgTimestamp.new,
|
30
|
+
PgTimestamp.new(*([0] * number_of_args)))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_equality
|
36
|
+
fields = ["year", "month", "day", "hour", "minute", "second", "microseconds"]
|
37
|
+
for field in fields
|
38
|
+
assertInfo("For field #{field}") do
|
39
|
+
time1 = PgTimestamp.new
|
40
|
+
time2 = PgTimestamp.new
|
41
|
+
assertEquals(time1.eql?(time2), true)
|
42
|
+
assertEquals(time1 == time2, true)
|
43
|
+
assertEquals(time1 != time2, false)
|
44
|
+
args = fields.collect do |f|
|
45
|
+
if f == field then 1 else 0 end
|
46
|
+
end
|
47
|
+
time2 = PgTimestamp.new(*args)
|
48
|
+
assertEquals(time1 == time2, false)
|
49
|
+
assertEquals(time1 != time2, true)
|
50
|
+
assertEquals(time1.eql?(Object.new), false)
|
51
|
+
assertEquals(time1 == Object.new, false)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_hash
|
57
|
+
count = 0
|
58
|
+
hashes = Hash.new(0)
|
59
|
+
testHash = proc { |*args|
|
60
|
+
assertEquals(PgTimestamp.new(*args).hash, PgTimestamp.new(*args).hash)
|
61
|
+
hashes[PgTimestamp.new(*args).hash] += 1
|
62
|
+
count += 1
|
63
|
+
}
|
64
|
+
for i in (0...10)
|
65
|
+
testHash.call(i, 0, 0, 0, 0, 0, 0)
|
66
|
+
testHash.call(0, i, 0, 0, 0, 0, 0)
|
67
|
+
testHash.call(0, 0, i, 0, 0, 0, 0)
|
68
|
+
testHash.call(0, 0, 0, i, 0, 0, 0)
|
69
|
+
testHash.call(0, 0, 0, 0, i, 0, 0)
|
70
|
+
testHash.call(0, 0, 0, 0, 0, i, 0)
|
71
|
+
testHash.call(0, 0, 0, 0, 0, 0, i)
|
72
|
+
end
|
73
|
+
assertGreaterOrEqual(hashes.size.to_f / count, 0.5)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_to_s
|
77
|
+
testCases = [
|
78
|
+
[[0, 0, 0, 0, 0, 0], "0000-00-00 00:00:00.00000"],
|
79
|
+
[[1999, 12, 31, 23, 59, 59], "1999-12-31 23:59:59.00000"],
|
80
|
+
[[1999, 12, 31, 23, 59, 59, 98765], "1999-12-31 23:59:59.98765"],
|
81
|
+
]
|
82
|
+
for testCase in testCases
|
83
|
+
args, expected = *testCase
|
84
|
+
assertEquals(PgTimestamp.new(*args).to_s, expected)
|
85
|
+
assertEquals(PgTimestamp.new(*args).to_sql, "timestamp '#{expected}'")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_to_local_time
|
90
|
+
testCases = [
|
91
|
+
[1970, 1, 1, 0, 0, 0],
|
92
|
+
[1999, 12, 31, 23, 59, 59],
|
93
|
+
]
|
94
|
+
for testCase in testCases
|
95
|
+
time = Time.local(*testCase)
|
96
|
+
assertEquals(PgTimestamp.new(*testCase).to_local_time, time)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_to_utc_time
|
101
|
+
testCases = [
|
102
|
+
[1970, 1, 1, 0, 0, 0],
|
103
|
+
[1999, 12, 31, 23, 59, 59],
|
104
|
+
]
|
105
|
+
for testCase in testCases
|
106
|
+
time = Time.utc(*testCase)
|
107
|
+
assertEquals(PgTimestamp.new(*testCase).to_utc_time, time)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_from_sql
|
112
|
+
testCases = [
|
113
|
+
[1900, 1, 1, 0, 0, 0],
|
114
|
+
[1999, 12, 31, 23, 59, 59],
|
115
|
+
[1999, 12, 31, 23, 59, 59, 98765],
|
116
|
+
]
|
117
|
+
for testCase in testCases
|
118
|
+
sql = "%04d-%02d-%02d %02d:%02d:%02d" % testCase[0..5]
|
119
|
+
if testCase[6]
|
120
|
+
sql += ".%6d" % testCase[6]
|
121
|
+
end
|
122
|
+
assertEquals(PgTimestamp.from_sql(sql), PgTimestamp.new(*testCase))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
PgTimestampTest.new.run if $0 == __FILE__
|
129
|
+
|
130
|
+
# Local Variables:
|
131
|
+
# tab-width: 2
|
132
|
+
# ruby-indent-level: 2
|
133
|
+
# indent-tabs-mode: nil
|
134
|
+
# End:
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RandomThings
|
2
|
+
|
3
|
+
def randomString
|
4
|
+
rand.to_s
|
5
|
+
end
|
6
|
+
module_function :randomString
|
7
|
+
|
8
|
+
alias_method :randomWhatever, :randomString
|
9
|
+
module_function :randomWhatever
|
10
|
+
|
11
|
+
def randomInteger
|
12
|
+
rand(1000000)
|
13
|
+
end
|
14
|
+
|
15
|
+
def randomFloat
|
16
|
+
rand
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
# Local Variables:
|
22
|
+
# tab-width: 2
|
23
|
+
# ruby-indent-level: 2
|
24
|
+
# indent-tabs-mode: nil
|
25
|
+
# End:
|