caruby-core 1.5.5 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/History.md +5 -1
- data/lib/caruby.rb +3 -5
- data/lib/caruby/caruby-src.tar.gz +0 -0
- data/lib/caruby/database.rb +53 -69
- data/lib/caruby/database/application_service.rb +25 -0
- data/lib/caruby/database/cache.rb +60 -0
- data/lib/caruby/database/fetched_matcher.rb +52 -38
- data/lib/caruby/database/lazy_loader.rb +4 -4
- data/lib/caruby/database/operation.rb +34 -0
- data/lib/caruby/database/persistable.rb +171 -86
- data/lib/caruby/database/persistence_service.rb +32 -34
- data/lib/caruby/database/persistifier.rb +100 -43
- data/lib/caruby/database/reader.rb +107 -85
- data/lib/caruby/database/reader_template_builder.rb +60 -0
- data/lib/caruby/database/saved_matcher.rb +3 -3
- data/lib/caruby/database/sql_executor.rb +88 -17
- data/lib/caruby/database/writer.rb +213 -177
- data/lib/caruby/database/writer_template_builder.rb +334 -0
- data/lib/caruby/{util → helpers}/controlled_value.rb +0 -0
- data/lib/caruby/{util → helpers}/coordinate.rb +4 -4
- data/lib/caruby/{util → helpers}/person.rb +3 -3
- data/lib/caruby/{util → helpers}/properties.rb +7 -9
- data/lib/caruby/{util → helpers}/roman.rb +2 -2
- data/lib/caruby/{util → helpers}/version.rb +1 -1
- data/lib/caruby/json/deserializer.rb +2 -2
- data/lib/caruby/json/serializer.rb +49 -7
- data/lib/caruby/metadata.rb +30 -0
- data/lib/caruby/metadata/java_property.rb +21 -0
- data/lib/caruby/metadata/propertied.rb +191 -0
- data/lib/caruby/metadata/property.rb +22 -0
- data/lib/caruby/metadata/property_characteristics.rb +201 -0
- data/lib/caruby/migration/migratable.rb +11 -182
- data/lib/caruby/rdbi/driver/jdbc.rb +446 -0
- data/lib/caruby/resource.rb +20 -823
- data/lib/caruby/version.rb +1 -1
- data/test/lib/caruby/database/cache_test.rb +54 -0
- data/test/lib/caruby/{util → helpers}/controlled_value_test.rb +3 -5
- data/test/lib/caruby/{util → helpers}/person_test.rb +4 -6
- data/test/lib/caruby/helpers/properties_test.rb +34 -0
- data/test/lib/caruby/{util → helpers}/roman_test.rb +2 -3
- data/test/lib/caruby/{util → helpers}/version_test.rb +2 -3
- data/test/lib/helper.rb +7 -0
- metadata +161 -214
- data/lib/caruby/cli/application.rb +0 -36
- data/lib/caruby/cli/command.rb +0 -202
- data/lib/caruby/csv/csv_mapper.rb +0 -159
- data/lib/caruby/csv/csvio.rb +0 -203
- data/lib/caruby/database/search_template_builder.rb +0 -56
- data/lib/caruby/database/store_template_builder.rb +0 -278
- data/lib/caruby/domain.rb +0 -193
- data/lib/caruby/domain/attribute.rb +0 -584
- data/lib/caruby/domain/attributes.rb +0 -628
- data/lib/caruby/domain/dependency.rb +0 -225
- data/lib/caruby/domain/id_alias.rb +0 -22
- data/lib/caruby/domain/importer.rb +0 -183
- data/lib/caruby/domain/introspection.rb +0 -176
- data/lib/caruby/domain/inverse.rb +0 -172
- data/lib/caruby/domain/inversible.rb +0 -90
- data/lib/caruby/domain/java_attribute.rb +0 -173
- data/lib/caruby/domain/merge.rb +0 -185
- data/lib/caruby/domain/metadata.rb +0 -142
- data/lib/caruby/domain/mixin.rb +0 -35
- data/lib/caruby/domain/properties.rb +0 -95
- data/lib/caruby/domain/reference_visitor.rb +0 -428
- data/lib/caruby/domain/uniquify.rb +0 -50
- data/lib/caruby/import/java.rb +0 -387
- data/lib/caruby/migration/migrator.rb +0 -918
- data/lib/caruby/migration/resource_module.rb +0 -9
- data/lib/caruby/migration/uniquify.rb +0 -17
- data/lib/caruby/util/attribute_path.rb +0 -44
- data/lib/caruby/util/cache.rb +0 -56
- data/lib/caruby/util/class.rb +0 -149
- data/lib/caruby/util/collection.rb +0 -1152
- data/lib/caruby/util/domain_extent.rb +0 -46
- data/lib/caruby/util/file_separator.rb +0 -65
- data/lib/caruby/util/inflector.rb +0 -27
- data/lib/caruby/util/log.rb +0 -95
- data/lib/caruby/util/math.rb +0 -12
- data/lib/caruby/util/merge.rb +0 -59
- data/lib/caruby/util/module.rb +0 -18
- data/lib/caruby/util/options.rb +0 -97
- data/lib/caruby/util/partial_order.rb +0 -35
- data/lib/caruby/util/pretty_print.rb +0 -204
- data/lib/caruby/util/stopwatch.rb +0 -74
- data/lib/caruby/util/topological_sync_enumerator.rb +0 -62
- data/lib/caruby/util/transitive_closure.rb +0 -55
- data/lib/caruby/util/tree.rb +0 -48
- data/lib/caruby/util/trie.rb +0 -37
- data/lib/caruby/util/uniquifier.rb +0 -30
- data/lib/caruby/util/validation.rb +0 -20
- data/lib/caruby/util/visitor.rb +0 -365
- data/lib/caruby/util/weak_hash.rb +0 -36
- data/test/lib/caruby/csv/csv_mapper_test.rb +0 -40
- data/test/lib/caruby/csv/csvio_test.rb +0 -69
- data/test/lib/caruby/database/persistable_test.rb +0 -92
- data/test/lib/caruby/domain/domain_test.rb +0 -112
- data/test/lib/caruby/domain/inversible_test.rb +0 -99
- data/test/lib/caruby/domain/reference_visitor_test.rb +0 -130
- data/test/lib/caruby/import/java_test.rb +0 -80
- data/test/lib/caruby/import/mixed_case_test.rb +0 -14
- data/test/lib/caruby/migration/test_case.rb +0 -102
- data/test/lib/caruby/test_case.rb +0 -230
- data/test/lib/caruby/util/cache_test.rb +0 -23
- data/test/lib/caruby/util/class_test.rb +0 -61
- data/test/lib/caruby/util/collection_test.rb +0 -398
- data/test/lib/caruby/util/command_test.rb +0 -55
- data/test/lib/caruby/util/domain_extent_test.rb +0 -60
- data/test/lib/caruby/util/file_separator_test.rb +0 -30
- data/test/lib/caruby/util/inflector_test.rb +0 -12
- data/test/lib/caruby/util/lazy_hash_test.rb +0 -34
- data/test/lib/caruby/util/merge_test.rb +0 -83
- data/test/lib/caruby/util/module_test.rb +0 -25
- data/test/lib/caruby/util/options_test.rb +0 -59
- data/test/lib/caruby/util/partial_order_test.rb +0 -42
- data/test/lib/caruby/util/pretty_print_test.rb +0 -85
- data/test/lib/caruby/util/properties_test.rb +0 -50
- data/test/lib/caruby/util/stopwatch_test.rb +0 -18
- data/test/lib/caruby/util/topological_sync_enumerator_test.rb +0 -69
- data/test/lib/caruby/util/transitive_closure_test.rb +0 -67
- data/test/lib/caruby/util/tree_test.rb +0 -23
- data/test/lib/caruby/util/trie_test.rb +0 -14
- data/test/lib/caruby/util/visitor_test.rb +0 -278
- data/test/lib/caruby/util/weak_hash_test.rb +0 -45
- data/test/lib/examples/clinical_trials/migration/migration_test.rb +0 -58
- data/test/lib/examples/clinical_trials/migration/test_case.rb +0 -38
@@ -1,55 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
|
5
|
-
require 'caruby/cli/command'
|
6
|
-
require 'set'
|
7
|
-
|
8
|
-
module CaRuby
|
9
|
-
class CommandTest < Test::Unit::TestCase
|
10
|
-
def test_empty
|
11
|
-
verify_execution(Command.new, "test", {})
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_args_only
|
15
|
-
verify_execution(Command.new(:arg), "test arg", :arg => 'arg')
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_nonmandatory_argument_option
|
19
|
-
verify_execution(Command.new(:opt => :none), "test --opt", :opt => true)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_mandatory_argument_option
|
23
|
-
verify_execution(Command.new(:opt => :mandatory), "test --opt opt", {:opt => 'opt'})
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_integer_argument_option
|
27
|
-
verify_execution(Command.new(:opt => :integer), "test --opt 1", {:opt => 1})
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_array_argument_option
|
31
|
-
verify_execution(Command.new(:opt => :array), "test --opt a,b", {:opt => ['a', 'b']})
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_complex
|
35
|
-
verify_execution(Command.new(:arg1, :opt1 => :none, :opt2 => :optional, :opt3 => :mandatory),
|
36
|
-
"test --opt1 --opt3 opt3 arg1 arg2",
|
37
|
-
{:opt1 => true, :opt3 => 'opt3', :arg1 => 'arg1'},
|
38
|
-
'arg2')
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def verify_execution(cmd, s, opts, *args)
|
44
|
-
ARGV.clear.concat(s.split[1..-1])
|
45
|
-
cmd.start do |copts, *cargs|
|
46
|
-
opts.each do |opt, expected|
|
47
|
-
actual = copts[opt]
|
48
|
-
assert_not_nil(actual, "Command option #{opt} not found.")
|
49
|
-
assert_equal(expected, actual, "Command option #{opt} parsed incorrectly.")
|
50
|
-
end
|
51
|
-
assert_equal(cargs, args, "Command arguments differ.")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
|
5
|
-
require 'caruby/util/domain_extent'
|
6
|
-
|
7
|
-
class DomainExtentTest < Test::Unit::TestCase
|
8
|
-
# Test composite key class
|
9
|
-
class Composite
|
10
|
-
attr_reader :a, :b, :c
|
11
|
-
|
12
|
-
def initialize(a, b, c=3)
|
13
|
-
super()
|
14
|
-
@a = a; @b = b; @c = c
|
15
|
-
end
|
16
|
-
|
17
|
-
def ==(other)
|
18
|
-
a == other.a && b == other.b && c == other.c
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
attr_reader :extent
|
23
|
-
|
24
|
-
def setup
|
25
|
-
@extent = DomainExtent.new
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_create_on_demand
|
29
|
-
assert(!extent.has_key?(String), 'New domain extent not empty')
|
30
|
-
assert_not_nil(extent[String], 'Entry not created on demand')
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_existing_fetch
|
34
|
-
expected = extent[String][1] = 'a'
|
35
|
-
target = extent.get(String, 1)
|
36
|
-
assert_equal(expected, target, 'Existing entry not found')
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_missing_fetch
|
40
|
-
assert_nil(DomainExtent.new.get(Symbol, :a), 'Default factory instance not nil')
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_simple_key_factory
|
44
|
-
extent = DomainExtent.new
|
45
|
-
# the String extent key is a number
|
46
|
-
# the String extent value is the number as a string
|
47
|
-
extent.set_factory(String) { |key| key.to_s }
|
48
|
-
assert_equal('1', extent.get(String, 1), 'Simple key instance not found')
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_composite_key_factory
|
52
|
-
extent = DomainExtent.new
|
53
|
-
# the String extent key is a number
|
54
|
-
# the String extent value is the number as a string
|
55
|
-
extent.set_factory(Composite) { |key| Composite.new(key[:a], key[:b], key[:c]) }
|
56
|
-
key = {:a => 1, :b => 2, :c => 3}
|
57
|
-
expected = Composite.new(1, 2, 3)
|
58
|
-
assert_equal(expected, extent.get(Composite, key), 'Composite key instance not found')
|
59
|
-
end
|
60
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require 'caruby/util/file_separator'
|
5
|
-
|
6
|
-
class FileSeparatorTest < Test::Unit::TestCase
|
7
|
-
FIXTURES_DIR = 'test/fixtures/caruby/util'
|
8
|
-
LF_FILE = File.join(FIXTURES_DIR, 'lf_line_sep.txt')
|
9
|
-
CR_FILE = File.join(FIXTURES_DIR, 'cr_line_sep.txt')
|
10
|
-
CRLF_FILE = File.join(FIXTURES_DIR, 'crlf_line_sep.txt')
|
11
|
-
|
12
|
-
def test_lf_line_separator
|
13
|
-
verify_read(LF_FILE, "LF")
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_cr_line_separator
|
17
|
-
verify_read(CR_FILE, "CR")
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_crlf_line_separator
|
21
|
-
verify_read(CRLF_FILE, "CRLF")
|
22
|
-
end
|
23
|
-
|
24
|
-
def verify_read(file, type)
|
25
|
-
lines = File.open(file) { |io| io.readlines }
|
26
|
-
assert_equal(3, lines.size, "#{type} line separator not recognized in readlines")
|
27
|
-
lines = File.open(file) { |io| io.to_a }
|
28
|
-
assert_equal(3, lines.size, "#{type} line separator not recognized in to_a")
|
29
|
-
end
|
30
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require 'caruby/util/inflector'
|
5
|
-
|
6
|
-
class InflectorTest < Test::Unit::TestCase
|
7
|
-
def test_quantified_s
|
8
|
-
assert_equal("1 person", "person".quantify(1))
|
9
|
-
assert_equal("2 people", "person".quantify(2))
|
10
|
-
assert_equal("0 people", "person".quantify(0))
|
11
|
-
end
|
12
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
|
5
|
-
require 'caruby/util/domain_extent'
|
6
|
-
|
7
|
-
class LazyHastTest < Test::Unit::TestCase
|
8
|
-
|
9
|
-
def test_value_factory
|
10
|
-
hash = LazyHash.new { |key| key.to_s }
|
11
|
-
assert_equal('1', hash[1], "Factory return value is incorrect")
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_default_value_factory
|
15
|
-
hash = LazyHash.new
|
16
|
-
assert_nil(hash[1], "Default factory does not return")
|
17
|
-
assert(hash.has_key?(1), "Default entry not created")
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_nil_key
|
21
|
-
hash = LazyHash.new
|
22
|
-
assert_nil(hash[nil], "nil key does not return")
|
23
|
-
assert(!hash.has_key?(nil), "Entry created for nil key")
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_reject_missing_value
|
27
|
-
hash = LazyHash.new(:compact => true)
|
28
|
-
assert(!hash.has_key?(1), "Default entry created for nil value")
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_fetch
|
32
|
-
assert_raises(IndexError, "Fetch non-existent doesn't raise IndexError") { LazyHash.new.fetch(:a) }
|
33
|
-
end
|
34
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require 'caruby/util/merge'
|
5
|
-
require 'caruby/util/log'
|
6
|
-
|
7
|
-
class MergeTest < Test::Unit::TestCase
|
8
|
-
LogCaRuby::Log.instance.open(File.join('test', 'results', 'log', 'caruby.log'), :debug => true)
|
9
|
-
|
10
|
-
class Target
|
11
|
-
include Mergeable
|
12
|
-
|
13
|
-
attr_accessor :a, :b, :c, :array
|
14
|
-
|
15
|
-
def self.mergeable_attributes
|
16
|
-
[:a, :b]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Partial
|
21
|
-
attr_accessor :a, :c, :d
|
22
|
-
end
|
23
|
-
|
24
|
-
attr_reader :target
|
25
|
-
|
26
|
-
def setup
|
27
|
-
@target = Target.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_merge_attributes_hash
|
31
|
-
target.merge_attributes(:a => 1, :b => 2, :c => 3)
|
32
|
-
assert_equal(1, target.a, 'Attribute not merged')
|
33
|
-
assert_equal(2, target.b, 'Attribute not merged')
|
34
|
-
assert_equal(3, target.c, 'Attribute not merged')
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_merge_attributes_other
|
38
|
-
other = Target.new
|
39
|
-
other.a = 1
|
40
|
-
other.b = 2
|
41
|
-
other.c = 3
|
42
|
-
target.merge_attributes(other)
|
43
|
-
assert_equal(1, target.a, 'Attribute not merged')
|
44
|
-
assert_equal(2, target.b, 'Attribute not merged')
|
45
|
-
assert_nil(target.c, 'Non-mergeable attribute merged')
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_merge_attributes_other_partial
|
49
|
-
other = Partial.new
|
50
|
-
other.a = 1
|
51
|
-
other.c = 3
|
52
|
-
other.d = 4
|
53
|
-
target.merge_attributes(other)
|
54
|
-
assert_equal(1, target.a, 'Attribute not merged')
|
55
|
-
assert_nil(target.c, 'Non-mergeable attribute merged')
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_array_merge
|
59
|
-
array = [1]
|
60
|
-
array.merge([1, 2])
|
61
|
-
assert_equal([1, 2], array, 'Array deep merge incorrect')
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_array_attribute_merge
|
65
|
-
target.a = [1]
|
66
|
-
target.merge_attributes(:array => [1, 2])
|
67
|
-
assert_equal([1, 2], target.array, 'Array attribute not merged correctly')
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_hash_deep_merge
|
71
|
-
assert_equal({:a => [1], :b => [2, 3]}, {:a => [1], :b => [2]}.merge({:b => [3]}, :deep), 'Hash deep merge incorrect')
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_hash_in_place_deep_merge
|
75
|
-
hash = {:a => [1], :b => [2]}
|
76
|
-
hash.merge!({:b => [3], :c => 4}, :deep)
|
77
|
-
assert_equal({:a => [1], :b => [2, 3], :c => 4}, hash, 'Hash deep merge incorrect')
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_nested_hash_deep_merge
|
81
|
-
assert_equal({:a => {:b => [1, 2]}, :c => 3}, {:a => {:b => [1]}}.merge({:a => {:b => [2]}, :c => 3}, :deep), 'Hash deep merge incorrect')
|
82
|
-
end
|
83
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require 'caruby/util/module'
|
5
|
-
|
6
|
-
module Outer
|
7
|
-
module Middle
|
8
|
-
class C; end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class ModuleTest < Test::Unit::TestCase
|
13
|
-
def test_module_with_name
|
14
|
-
assert_equal(Outer::Middle, Outer.module_with_name('Middle'), "Unqualified module incorrect")
|
15
|
-
assert_nil(Outer.module_with_name('Zed'), "Missing module incorrectly resolves to non-nil value")
|
16
|
-
assert_equal(Outer::Middle::C, Outer.module_with_name('Middle::C'), "Qualified module incorrect")
|
17
|
-
assert_equal(Outer, Kernel.module_with_name('Outer'), "Top-level module incorrect")
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_parent_module
|
21
|
-
assert_equal(Outer, Outer::Middle.parent_module, "Middle parent module incorrect")
|
22
|
-
assert_equal(Outer::Middle, Outer::Middle::C.parent_module, "Inner parent module incorrect")
|
23
|
-
assert_equal(Kernel, Outer.parent_module, "Outer parent module incorrect")
|
24
|
-
end
|
25
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require 'caruby/util/options'
|
5
|
-
|
6
|
-
class OptionsTest < Test::Unit::TestCase
|
7
|
-
def test_present
|
8
|
-
assert(Options.get(:key, {:key => true}), "Option true value not returned")
|
9
|
-
assert(!Options.get(:key, {:key => false}), "Option true value not returned")
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_nil_value
|
13
|
-
assert_equal(:a, Options.get(:key, {:key => nil}, :a), "Options nil value not returned")
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_false_with_true_default
|
17
|
-
assert_equal(false, Options.get(:key, {:key => false}, true), "Option false value with true default doesn't return false")
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_missing
|
21
|
-
assert_nil(Options.get(:key, {}), "Missing option incorrectly found")
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_default_value
|
25
|
-
assert_equal(:a, Options.get(:key, {}, :a), "Option default value not used")
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_default_block
|
29
|
-
assert_equal(:b, Options.get(:key, {}) { :b }, "Option default block not called")
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_symbol
|
33
|
-
assert(Options.get(:key, :key), "Option not found in singleton options")
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_array
|
37
|
-
assert(Options.get(:b, [:a, :b]), "Option not found in array options")
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_collection_value
|
41
|
-
assert_equal([:a], Options.get(:key, {:key => [:a]}, []), "Option array value not returned")
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_empty_to_hash
|
45
|
-
assert_equal({}, Options.to_hash(), "Option to_hash with empty argument list not an empty hash")
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_nil_to_hash
|
49
|
-
assert_equal({}, Options.to_hash(nil), "Option to_hash with nil argument list not an empty hash")
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_hash_to_hash
|
53
|
-
assert_equal({:a => 1}, Options.to_hash({:a => 1}), "Option to_hash with hash argument list not an empty hash")
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_lish_to_hash
|
57
|
-
assert_equal({:a => 1, :b => true, :c => [2, 3]}, Options.to_hash(:a, 1, :b, :c, 2, 3), "Option to_hash with list argument list incorrect")
|
58
|
-
end
|
59
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
require 'caruby/util/partial_order'
|
5
|
-
|
6
|
-
class Queued
|
7
|
-
include PartialOrder
|
8
|
-
|
9
|
-
attr_reader :queue
|
10
|
-
|
11
|
-
def initialize(on)
|
12
|
-
@queue = on.push(self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def <=>(other)
|
16
|
-
queue.index(self) <=> other.queue.index(other) if queue.equal?(other.queue)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class PartialOrderTest < Test::Unit::TestCase
|
21
|
-
def test_same_queue
|
22
|
-
q = []
|
23
|
-
a = Queued.new(q)
|
24
|
-
assert_equal(a, a, "Same value, queue not equal")
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_different_eql_queue
|
28
|
-
a = Queued.new([])
|
29
|
-
@b = Queued.new([])
|
30
|
-
assert_nil(a <=> @b, "Same value, different queue <=> not nil")
|
31
|
-
assert_not_equal(a, @b, "Same value, different queue is equal")
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_less_than
|
35
|
-
q = []
|
36
|
-
a = Queued.new(q)
|
37
|
-
b = Queued.new(q)
|
38
|
-
c = Queued.new([])
|
39
|
-
assert(a < b, "Comparison incorrect")
|
40
|
-
assert_nil(a < c, "Comparison incorrect")
|
41
|
-
end
|
42
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
$:.unshift 'lib'
|
2
|
-
|
3
|
-
require "test/unit"
|
4
|
-
|
5
|
-
require 'set'
|
6
|
-
require 'date'
|
7
|
-
require 'caruby/util/pretty_print'
|
8
|
-
|
9
|
-
class PrettyPrintTest < Test::Unit::TestCase
|
10
|
-
def test_nil
|
11
|
-
assert_equal('nil', nil.pp_s, 'Nil pretty print incorrect')
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_date_time
|
15
|
-
date = DateTime.civil(2009, 4, 15, 5, 55, 55)
|
16
|
-
assert_equal(date.strftime, date.pp_s, 'Date pretty print incorrect')
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_array
|
20
|
-
assert_equal('[:a, :b]', [:a, :b].pp_s, 'Array pretty print incorrect')
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_java_collection
|
24
|
-
a = Java::JavaUtil::ArrayList.new
|
25
|
-
a << :a << :b
|
26
|
-
assert_equal(a.to_a.pp_s, a.pp_s, 'Java collection pretty print incorrect')
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_java_collection_cycle
|
30
|
-
a = Java::JavaUtil::ArrayList.new
|
31
|
-
a << :a << a
|
32
|
-
assert_equal('[:a, [...]]', a.pp_s(:single_line), 'Cyclic set pretty print incorrect')
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_hash
|
36
|
-
assert_equal('{:a => a, :b => b}', {:a => 'a', :b => 'b'}.pp_s(:single_line), 'Hash pretty print incorrect')
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_qp
|
40
|
-
assert_equal('1', 1.qp, 'Numeric quick print incorrect')
|
41
|
-
assert_equal('nil', nil.qp, 'nil quick print incorrect')
|
42
|
-
assert_equal('a', 'a'.qp, 'String quick print incorrect')
|
43
|
-
assert_equal(':a', :a.qp, 'Symbol quick print incorrect')
|
44
|
-
assert_equal('[:a]', [:a].qp, 'Array quick print incorrect')
|
45
|
-
assert_equal('TestCase', Test::Unit::TestCase.qp, 'Class quick print incorrect')
|
46
|
-
|
47
|
-
x = {:a => 'a', :b => 'b'}
|
48
|
-
x.qp
|
49
|
-
|
50
|
-
|
51
|
-
assert_equal('{:a => a, :b => b}', {:a => 'a', :b => 'b'}.qp, 'Hash quick print incorrect')
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_set
|
55
|
-
assert_equal([:a].pp_s, [:a].to_set.pp_s, 'Set pretty print incorrect')
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_set_cycle
|
59
|
-
a = [:a].to_set
|
60
|
-
a << a
|
61
|
-
assert_equal('[:a, [...]]', a.pp_s(:single_line), 'Cyclic set pretty print incorrect')
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_single_line_argument
|
65
|
-
a = [].fill(:a, 0, 80)
|
66
|
-
assert(a.pp_s =~ /\n/, 'Test array not long enough')
|
67
|
-
assert(!a.pp_s(:single_line).include?("\n"), 'Single line option ignored')
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_single_line_option
|
71
|
-
a = [].fill(:a, 0, 80)
|
72
|
-
assert_equal(a.pp_s(:single_line => true), a.pp_s(:single_line), 'Single line option ignored')
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_print_wrapper_block
|
76
|
-
tuples = [[:a, :b], [:c]]
|
77
|
-
wrapper = PrintWrapper.new { |tuple| "<#{tuple.join(',')}>" }
|
78
|
-
wrappers = tuples.wrap{ |tuple| wrapper.wrap(tuple) }
|
79
|
-
assert_equal("[<a,b>, <c>]", wrappers.pp_s)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_wrapper_block
|
83
|
-
assert_equal("[<a,b>, <c>]", [[:a, :b], [:c]].pp_s { |tuple| "<#{tuple.join(',')}>" })
|
84
|
-
end
|
85
|
-
end
|