jactive_support 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rvmrc +63 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/Rakefile +45 -0
- data/jactive_support.gemspec +24 -0
- data/lib/jactive_support.rb +6 -0
- data/lib/jactive_support/constantize.rb +19 -0
- data/lib/jactive_support/core_ext.rb +4 -0
- data/lib/jactive_support/core_ext/enum.rb +43 -0
- data/lib/jactive_support/core_ext/hash.rb +2 -0
- data/lib/jactive_support/core_ext/hash/assert_valid_params.rb +19 -0
- data/lib/jactive_support/core_ext/hash/with_keys_values.rb +9 -0
- data/lib/jactive_support/core_ext/locale.rb +28 -0
- data/lib/jactive_support/core_ext/module.rb +9 -0
- data/lib/jactive_support/core_ext/numeric.rb +7 -0
- data/lib/jactive_support/core_ext/ordering.rb +17 -0
- data/lib/jactive_support/core_ext/to_java.rb +9 -0
- data/lib/jactive_support/core_ext/to_java_date.rb +25 -0
- data/lib/jactive_support/core_ext/to_java_list.rb +11 -0
- data/lib/jactive_support/core_ext/to_java_map.rb +11 -0
- data/lib/jactive_support/java_ext.rb +4 -0
- data/lib/jactive_support/java_ext/date.rb +37 -0
- data/lib/jactive_support/java_ext/date/calculations.rb +43 -0
- data/lib/jactive_support/java_ext/date/conversions.rb +135 -0
- data/lib/jactive_support/java_ext/enum.rb +19 -0
- data/lib/jactive_support/java_ext/iterable.rb +74 -0
- data/lib/jactive_support/java_ext/iterator.rb +8 -0
- data/lib/jactive_support/java_ext/list.rb +65 -0
- data/lib/jactive_support/java_ext/list_iterator.rb +8 -0
- data/lib/jactive_support/java_ext/locale.rb +32 -0
- data/lib/jactive_support/java_ext/map.rb +6 -0
- data/lib/jactive_support/java_ext/map/constructor.rb +35 -0
- data/lib/jactive_support/java_ext/map/hash.rb +166 -0
- data/lib/jactive_support/java_ext/number.rb +91 -0
- data/lib/jactive_support/java_ext/sql_date.rb +7 -0
- data/lib/jactive_support/java_ext/sql_date/conversions.rb +33 -0
- data/lib/jactive_support/json.rb +1 -0
- data/lib/jactive_support/json/encoders/collection.rb +12 -0
- data/lib/jactive_support/json/encoders/locale.rb +6 -0
- data/lib/jactive_support/json/encoders/map.rb +55 -0
- data/lib/jactive_support/json/encoding.rb +5 -0
- data/lib/jactive_support/rescuable.rb +62 -0
- data/lib/jactive_support/version.rb +3 -0
- data/spec/constantize_spec.rb +57 -0
- data/spec/core_ext/hash_spec.rb +34 -0
- data/spec/core_ext/module_spec.rb +19 -0
- data/spec/core_ext/ordering_spec.rb +12 -0
- data/spec/enum_spec.rb +67 -0
- data/spec/java_ext/iterable/clear_spec.rb +56 -0
- data/spec/java_ext/iterable/delete_if_spec.rb +71 -0
- data/spec/java_ext/iterable/empty_spec.rb +10 -0
- data/spec/java_ext/iterable/reject_spec.rb +76 -0
- data/spec/java_ext/iterable/shared/enumeratorize.rb +12 -0
- data/spec/java_ext/iterable/shared/fixtures.rb +90 -0
- data/spec/java_ext/iterable/shift_spec.rb +160 -0
- data/spec/java_ext/list/clear_spec.rb +56 -0
- data/spec/java_ext/list/collect_spec.rb +11 -0
- data/spec/java_ext/list/last_spec.rb +87 -0
- data/spec/java_ext/list/map_spec.rb +11 -0
- data/spec/java_ext/list/push_spec.rb +44 -0
- data/spec/java_ext/list/shared/collect.rb +133 -0
- data/spec/java_ext/list/shared/fixtures.rb +34 -0
- data/spec/java_ext/map/assoc_spec.rb +43 -0
- data/spec/java_ext/map/clear_spec.rb +49 -0
- data/spec/java_ext/map/clone_spec.rb +13 -0
- data/spec/java_ext/map/compare_by_identity_spec.rb +111 -0
- data/spec/java_ext/map/constructor_spec.rb +54 -0
- data/spec/java_ext/map/delete_if_spec.rb +54 -0
- data/spec/java_ext/map/delete_spec.rb +38 -0
- data/spec/java_ext/map/each_key_spec.rb +29 -0
- data/spec/java_ext/map/each_pair_spec.rb +38 -0
- data/spec/java_ext/map/each_spec.rb +9 -0
- data/spec/java_ext/map/each_value_spec.rb +28 -0
- data/spec/java_ext/map/element_reference_spec.rb +119 -0
- data/spec/java_ext/map/element_set_spec.rb +7 -0
- data/spec/java_ext/map/empty_spec.rb +15 -0
- data/spec/java_ext/map/eql_spec.rb +19 -0
- data/spec/java_ext/map/equal_value_spec.rb +18 -0
- data/spec/java_ext/map/fetch_spec.rb +35 -0
- data/spec/java_ext/map/fixtures/classes.rb +36 -0
- data/spec/java_ext/map/flatten_spec.rb +64 -0
- data/spec/java_ext/map/has_key_spec.rb +8 -0
- data/spec/java_ext/map/has_value_spec.rb +8 -0
- data/spec/java_ext/map/hash_spec.rb +53 -0
- data/spec/java_ext/map/include_spec.rb +7 -0
- data/spec/java_ext/map/index_spec.rb +7 -0
- data/spec/java_ext/map/indexes_spec.rb +9 -0
- data/spec/java_ext/map/indices_spec.rb +9 -0
- data/spec/java_ext/map/initialize_copy_spec.rb +13 -0
- data/spec/java_ext/map/initialize_spec.rb +64 -0
- data/spec/java_ext/map/inspect_spec.rb +9 -0
- data/spec/java_ext/map/invert_spec.rb +27 -0
- data/spec/java_ext/map/keep_if_spec.rb +33 -0
- data/spec/java_ext/map/key_spec.rb +14 -0
- data/spec/java_ext/map/keys_spec.rb +39 -0
- data/spec/java_ext/map/length_spec.rb +7 -0
- data/spec/java_ext/map/member_spec.rb +7 -0
- data/spec/java_ext/map/merge_spec.rb +69 -0
- data/spec/java_ext/map/rassoc_spec.rb +39 -0
- data/spec/java_ext/map/reject_spec.rb +123 -0
- data/spec/java_ext/map/replace_spec.rb +7 -0
- data/spec/java_ext/map/select_spec.rb +98 -0
- data/spec/java_ext/map/shared/each.rb +77 -0
- data/spec/java_ext/map/shared/eql.rb +224 -0
- data/spec/java_ext/map/shared/equal.rb +94 -0
- data/spec/java_ext/map/shared/index.rb +29 -0
- data/spec/java_ext/map/shared/iteration.rb +28 -0
- data/spec/java_ext/map/shared/key.rb +43 -0
- data/spec/java_ext/map/shared/length.rb +12 -0
- data/spec/java_ext/map/shared/replace.rb +82 -0
- data/spec/java_ext/map/shared/store.rb +68 -0
- data/spec/java_ext/map/shared/to_s.rb +68 -0
- data/spec/java_ext/map/shared/update.rb +95 -0
- data/spec/java_ext/map/shared/value.rb +16 -0
- data/spec/java_ext/map/shared/values_at.rb +12 -0
- data/spec/java_ext/map/shift_spec.rb +44 -0
- data/spec/java_ext/map/size_spec.rb +7 -0
- data/spec/java_ext/map/sort_spec.rb +17 -0
- data/spec/java_ext/map/store_spec.rb +7 -0
- data/spec/java_ext/map/to_a_spec.rb +29 -0
- data/spec/java_ext/map/to_hash_spec.rb +11 -0
- data/spec/java_ext/map/to_s_spec.rb +20 -0
- data/spec/java_ext/map/try_convert_spec.rb +32 -0
- data/spec/java_ext/map/update_spec.rb +7 -0
- data/spec/java_ext/map/value_spec.rb +8 -0
- data/spec/java_ext/map/values_at_spec.rb +7 -0
- data/spec/java_ext/map/values_spec.rb +10 -0
- data/spec/locale_spec.rb +77 -0
- data/spec/shared/fixtures.rb +7 -0
- data/spec/shared/version.rb +123 -0
- data/spec/spec_helper.rb +50 -0
- metadata +332 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'jactive_support/java_ext/list'
|
2
|
+
require File.expand_path('../shared/fixtures', __FILE__)
|
3
|
+
|
4
|
+
describe "java::util::List#clear" do
|
5
|
+
it "removes all elements" do
|
6
|
+
a = List[1, 2, 3, 4]
|
7
|
+
a.clear.should equal(a)
|
8
|
+
a.should == List[]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns self" do
|
12
|
+
a = List[1]
|
13
|
+
oid = a.object_id
|
14
|
+
a.clear.object_id.should == oid
|
15
|
+
end
|
16
|
+
|
17
|
+
it "leaves the List empty" do
|
18
|
+
a = List[1]
|
19
|
+
a.clear
|
20
|
+
a.empty?.should == true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "keeps tainted status" do
|
24
|
+
a = List[1]
|
25
|
+
a.taint
|
26
|
+
a.tainted?.should be_true
|
27
|
+
a.clear
|
28
|
+
a.tainted?.should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "does not accept any arguments" do
|
32
|
+
lambda { List[1].clear(true) }.should raise_error(ArgumentError)
|
33
|
+
end
|
34
|
+
|
35
|
+
ruby_version_is '1.9' do
|
36
|
+
it "keeps untrusted status" do
|
37
|
+
a = List[1]
|
38
|
+
a.untrust
|
39
|
+
a.untrusted?.should be_true
|
40
|
+
a.clear
|
41
|
+
a.untrusted?.should be_true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
ruby_version_is '' ... '1.9' do
|
46
|
+
it "raises a TypeError on a frozen array" do
|
47
|
+
lambda { ListSpecs.frozen_list.clear }.should raise_error(TypeError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
ruby_version_is '1.9' do
|
52
|
+
it "raises a RuntimeError on a frozen array" do
|
53
|
+
lambda { ListSpecs.frozen_list.clear }.should raise_error(RuntimeError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'jactive_support/java_ext/list'
|
2
|
+
require File.expand_path('../shared/fixtures', __FILE__)
|
3
|
+
require File.expand_path('../shared/collect', __FILE__)
|
4
|
+
|
5
|
+
describe "java::util::List#collect" do
|
6
|
+
it_behaves_like(:list_collect, :collect)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "java::util::List#collect!" do
|
10
|
+
it_behaves_like(:list_collect_b, :collect!)
|
11
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'jactive_support/java_ext/list'
|
2
|
+
require File.expand_path('../shared/fixtures', __FILE__)
|
3
|
+
|
4
|
+
describe "java::util::List#last" do
|
5
|
+
it "returns the last element" do
|
6
|
+
List[1, 1, 1, 1, 2].last.should == 2
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns nil if self is empty" do
|
10
|
+
List[].last.should == nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the last count elements if given a count" do
|
14
|
+
List[1, 2, 3, 4, 5, 9].last(3).should == [4, 5, 9]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns an empty list when passed a count on an empty list" do
|
18
|
+
List[].last(0).should == []
|
19
|
+
List[].last(1).should == []
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns an empty list when count == 0" do
|
23
|
+
List[1, 2, 3, 4, 5].last(0).should == []
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns an list containing the last element when passed count == 1" do
|
27
|
+
List[1, 2, 3, 4, 5].last(1).should == [5]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises an ArgumentError when count is negative" do
|
31
|
+
lambda { List[1, 2].last(-1) }.should raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns the entire list when count > length" do
|
35
|
+
List[1, 2, 3, 4, 5, 9].last(10).should == [1, 2, 3, 4, 5, 9]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns an list which is independent to the original when passed count" do
|
39
|
+
ary = List[1, 2, 3, 4, 5]
|
40
|
+
ary.last(0).replace([1,2])
|
41
|
+
ary.should == List[1, 2, 3, 4, 5]
|
42
|
+
ary.last(1).replace([1,2])
|
43
|
+
ary.should == List[1, 2, 3, 4, 5]
|
44
|
+
ary.last(6).replace([1,2])
|
45
|
+
ary.should == List[1, 2, 3, 4, 5]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "properly handles recursive lists" do
|
49
|
+
empty = ListSpecs.empty_recursive_list
|
50
|
+
empty.last.should equal(empty)
|
51
|
+
|
52
|
+
list = ListSpecs.recursive_list
|
53
|
+
list.last.should equal(list)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "tries to convert the passed argument to an Integer usinig #to_int" do
|
57
|
+
obj = mock('to_int')
|
58
|
+
obj.should_receive(:to_int).and_return(2)
|
59
|
+
List[1, 2, 3, 4, 5].last(obj).should == [4, 5]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "raises a TypeError if the passed argument is not numeric" do
|
63
|
+
lambda { List[1,2].last(nil) }.should raise_error(TypeError)
|
64
|
+
lambda { List[1,2].last("a") }.should raise_error(TypeError)
|
65
|
+
|
66
|
+
obj = mock("nonnumeric")
|
67
|
+
lambda { List[1,2].last(obj) }.should raise_error(TypeError)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "does not return subclass instance on List subclasses" do
|
71
|
+
List[].last(0).should be_kind_of(Array)
|
72
|
+
List[].last(2).should be_kind_of(Array)
|
73
|
+
List[1, 2, 3].last(0).should be_kind_of(Array)
|
74
|
+
List[1, 2, 3].last(1).should be_kind_of(Array)
|
75
|
+
List[1, 2, 3].last(2).should be_kind_of(Array)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "is not destructive" do
|
79
|
+
a = List[1, 2, 3]
|
80
|
+
a.last
|
81
|
+
a.should == List[1, 2, 3]
|
82
|
+
a.last(2)
|
83
|
+
a.should == List[1, 2, 3]
|
84
|
+
a.last(3)
|
85
|
+
a.should == List[1, 2, 3]
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'jactive_support/java_ext/list'
|
2
|
+
require File.expand_path('../shared/fixtures', __FILE__)
|
3
|
+
require File.expand_path('../shared/collect', __FILE__)
|
4
|
+
|
5
|
+
describe "java::util::List#map" do
|
6
|
+
it_behaves_like(:list_collect, :map)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "java::util::List#map!" do
|
10
|
+
it_behaves_like(:list_collect_b, :map!)
|
11
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'jactive_support/java_ext/list'
|
2
|
+
require File.expand_path('../shared/fixtures', __FILE__)
|
3
|
+
|
4
|
+
describe "java::util::List#push" do
|
5
|
+
it "appends the arguments to the list" do
|
6
|
+
a = List[ "a", "b", "c" ]
|
7
|
+
a.push("d", "e", "f").should equal(a)
|
8
|
+
a.push().should == List["a", "b", "c", "d", "e", "f"]
|
9
|
+
a.push(5)
|
10
|
+
a.should == List["a", "b", "c", "d", "e", "f", 5]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "isn't confused by previous shift" do
|
14
|
+
a = List[ "a", "b", "c" ]
|
15
|
+
a.shift
|
16
|
+
a.push("foo")
|
17
|
+
a.should == List["b", "c", "foo"]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "properly handles recursive lists" do
|
21
|
+
empty = ListSpecs.empty_recursive_list
|
22
|
+
empty.push(:last).should == List[empty, :last]
|
23
|
+
|
24
|
+
list = ListSpecs.recursive_list
|
25
|
+
list.push(:last).should == List[1, 'two', 3.0, list, list, list, list, list, :last]
|
26
|
+
end
|
27
|
+
|
28
|
+
ruby_version_is "" ... "1.9" do
|
29
|
+
it "raises a TypeError on a frozen list if modification takes place" do
|
30
|
+
lambda { ListSpecs.frozen_list.push(1) }.should raise_error(TypeError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not raise on a frozen list if no modification is made" do
|
34
|
+
ListSpecs.frozen_list.push.should == List[1, 2, 3]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ruby_version_is "1.9" do
|
39
|
+
it "raises a RuntimeError on a frozen list" do
|
40
|
+
lambda { ListSpecs.frozen_list.push(1) }.should raise_error(RuntimeError)
|
41
|
+
lambda { ListSpecs.frozen_list.push }.should raise_error(RuntimeError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
shared_examples_for :list_collect do |method|
|
2
|
+
it "returns a copy of list with each element replaced by the value returned by block" do
|
3
|
+
a = List['a', 'b', 'c', 'd']
|
4
|
+
b = a.send(method) { |i| i + '!' }
|
5
|
+
b.should == ["a!", "b!", "c!", "d!"]
|
6
|
+
b.object_id.should_not == a.object_id
|
7
|
+
end
|
8
|
+
|
9
|
+
it "does not return subclass instance" do
|
10
|
+
List[1, 2, 3].send(method) { |x| x + 1 }.should be_kind_of(Array)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not change self" do
|
14
|
+
a = List['a', 'b', 'c', 'd']
|
15
|
+
b = a.send(method) { |i| i + '!' }
|
16
|
+
a.should == List['a', 'b', 'c', 'd']
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the evaluated value of block if it broke in the block" do
|
20
|
+
a = List['a', 'b', 'c', 'd']
|
21
|
+
b = a.send(method) {|i|
|
22
|
+
if i == 'c'
|
23
|
+
break 0
|
24
|
+
else
|
25
|
+
i + '!'
|
26
|
+
end
|
27
|
+
}
|
28
|
+
b.should == 0
|
29
|
+
end
|
30
|
+
|
31
|
+
ruby_version_is '' ... '1.9' do
|
32
|
+
it 'returns a copy of self if no block given' do
|
33
|
+
a = List[1, 2, 3]
|
34
|
+
|
35
|
+
copy = a.send(method)
|
36
|
+
copy.should == a.to_a
|
37
|
+
copy.should_not equal(a)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
ruby_version_is '1.9' do
|
41
|
+
it "returns an Enumerator when no block given" do
|
42
|
+
a = List[1, 2, 3]
|
43
|
+
a.send(method).should be_an_instance_of(enumerator_class)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not copy tainted status" do
|
48
|
+
a = List[1, 2, 3]
|
49
|
+
a.taint
|
50
|
+
a.send(method){|x| x}.tainted?.should be_false
|
51
|
+
end
|
52
|
+
|
53
|
+
ruby_version_is '1.9' do
|
54
|
+
it "does not copy untrusted status" do
|
55
|
+
a = List[1, 2, 3]
|
56
|
+
a.untrust
|
57
|
+
a.send(method){|x| x}.untrusted?.should be_false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
shared_examples_for :list_collect_b do |method|
|
63
|
+
it "replaces each element with the value returned by block" do
|
64
|
+
a = List[7, 9, 3, 5]
|
65
|
+
a.send(method) { |i| i - 1 }.should equal(a)
|
66
|
+
a.should == List[6, 8, 2, 4]
|
67
|
+
end
|
68
|
+
|
69
|
+
it "returns self" do
|
70
|
+
a = List[1, 2, 3, 4, 5]
|
71
|
+
b = a.send(method) {|i| i+1 }
|
72
|
+
a.object_id.should == b.object_id
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
|
76
|
+
a = List['a', 'b', 'c', 'd']
|
77
|
+
b = a.send(method) {|i|
|
78
|
+
if i == 'c'
|
79
|
+
break 0
|
80
|
+
else
|
81
|
+
i + '!'
|
82
|
+
end
|
83
|
+
}
|
84
|
+
b.should == 0
|
85
|
+
a.should == List['a!', 'b!', 'c', 'd']
|
86
|
+
end
|
87
|
+
|
88
|
+
ruby_version_is '' ... '1.8.7' do
|
89
|
+
it 'raises LocalJumpError if no block given' do
|
90
|
+
a = List[1, 2, 3]
|
91
|
+
lambda { a.send(method) }.should raise_error(LocalJumpError)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
ruby_version_is '1.8.7' do
|
96
|
+
it "returns an Enumerator when no block given, and the enumerator can modify the original list" do
|
97
|
+
a = List[1, 2, 3]
|
98
|
+
enum = a.send(method)
|
99
|
+
enum.should be_an_instance_of(enumerator_class)
|
100
|
+
enum.each{|i| "#{i}!" }
|
101
|
+
a.should == List["1!", "2!", "3!"]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "keeps tainted status" do
|
106
|
+
a = List[1, 2, 3]
|
107
|
+
a.taint
|
108
|
+
a.tainted?.should be_true
|
109
|
+
a.send(method){|x| x}
|
110
|
+
a.tainted?.should be_true
|
111
|
+
end
|
112
|
+
|
113
|
+
ruby_version_is '1.9' do
|
114
|
+
it "keeps untrusted status" do
|
115
|
+
a = List[1, 2, 3]
|
116
|
+
a.untrust
|
117
|
+
a.send(method){|x| x}
|
118
|
+
a.untrusted?.should be_true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
ruby_version_is '' ... '1.9' do
|
123
|
+
it "raises a TypeError on a frozen list" do
|
124
|
+
lambda { ListSpecs.frozen_list.send(method) {} }.should raise_error(TypeError)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
ruby_version_is '1.9' do
|
129
|
+
it "raises a RuntimeError on a frozen list" do
|
130
|
+
lambda { ListSpecs.frozen_list.send(method) {} }.should raise_error(RuntimeError)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path('../../../../shared/version', __FILE__)
|
2
|
+
require File.expand_path('../../../../shared/fixtures', __FILE__)
|
3
|
+
|
4
|
+
class List < java::util::ArrayList
|
5
|
+
def self.[](*args)
|
6
|
+
new(args)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ListSpecs
|
11
|
+
def self.frozen_list
|
12
|
+
frozen_array = List[1,2,3]
|
13
|
+
frozen_array.freeze
|
14
|
+
frozen_array
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.empty_frozen_list
|
18
|
+
frozen_array = List[]
|
19
|
+
frozen_array.freeze
|
20
|
+
frozen_array
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.recursive_list
|
24
|
+
a = List[1, 'two', 3.0]
|
25
|
+
5.times { a << a }
|
26
|
+
a
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.empty_recursive_list
|
30
|
+
a = List[]
|
31
|
+
a << a
|
32
|
+
a
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
ruby_version_is "1.9" do
|
4
|
+
describe "Hash#assoc" do
|
5
|
+
before(:each) do
|
6
|
+
@h = {:apple => :green, :orange => :orange, :grape => :green, :banana => :yellow}
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns an Array if the argument is == to a key of the Hash" do
|
10
|
+
@h.assoc(:apple).should be_an_instance_of(Array)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns a 2-element Array if the argument is == to a key of the Hash" do
|
14
|
+
@h.assoc(:grape).size.should == 2
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets the first element of the Array to the located key" do
|
18
|
+
@h.assoc(:banana).first.should == :banana
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets the last element of the Array to the value of the located key" do
|
22
|
+
@h.assoc(:banana).last.should == :yellow
|
23
|
+
end
|
24
|
+
|
25
|
+
it "only returns the first matching key-value pair for identity hashes" do
|
26
|
+
@h.compare_by_identity
|
27
|
+
@h['pear'] = :red
|
28
|
+
@h['pear'] = :green
|
29
|
+
@h.keys.grep(/pear/).size.should == 2
|
30
|
+
@h.assoc('pear').should == ['pear', :red]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "uses #== to compare the argument to the keys" do
|
34
|
+
@h[1.0] = :value
|
35
|
+
1.should == 1.0
|
36
|
+
@h.assoc(1).should == [1.0, :value]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns nil if the argument is not a key of the Hash" do
|
40
|
+
@h.assoc(:green).should be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
+
|
4
|
+
describe "Hash#clear" do
|
5
|
+
#it "returns itself" do
|
6
|
+
# h = new_hash(1 => 2, 3 => 4)
|
7
|
+
# h.clear.should equal(h)
|
8
|
+
#end
|
9
|
+
|
10
|
+
it "removes all key, value pairs" do
|
11
|
+
h = new_hash(1 => 2, 3 => 4)
|
12
|
+
h.clear
|
13
|
+
h.should == new_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
=begin default
|
17
|
+
it "does not remove default values" do
|
18
|
+
h = new_hash 5
|
19
|
+
h.clear
|
20
|
+
h.default.should == 5
|
21
|
+
|
22
|
+
h = new_hash("a" => 100, "b" => 200)
|
23
|
+
h.default = "Go fish"
|
24
|
+
h.clear
|
25
|
+
h["z"].should == "Go fish"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "does not remove default procs" do
|
29
|
+
h = new_hash { 5 }
|
30
|
+
h.clear
|
31
|
+
h.default_proc.should_not == nil
|
32
|
+
end
|
33
|
+
=end
|
34
|
+
|
35
|
+
=begin frozen
|
36
|
+
ruby_version_is ""..."1.9" do
|
37
|
+
it "raises a TypeError if called on a frozen instance" do
|
38
|
+
lambda { HashSpecs.frozen_hash.clear }.should raise_error(TypeError)
|
39
|
+
lambda { HashSpecs.empty_frozen_hash.clear }.should raise_error(TypeError)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
ruby_version_is "1.9" do
|
43
|
+
it "raises a RuntimeError if called on a frozen instance" do
|
44
|
+
lambda { HashSpecs.frozen_hash.clear }.should raise_error(RuntimeError)
|
45
|
+
lambda { HashSpecs.empty_frozen_hash.clear }.should raise_error(RuntimeError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
=end
|
49
|
+
end
|