strokedb 0.0.2.1 → 0.0.2.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/README +18 -20
- data/bench.html +4001 -0
- data/bin/strokedb +14 -0
- data/examples/movies.rb +105 -0
- data/examples/movies2.rb +97 -0
- data/examples/strokewiki/README +28 -0
- data/examples/strokewiki/view/edit.xhtml +27 -0
- data/examples/strokewiki/view/new.xhtml +26 -0
- data/examples/strokewiki/view/pages.xhtml +27 -0
- data/examples/strokewiki/view/show.xhtml +40 -0
- data/examples/strokewiki/view/versions.xhtml +25 -0
- data/examples/strokewiki/wiki.rb +106 -0
- data/examples/todo.rb +92 -0
- data/lib/strokedb.rb +85 -0
- data/lib/{config → strokedb}/config.rb +14 -9
- data/lib/strokedb/console.rb +87 -0
- data/lib/strokedb/core_ext.rb +10 -0
- data/lib/{util/ext → strokedb/core_ext}/blank.rb +1 -1
- data/lib/{util/ext → strokedb/core_ext}/enumerable.rb +0 -0
- data/lib/{util/ext → strokedb/core_ext}/fixnum.rb +0 -0
- data/lib/strokedb/core_ext/float.rb +4 -0
- data/lib/{util/ext → strokedb/core_ext}/hash.rb +0 -0
- data/lib/strokedb/core_ext/infinity.rb +33 -0
- data/lib/strokedb/core_ext/kernel.rb +41 -0
- data/lib/strokedb/core_ext/object.rb +16 -0
- data/lib/{util/ext → strokedb/core_ext}/string.rb +28 -1
- data/lib/strokedb/core_ext/symbol.rb +13 -0
- data/lib/strokedb/data_structures.rb +5 -0
- data/lib/strokedb/data_structures/chunked_skiplist.rb +123 -0
- data/lib/{data_structures → strokedb/data_structures}/inverted_list.rb +0 -0
- data/lib/{data_structures → strokedb/data_structures}/point_query.rb +0 -0
- data/lib/strokedb/data_structures/simple_skiplist.rb +350 -0
- data/lib/{data_structures → strokedb/data_structures}/skiplist.rb +1 -1
- data/lib/{document → strokedb}/document.rb +180 -71
- data/lib/{document → strokedb/document}/callback.rb +0 -0
- data/lib/{document → strokedb/document}/delete.rb +2 -2
- data/lib/strokedb/document/dsl.rb +4 -0
- data/lib/{document → strokedb/document/dsl}/associations.rb +0 -0
- data/lib/{document → strokedb/document/dsl}/coercions.rb +0 -0
- data/lib/strokedb/document/dsl/meta_dsl.rb +7 -0
- data/lib/{document → strokedb/document/dsl}/validations.rb +26 -21
- data/lib/{document → strokedb/document/dsl}/virtualize.rb +0 -0
- data/lib/{document → strokedb/document}/meta.rb +92 -29
- data/lib/{document → strokedb/document}/slot.rb +17 -5
- data/lib/{document → strokedb/document}/util.rb +0 -0
- data/lib/{document → strokedb/document}/versions.rb +2 -2
- data/lib/strokedb/index.rb +2 -0
- data/lib/strokedb/nsurl.rb +24 -0
- data/lib/strokedb/store.rb +149 -0
- data/lib/strokedb/stores.rb +6 -0
- data/lib/{stores → strokedb/stores}/chainable_storage.rb +20 -14
- data/lib/strokedb/stores/file_storage.rb +118 -0
- data/lib/{stores/inverted_list_index → strokedb/stores}/inverted_list_file_storage.rb +50 -0
- data/lib/strokedb/stores/memory_storage.rb +80 -0
- data/lib/{stores → strokedb/stores}/remote_store.rb +10 -4
- data/lib/strokedb/sync.rb +4 -0
- data/lib/{sync → strokedb/sync}/chain_sync.rb +0 -0
- data/lib/{sync → strokedb/sync}/diff.rb +12 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/array.rb +1 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/default.rb +0 -0
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/hash.rb +1 -1
- data/lib/{sync/stroke_diff → strokedb/sync/diff}/string.rb +1 -1
- data/lib/{sync → strokedb/sync}/lamport_timestamp.rb +0 -0
- data/lib/{sync → strokedb/sync}/store_sync.rb +15 -7
- data/lib/strokedb/transaction.rb +78 -0
- data/lib/{util → strokedb}/util.rb +14 -7
- data/lib/strokedb/util/attach_dsl.rb +29 -0
- data/lib/{util → strokedb/util}/blankslate.rb +0 -0
- data/lib/strokedb/util/class_optimization.rb +93 -0
- data/lib/{util → strokedb/util}/inflect.rb +0 -0
- data/lib/strokedb/util/java_util.rb +13 -0
- data/lib/{util → strokedb/util}/lazy_array.rb +0 -0
- data/lib/{util → strokedb/util}/lazy_mapping_array.rb +4 -0
- data/lib/{util → strokedb/util}/lazy_mapping_hash.rb +0 -0
- data/lib/{util → strokedb/util}/serialization.rb +21 -0
- data/lib/strokedb/util/uuid.rb +159 -0
- data/lib/{util → strokedb/util}/xml.rb +0 -0
- data/lib/{view → strokedb}/view.rb +2 -2
- data/lib/strokedb/volumes.rb +5 -0
- data/lib/strokedb/volumes/archive_volume.rb +165 -0
- data/lib/strokedb/volumes/block_volume.rb +169 -0
- data/lib/strokedb/volumes/distributed_pointer.rb +43 -0
- data/lib/strokedb/volumes/fixed_length_skiplist_volume.rb +109 -0
- data/lib/strokedb/volumes/map_volume.rb +268 -0
- data/meta/MANIFEST +175 -0
- data/script/console +2 -70
- data/spec/integration/remote_store_spec.rb +70 -0
- data/spec/integration/search_spec.rb +76 -0
- data/spec/integration/spec_helper.rb +1 -0
- data/spec/lib/spec_helper.rb +1 -0
- data/spec/lib/strokedb/config_spec.rb +250 -0
- data/spec/lib/strokedb/core_ext/blank_spec.rb +20 -0
- data/spec/lib/strokedb/core_ext/extract_spec.rb +42 -0
- data/spec/lib/strokedb/core_ext/float_spec.rb +62 -0
- data/spec/lib/strokedb/core_ext/infinity_spec.rb +40 -0
- data/spec/lib/strokedb/core_ext/spec_helper.rb +1 -0
- data/spec/lib/strokedb/core_ext/string_spec.rb +25 -0
- data/spec/lib/strokedb/core_ext/symbol_spec.rb +8 -0
- data/spec/lib/strokedb/data_structures/chunked_skiplist_spec.rb +144 -0
- data/spec/lib/strokedb/data_structures/inverted_list_spec.rb +172 -0
- data/spec/lib/strokedb/data_structures/simple_skiplist_spec.rb +200 -0
- data/spec/lib/strokedb/data_structures/skiplist_spec.rb +253 -0
- data/spec/lib/strokedb/data_structures/spec_helper.rb +1 -0
- data/spec/lib/strokedb/document/associations_spec.rb +319 -0
- data/spec/lib/strokedb/document/callbacks_spec.rb +134 -0
- data/spec/lib/strokedb/document/coercions_spec.rb +110 -0
- data/spec/lib/strokedb/document/document_spec.rb +1063 -0
- data/spec/lib/strokedb/document/meta_meta_spec.rb +30 -0
- data/spec/lib/strokedb/document/meta_spec.rb +435 -0
- data/spec/lib/strokedb/document/metaslot_spec.rb +43 -0
- data/spec/lib/strokedb/document/slot_spec.rb +130 -0
- data/spec/lib/strokedb/document/spec_helper.rb +1 -0
- data/spec/lib/strokedb/document/validations_spec.rb +1081 -0
- data/spec/lib/strokedb/document/virtualize_spec.rb +80 -0
- data/spec/lib/strokedb/nsurl_spec.rb +73 -0
- data/spec/lib/strokedb/spec_helper.rb +1 -0
- data/spec/lib/strokedb/stores/chained_storages_spec.rb +116 -0
- data/spec/lib/strokedb/stores/spec_helper.rb +1 -0
- data/spec/lib/strokedb/stores/store_spec.rb +201 -0
- data/spec/lib/strokedb/stores/transaction_spec.rb +107 -0
- data/spec/lib/strokedb/sync/chain_sync_spec.rb +43 -0
- data/spec/lib/strokedb/sync/diff_spec.rb +111 -0
- data/spec/lib/strokedb/sync/lamport_timestamp_spec.rb +174 -0
- data/spec/lib/strokedb/sync/slot_diff_spec.rb +164 -0
- data/spec/lib/strokedb/sync/spec_helper.rb +1 -0
- data/spec/lib/strokedb/sync/store_sync_spec.rb +181 -0
- data/spec/lib/strokedb/sync/stroke_diff/array_spec.rb +97 -0
- data/spec/lib/strokedb/sync/stroke_diff/complex_spec.rb +58 -0
- data/spec/lib/strokedb/sync/stroke_diff/hash_spec.rb +144 -0
- data/spec/lib/strokedb/sync/stroke_diff/scalar_spec.rb +23 -0
- data/spec/lib/strokedb/sync/stroke_diff/spec_helper.rb +25 -0
- data/spec/lib/strokedb/sync/stroke_diff/string_spec.rb +61 -0
- data/spec/lib/strokedb/util/attach_dsl_spec.rb +45 -0
- data/spec/lib/strokedb/util/inflect_spec.rb +14 -0
- data/spec/lib/strokedb/util/lazy_array_spec.rb +157 -0
- data/spec/lib/strokedb/util/lazy_mapping_array_spec.rb +174 -0
- data/spec/lib/strokedb/util/lazy_mapping_hash_spec.rb +92 -0
- data/spec/lib/strokedb/util/spec_helper.rb +1 -0
- data/spec/lib/strokedb/util/uuid_spec.rb +46 -0
- data/spec/lib/strokedb/view_spec.rb +228 -0
- data/spec/lib/strokedb/volumes/archive_volume_spec.rb +105 -0
- data/spec/lib/strokedb/volumes/block_volume_spec.rb +100 -0
- data/spec/lib/strokedb/volumes/distributed_pointer_spec.rb +14 -0
- data/spec/lib/strokedb/volumes/fixed_length_skiplist_volume_spec.rb +177 -0
- data/spec/lib/strokedb/volumes/map_volume_spec.rb +172 -0
- data/spec/lib/strokedb/volumes/spec_helper.rb +1 -0
- data/spec/regression/docref_spec.rb +94 -0
- data/spec/regression/meta_spec.rb +23 -0
- data/spec/regression/spec_helper.rb +1 -0
- data/spec/regression/sync_spec.rb +36 -0
- data/spec/spec.opts +7 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/temp/storages/TIMESTAMP +1 -0
- data/spec/temp/storages/UUID +1 -0
- data/spec/temp/storages/database-sync/TIMESTAMP +1 -0
- data/spec/temp/storages/database-sync/UUID +1 -0
- data/spec/temp/storages/database-sync/config +1 -0
- data/spec/temp/storages/database-sync/file/LAST +1 -0
- data/spec/temp/storages/database-sync/file/bd/f6/bdf675e5-8a7b-494e-97f2-f74a14ccd95d.av +0 -0
- data/spec/temp/storages/database-sync/file/uindex.wal +0 -0
- data/spec/temp/storages/database-sync/inverted_list_file/INVERTED_INDEX +1 -0
- data/spec/temp/storages/inverted_list_storage/INVERTED_INDEX +0 -0
- data/strokedb.gemspec +120 -0
- data/task/benchmark.task +9 -0
- data/task/ditz.task +30 -0
- data/task/echoe.rb +17 -0
- data/task/rcov.task +50 -0
- data/task/rdoc.task +10 -0
- data/task/rspec.task +0 -0
- data/vendor/java_inline.rb +106 -0
- data/vendor/rbmodexcl/mrimodexcl.rb +82 -0
- data/vendor/rbmodexcl/rbmodexcl.rb +5 -0
- data/vendor/rbmodexcl/rbxmodexcl.rb +48 -0
- data/vendor/rbmodexcl/spec/unextend_spec.rb +50 -0
- data/vendor/rbmodexcl/spec/uninclude_spec.rb +26 -0
- metadata +271 -79
- data/CONTRIBUTORS +0 -7
- data/CREDITS +0 -13
- data/bin/sdbc +0 -2
- data/lib/init.rb +0 -57
- data/lib/stores/inverted_list_index/inverted_list_index.rb +0 -49
- data/lib/stores/skiplist_store/chunk.rb +0 -119
- data/lib/stores/skiplist_store/chunk_storage.rb +0 -21
- data/lib/stores/skiplist_store/file_chunk_storage.rb +0 -44
- data/lib/stores/skiplist_store/memory_chunk_storage.rb +0 -37
- data/lib/stores/skiplist_store/skiplist_store.rb +0 -217
- data/lib/stores/store.rb +0 -5
- data/lib/sync/stroke_diff/stroke_diff.rb +0 -9
- data/lib/util/ext/object.rb +0 -8
- data/lib/util/java_util.rb +0 -9
- data/lib/util/trigger_partition.rb +0 -136
- data/strokedb.rb +0 -75
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Scalar diff" do
|
|
4
|
+
|
|
5
|
+
scalars = [
|
|
6
|
+
1, -1, 12345678901234567890,
|
|
7
|
+
3.1415926, 2.71828182, -0.333,
|
|
8
|
+
:sym1, :sym2,
|
|
9
|
+
false, true, nil,
|
|
10
|
+
Object.new, Object.new # okay, these are not scalaras, but relevant to the spec
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
scalars.each do |s1|
|
|
14
|
+
it "should patch scalar #{s1.inspect}" do
|
|
15
|
+
scalars.each do |s2|
|
|
16
|
+
s1.stroke_patch(s1.stroke_diff(s2)).should == s2
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# TODO: spec merging
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
|
2
|
+
|
|
3
|
+
def should_merge(base, a, b, r)
|
|
4
|
+
c, r1, r2 = base.stroke_merge(base.stroke_diff(a), base.stroke_diff(b))
|
|
5
|
+
c.should be_false
|
|
6
|
+
r1.should == r
|
|
7
|
+
r2.should == r
|
|
8
|
+
# another order
|
|
9
|
+
c, r1, r2 = base.stroke_merge(base.stroke_diff(b), base.stroke_diff(a))
|
|
10
|
+
c.should be_false
|
|
11
|
+
r1.should == r
|
|
12
|
+
r2.should == r
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def should_yield_conflict(base, a, b, ra, rb)
|
|
16
|
+
c, r1, r2 = base.stroke_merge(base.stroke_diff(a), base.stroke_diff(b))
|
|
17
|
+
c.should be_true
|
|
18
|
+
r1.should == ra
|
|
19
|
+
r2.should == rb
|
|
20
|
+
# another order
|
|
21
|
+
c, r1, r2 = base.stroke_merge(base.stroke_diff(b), base.stroke_diff(a))
|
|
22
|
+
c.should be_true
|
|
23
|
+
r1.should == rb
|
|
24
|
+
r2.should == ra
|
|
25
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "String diff" do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@str = "str"
|
|
7
|
+
@obj = Object.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should correctly patch string with string diff" do
|
|
11
|
+
2000.times {
|
|
12
|
+
from = gen_str
|
|
13
|
+
to = gen_str
|
|
14
|
+
from.stroke_patch(from.stroke_diff(to)).should == to
|
|
15
|
+
}
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
[ nil,
|
|
19
|
+
1, 2**64, -1.0,
|
|
20
|
+
:sym,
|
|
21
|
+
[:arr],
|
|
22
|
+
{:arr => 1},
|
|
23
|
+
@obj
|
|
24
|
+
].each do |obj|
|
|
25
|
+
it "should correctly patch string with a replacement #{obj.inspect}" do
|
|
26
|
+
@arr.stroke_patch(@arr.stroke_diff(obj)).should == obj
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def gen_str
|
|
31
|
+
letters = %w(a b c d)
|
|
32
|
+
str = ""
|
|
33
|
+
len = rand(letters.size*2)
|
|
34
|
+
len.times {
|
|
35
|
+
str << letters[rand(letters.size)]
|
|
36
|
+
}
|
|
37
|
+
str
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "String automerge" do
|
|
42
|
+
|
|
43
|
+
it "should do a trivial merge" do
|
|
44
|
+
# should_merge("abc", "abcd", "axc", "axcd")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def should_merge(base, a, b, r)
|
|
49
|
+
c, r1, r2 = base.stroke_merge(base.stroke_diff(a), base.stroke_diff(b))
|
|
50
|
+
c.should be_false
|
|
51
|
+
r1.should == r1
|
|
52
|
+
r2.should == r
|
|
53
|
+
# another order
|
|
54
|
+
c, r1, r2 = base.stroke_merge(base.stroke_diff(b), base.stroke_diff(a))
|
|
55
|
+
c.should be_false
|
|
56
|
+
r1.should == r1
|
|
57
|
+
r2.should == r
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "attach_dsl DSL :-)" do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
module MetaDSL
|
|
7
|
+
def on_initialize(&block)
|
|
8
|
+
store_dsl_options("on_initialize", block)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module HasMany
|
|
13
|
+
attach_dsl MetaDSL
|
|
14
|
+
def has_many(*args)
|
|
15
|
+
store_dsl_options("has_many", { :module => HasMany, :args => args } )
|
|
16
|
+
end
|
|
17
|
+
on_initialize do |doc|
|
|
18
|
+
blah_blah
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
module ValidatePresenceOf
|
|
23
|
+
attach_dsl MetaDSL
|
|
24
|
+
def validate_presence_of(*args)
|
|
25
|
+
store_dsl_options("validate_presence_of", { :module => ValidatePresenceOf, :args => args } )
|
|
26
|
+
end
|
|
27
|
+
on_initialize do |doc|
|
|
28
|
+
blah_blah
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
module App1
|
|
33
|
+
attach_dsl HasMany, ValidatePresenceOf
|
|
34
|
+
has_many :blah, :blah => :blah
|
|
35
|
+
validate_presence_of :blah, :blah
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "should return a list of DSL options" do
|
|
40
|
+
App1.dsl.keys.to_set.should == %w[has_many validate_presence_of].to_set
|
|
41
|
+
App1.dsl["has_many"].should == {:module => HasMany, :args => [:blah, {:blah => :blah}]}
|
|
42
|
+
App1.dsl["has_many"][:module].dsl["on_initialize"].should be_a_kind_of(Proc)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Inflect" do
|
|
4
|
+
|
|
5
|
+
it "#singular should return singular of word" do
|
|
6
|
+
English::Inflect.singular('boy').should == 'boy'
|
|
7
|
+
English::Inflect.singular('boys').should == 'boy'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "#prural should return plural of word" do
|
|
11
|
+
English::Inflect.plural('hive').should == 'hives'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "LazyArray instance" do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
@array = LazyArray.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should have class Array" do
|
|
10
|
+
# Make it look like array for outer world
|
|
11
|
+
@array.class.should == Array
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should be inherited from Array" do
|
|
15
|
+
@array.class.ancestors.first.should == Array
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
describe "LazyArray instance with block specified" do
|
|
22
|
+
|
|
23
|
+
before(:each) do
|
|
24
|
+
@loader = proc { [1,2,3] }
|
|
25
|
+
@array = LazyArray.new.load_with(&@loader)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should call loading proc on #[index]=" do
|
|
29
|
+
@array[0]="10"
|
|
30
|
+
@array.should == ["10",2,3]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should call loading proc on #[index]" do
|
|
34
|
+
@array[0].should == 1
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should call loading proc on #[start,length]" do
|
|
38
|
+
@array[0,2].should == [1,2]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should call loading proc on #[range]" do
|
|
42
|
+
@array[0..1].should == [1,2]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should call loading proc on #slice(index)" do
|
|
46
|
+
@array.slice(0).should == 1
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should call loading proc on #slice(start,length)" do
|
|
50
|
+
@array.slice(0,2).should == [1,2]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
it "should call loading proc on #slice(range)" do
|
|
55
|
+
@array.slice(0..1).should == [1,2]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "should call loading proc on #at(index)" do
|
|
59
|
+
@array.at(0).should == 1
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "should call loading proc on #first" do
|
|
63
|
+
@array.first.should == 1
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "should call loading proc on #last" do
|
|
67
|
+
@array.last.should == 3
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should yield mapped value in #each block" do
|
|
71
|
+
array_yielded = []
|
|
72
|
+
@array.each do |val|
|
|
73
|
+
array_yielded << val
|
|
74
|
+
end
|
|
75
|
+
array_yielded.should == [1,2,3]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it "should call loading proc on #each" do
|
|
79
|
+
i = 0
|
|
80
|
+
@array.each do |e|
|
|
81
|
+
e.should == [1,2,3][i]
|
|
82
|
+
i+=1
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should call loading proc on #each_with_index" do
|
|
87
|
+
@array.each_with_index do |e, i|
|
|
88
|
+
e.should == [1,2,3][i]
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should call loading proc on #inject" do
|
|
93
|
+
i = 0
|
|
94
|
+
@array.inject([]) do |c, e|
|
|
95
|
+
e.should == [1,2,3][i]
|
|
96
|
+
i += 1
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "should call loading proc on #map" do
|
|
101
|
+
i = 0
|
|
102
|
+
@array.map do |e|
|
|
103
|
+
e.should == [1,2,3][i]
|
|
104
|
+
i+=1
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "should call loading proc on #zip" do
|
|
109
|
+
@array.zip([1,2,3]).should == [1,2,3].zip([1,2,3])
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
it "should call unloading proc on #push" do
|
|
113
|
+
@array.push "10"
|
|
114
|
+
@array.should == [1,2,3,"10"]
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should call unloading proc on #<<" do
|
|
118
|
+
@array << "10"
|
|
119
|
+
@array.should == [1,2,3,"10"]
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it "should call unloading proc on #unshift" do
|
|
123
|
+
@array.unshift "10"
|
|
124
|
+
@array.should == ["10",1,2,3]
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "should call loading proc on #pop" do
|
|
128
|
+
@array.pop.should == 3
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "should call loading proc on #shift" do
|
|
132
|
+
@array.shift.should == 1
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should call loading proc on #inspect" do
|
|
136
|
+
@array.inspect
|
|
137
|
+
@array.should == [1,2,3]
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "should call loading proc on #find" do
|
|
141
|
+
@array.find{|v| v == 2}.should == 2
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "should call loading proc on #index" do
|
|
145
|
+
@array.index(2).should == 1
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
it "should call loading proc on #to_a" do
|
|
149
|
+
@array.to_a.should == [1,2,3]
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it "should call loading proc on #==" do
|
|
153
|
+
@array.should == [1,2,3]
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
end
|
|
157
|
+
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "LazyMappingArray instance" do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@array = LazyMappingArray.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "should have class Array" do
|
|
9
|
+
@array.class.should == Array
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should be inherited from Array" do
|
|
13
|
+
@array.class.ancestors.first.should == Array
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should work in case statements" do
|
|
17
|
+
@array.should be_a_kind_of(Array)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "LazyMappingArray instance with map/unmap specified" do
|
|
22
|
+
before(:each) do
|
|
23
|
+
@original = [1,2,3,[1],[2]]
|
|
24
|
+
@mapper = proc {|arg| arg.to_s }
|
|
25
|
+
@unmapper = proc {|arg| arg.to_i }
|
|
26
|
+
@array = LazyMappingArray.new(@original).map_with(&@mapper).unmap_with(&@unmapper)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should call unmapping proc on #[index]=" do
|
|
30
|
+
@array[0]="10"
|
|
31
|
+
Array.new(@array).first.should == 10
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should work with #[index]=(array)" do
|
|
35
|
+
@array[1,0] = %w[ 1 2 3 ]
|
|
36
|
+
@original[1,0] = [1,2,3]
|
|
37
|
+
# TODO: huge bug inside!
|
|
38
|
+
# p @array
|
|
39
|
+
# p @array.to_a
|
|
40
|
+
# p @original
|
|
41
|
+
# p @original.map(&@mapper)
|
|
42
|
+
@array.to_a.should == @original.map(&@mapper)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should call mapping proc on #[index]" do
|
|
46
|
+
@array[0].should == @mapper.call(@original[0])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should call mapping proc on #[start,length]" do
|
|
50
|
+
@array[0,2].to_a.should == @original[0,2].map(&@mapper)
|
|
51
|
+
@array[3,2].to_a.should == @original[3,2].map(&@mapper)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should call mapping proc on #[range]" do
|
|
55
|
+
@array[0..1].to_a.should == @original[0..1].map(&@mapper)
|
|
56
|
+
@array[3..4].to_a.should == @original[3..4].map(&@mapper)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should call mapping proc on #slice(index)" do
|
|
60
|
+
@array.slice(0).should == @mapper.call(@original.slice(0))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should call mapping proc on #slice(start,length)" do
|
|
64
|
+
@array.slice(0,2).to_a.should == @original.slice(0,2).map(&@mapper)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should call mapping proc on #slice(range)" do
|
|
68
|
+
@array.slice(0..1).to_a.should == @original.slice(0..1).map(&@mapper)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "should call mapping proc on #at(index)" do
|
|
72
|
+
@array.at(0).should == @mapper.call(@original.at(0))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "should call mapping proc on #first" do
|
|
76
|
+
@array.first.should == @mapper.call(@original.first)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it "should call mapping proc on #last" do
|
|
80
|
+
@array.last.should == @mapper.call(@original.last)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "should yield mapped value in #each block" do
|
|
84
|
+
mapped_original = []
|
|
85
|
+
@original.each do |val|
|
|
86
|
+
mapped_original << @mapper.call(val)
|
|
87
|
+
end
|
|
88
|
+
array_yielded = []
|
|
89
|
+
@array.each do |val|
|
|
90
|
+
array_yielded << val
|
|
91
|
+
end
|
|
92
|
+
array_yielded.should == mapped_original
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it "should call mapping proc on #each" do
|
|
96
|
+
i = 0
|
|
97
|
+
@array.each do |e|
|
|
98
|
+
e.should == @mapper.call(@original[i])
|
|
99
|
+
i+=1
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should call mapping proc on #each_with_index" do
|
|
104
|
+
@array.each_with_index do |e, i|
|
|
105
|
+
e.should == @mapper.call(@original[i])
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should call mapping proc on #inject" do
|
|
110
|
+
i = 0
|
|
111
|
+
@array.inject([]) do |c, e|
|
|
112
|
+
e.should == @mapper.call(@original[i])
|
|
113
|
+
i+=1
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should call mapping proc on #map" do
|
|
118
|
+
i = 0
|
|
119
|
+
@array.map do |e|
|
|
120
|
+
e.should == @mapper.call(@original[i])
|
|
121
|
+
i+=1
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should call mapping proc on #zip" do
|
|
126
|
+
@array.zip(@original){|a, o| a.should == @mapper.call(o) }
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it "should call unmapping proc on #push" do
|
|
130
|
+
@array.push "10"
|
|
131
|
+
Array.new(@array).last.should == 10
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "should call unmapping proc on #<<" do
|
|
135
|
+
@array << "10"
|
|
136
|
+
Array.new(@array).last.should == 10
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "should call unmapping proc on #unshift" do
|
|
140
|
+
@array.unshift "10"
|
|
141
|
+
Array.new(@array).first.should == 10
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it "should call mapping proc on #pop" do
|
|
145
|
+
@array << "10"
|
|
146
|
+
@array.pop.should == "10"
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it "should call mapping proc on #shift" do
|
|
150
|
+
@array[0] = "10"
|
|
151
|
+
@array.shift.should == "10"
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it "should call mapping proc on #index" do
|
|
155
|
+
@array.index(1).should == 0
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it "should call unmapping proc on #-" do
|
|
159
|
+
@array << "20"
|
|
160
|
+
@array << "10"
|
|
161
|
+
@array = @array - ["10"]
|
|
162
|
+
Array.new(@array).last.should == 20
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it "should call unmapping proc on #include?" do
|
|
166
|
+
@array.should include("1")
|
|
167
|
+
@array.should_not include("10")
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
it "should be == to similar non-lazy array" do
|
|
171
|
+
@array.should == @original.map{|v| @mapper.call(v)}
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
end
|