picky 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/lib/picky/backends/file/basic.rb +10 -80
  2. data/lib/picky/backends/file/json.rb +56 -15
  3. data/lib/picky/backends/file.rb +62 -0
  4. data/lib/picky/backends/memory/basic.rb +111 -0
  5. data/lib/picky/backends/memory/json.rb +41 -0
  6. data/lib/picky/backends/{file → memory}/marshal.rb +4 -1
  7. data/lib/picky/backends/{file → memory}/text.rb +5 -1
  8. data/lib/picky/backends/memory.rb +16 -6
  9. data/lib/picky/backends/redis/{float_hash.rb → float.rb} +1 -1
  10. data/lib/picky/backends/redis/{list_hash.rb → list.rb} +1 -1
  11. data/lib/picky/backends/redis/{string_hash.rb → string.rb} +1 -1
  12. data/lib/picky/backends/redis.rb +16 -6
  13. data/lib/picky/bundle.rb +5 -2
  14. data/lib/picky/category.rb +1 -1
  15. data/lib/picky/cores.rb +7 -0
  16. data/lib/picky/extensions/symbol.rb +22 -0
  17. data/lib/picky/generators/partial/infix.rb +93 -0
  18. data/lib/picky/generators/partial/substring.rb +2 -2
  19. data/lib/picky/indexes_indexing.rb +2 -0
  20. data/lib/picky/indexing/bundle.rb +1 -1
  21. data/lib/picky/loader.rb +11 -6
  22. data/lib/picky/migrations/from_30_to_31.rb +2 -2
  23. data/lib/picky/query/allocation.rb +1 -0
  24. data/lib/picky/query/combinations.rb +3 -1
  25. data/spec/lib/backends/{file → memory}/basic_spec.rb +3 -3
  26. data/spec/lib/backends/{file → memory}/json_spec.rb +3 -3
  27. data/spec/lib/backends/{file → memory}/marshal_spec.rb +3 -3
  28. data/spec/lib/backends/{file → memory}/text_spec.rb +1 -1
  29. data/spec/lib/backends/memory_spec.rb +4 -4
  30. data/spec/lib/backends/redis/{float_hash_spec.rb → float_spec.rb} +2 -2
  31. data/spec/lib/backends/redis/{list_hash_spec.rb → list_spec.rb} +2 -2
  32. data/spec/lib/backends/redis/{string_hash_spec.rb → string_spec.rb} +2 -2
  33. data/spec/lib/backends/redis_spec.rb +4 -4
  34. data/spec/lib/bundle_spec.rb +27 -0
  35. data/spec/lib/extensions/symbol_spec.rb +237 -1
  36. data/spec/lib/generators/partial/infix_spec.rb +233 -0
  37. data/spec/lib/indexed/memory_spec.rb +8 -8
  38. data/spec/lib/query/allocation_spec.rb +7 -5
  39. metadata +30 -22
@@ -0,0 +1,93 @@
1
+ module Picky
2
+
3
+ module Generators
4
+
5
+ module Partial
6
+
7
+ # The subtoken partial strategy.
8
+ #
9
+ # If given "florian"
10
+ # it will index "floria", "flori", "flor", "flo", "fl", "f"
11
+ # (Depending on what the given from value is, the example is with option from: 1)
12
+ #
13
+ class Infix < Strategy
14
+
15
+ attr_reader :min,
16
+ :max
17
+
18
+ # The min option signifies with what size it
19
+ # will start in generating the infix tokens.
20
+ #
21
+ # Examples:
22
+ #
23
+ # With :hello, and max: -1 (default)
24
+ # * min: 1 # => [:hello, :hell, :ello, :hel, :ell, :llo, :he, :el, :ll, :lo, :h, :e, :l, :l, :o]
25
+ # * min: 4 # => [:hello, :hell, :ello]
26
+ #
27
+ # With :hello, and max: -2
28
+ # * min: 1 # => [:hell, :ello, :hel, :ell, :llo, :he, :el, :ll, :lo, :h, :e, :l, :l, :o]
29
+ # * min: 4 # => [:hell, :ello]
30
+ #
31
+ # (min 1 is default)
32
+ #
33
+ def initialize options = {}
34
+ @min = options[:min] || 1
35
+ @max = options[:max] || -1
36
+ end
37
+
38
+ # Generates a partial index from the given inverted index.
39
+ #
40
+ def generate_from inverted
41
+ result = {}
42
+
43
+ # Generate for each key token the subtokens.
44
+ #
45
+ i = 0
46
+ j = 0
47
+ inverted.each_key do |token|
48
+ i += 1
49
+ if i == 5000
50
+ j += 1
51
+ timed_exclaim %Q{#{"%8i" % (i*j)} generated (current token: "#{token}").}
52
+ i = 0
53
+ end
54
+ generate_for token, inverted, result
55
+ end
56
+
57
+ # Remove duplicate ids.
58
+ #
59
+ # THINK If it is unique for a subtoken, it is
60
+ # unique for all derived longer tokens.
61
+ #
62
+ result.each_value &:uniq!
63
+
64
+ result
65
+ end
66
+
67
+ private
68
+
69
+ # To each shortened token of :test
70
+ # :test, :tes, :te, :t
71
+ # add all ids of :test
72
+ #
73
+ # "token" here means just text.
74
+ #
75
+ # THINK Could be improved by appending the aforegoing ids?
76
+ #
77
+ def generate_for token, inverted, result
78
+ token.each_intoken(min, max) do |intoken|
79
+ if result[intoken]
80
+ result[intoken] += inverted[token] # unique
81
+ else
82
+ result[intoken] = inverted[token].dup
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+
93
+ end
@@ -49,8 +49,8 @@ module Picky
49
49
  # * from: 4 # => [:hell]
50
50
  #
51
51
  def initialize options = {}
52
- from = options[:from] || 1
53
- to = options[:to] || -1
52
+ from = options[:from] || 1
53
+ to = options[:to] || -1
54
54
  @generator = SubstringGenerator.new from, to
55
55
  end
56
56
 
@@ -35,6 +35,8 @@ module Picky
35
35
  # For integration testing – indexes for the tests
36
36
  # without forking and shouting ;)
37
37
  #
38
+ # TODO Rename to #index_without_forking, or just #index.
39
+ #
38
40
  def index_for_tests
39
41
  indexes.each(&:index)
40
42
  end
@@ -46,7 +46,7 @@ module Picky
46
46
  @weights_strategy = weights_strategy
47
47
  @partial_strategy = partial_strategy
48
48
  @key_format = options[:key_format]
49
- @prepared = Backends::File::Text.new category.prepared_index_path
49
+ @prepared = Backends::Memory::Text.new category.prepared_index_path
50
50
 
51
51
  @inverted = {}
52
52
  @weights = {}
data/lib/picky/loader.rb CHANGED
@@ -83,6 +83,7 @@ module Picky
83
83
  load_relative 'generators/partial/strategy'
84
84
  load_relative 'generators/partial/none'
85
85
  load_relative 'generators/partial/substring'
86
+ load_relative 'generators/partial/infix'
86
87
  load_relative 'generators/partial/default'
87
88
 
88
89
  # Weight index generation strategies.
@@ -114,15 +115,19 @@ module Picky
114
115
 
115
116
  load_relative 'backends/redis'
116
117
  load_relative 'backends/redis/basic'
117
- load_relative 'backends/redis/list_hash'
118
- load_relative 'backends/redis/string_hash'
119
- load_relative 'backends/redis/float_hash'
118
+ load_relative 'backends/redis/list'
119
+ load_relative 'backends/redis/string'
120
+ load_relative 'backends/redis/float'
120
121
 
122
+ load_relative 'backends/memory'
123
+ load_relative 'backends/memory/basic'
124
+ load_relative 'backends/memory/text'
125
+ load_relative 'backends/memory/marshal'
126
+ load_relative 'backends/memory/json'
127
+
128
+ load_relative 'backends/file'
121
129
  load_relative 'backends/file/basic'
122
- load_relative 'backends/file/text'
123
- load_relative 'backends/file/marshal'
124
130
  load_relative 'backends/file/json'
125
- load_relative 'backends/memory'
126
131
 
127
132
  # Indexing and Indexed things.
128
133
  #
@@ -31,7 +31,7 @@ MESSAGE
31
31
  class Redis
32
32
 
33
33
  def initialize(*)
34
- raise <<-RAISE
34
+ raise <<-MESSAGE
35
35
 
36
36
  The Picky::Indexes::Redis is not available anymore and has been replaced by Picky::Index.
37
37
  (with the addition of a "backend" option)
@@ -51,7 +51,7 @@ use
51
51
 
52
52
  Thanks and sorry for the inconvenience!
53
53
 
54
- RAISE
54
+ MESSAGE
55
55
  end
56
56
 
57
57
  end
@@ -38,6 +38,7 @@ module Picky
38
38
  # Asks the backend for the (intersected) ids.
39
39
  #
40
40
  def calculate_ids amount, offset
41
+ return [] if combinations.empty?
41
42
  @backend.ids combinations, amount, offset
42
43
  end
43
44
 
@@ -13,7 +13,9 @@ module Picky
13
13
 
14
14
  attr_reader :combinations
15
15
 
16
- delegate :empty?, :inject, :to => :@combinations
16
+ delegate :empty?,
17
+ :inject,
18
+ :to => :@combinations
17
19
 
18
20
  def initialize combinations = []
19
21
  @combinations = combinations
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Backends::File::Basic do
3
+ describe Picky::Backends::Memory::Basic do
4
4
 
5
5
  let(:file) { described_class.new 'some/cache/path/to/file' }
6
6
 
7
7
  describe 'backup_file_path_of' do
8
8
  it 'returns a backup path relative to the path' do
9
- file.backup_file_path_of('some/path/to/some.index').should == 'some/path/to/backup/some.index'
9
+ file.backup_file_path_of('some/path/to/some.memory.index').should == 'some/path/to/backup/some.memory.index'
10
10
  end
11
11
  end
12
12
 
@@ -18,7 +18,7 @@ describe Picky::Backends::File::Basic do
18
18
 
19
19
  describe 'to_s' do
20
20
  it 'returns the cache path with the default file extension' do
21
- file.to_s.should == 'Picky::Backends::File::Basic(some/cache/path/to/file.index)'
21
+ file.to_s.should == 'Picky::Backends::Memory::Basic(some/cache/path/to/file.memory.index)'
22
22
  end
23
23
  end
24
24
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Backends::File::JSON do
3
+ describe Picky::Backends::Memory::JSON do
4
4
 
5
5
  let(:file) { described_class.new 'some/cache/path/to/file' }
6
6
 
@@ -8,7 +8,7 @@ describe Picky::Backends::File::JSON do
8
8
  it "delegates to the given hash" do
9
9
  hash = stub :hash
10
10
 
11
- hash.should_receive(:dump_json).once.with "some/cache/path/to/file.json"
11
+ hash.should_receive(:dump_json).once.with "some/cache/path/to/file.memory.json"
12
12
 
13
13
  file.dump hash
14
14
  end
@@ -24,7 +24,7 @@ describe Picky::Backends::File::JSON do
24
24
 
25
25
  describe 'to_s' do
26
26
  it 'returns the cache path with the default file extension' do
27
- file.to_s.should == 'Picky::Backends::File::JSON(some/cache/path/to/file.json)'
27
+ file.to_s.should == 'Picky::Backends::Memory::JSON(some/cache/path/to/file.memory.json)'
28
28
  end
29
29
  end
30
30
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Backends::File::Marshal do
3
+ describe Picky::Backends::Memory::Marshal do
4
4
 
5
5
  let(:file) { described_class.new 'some/cache/path/to/file' }
6
6
 
@@ -8,7 +8,7 @@ describe Picky::Backends::File::Marshal do
8
8
  it "delegates to the given hash" do
9
9
  hash = stub :hash
10
10
 
11
- hash.should_receive(:dump_marshal).once.with "some/cache/path/to/file.dump"
11
+ hash.should_receive(:dump_marshal).once.with "some/cache/path/to/file.memory.dump"
12
12
 
13
13
  file.dump hash
14
14
  end
@@ -24,7 +24,7 @@ describe Picky::Backends::File::Marshal do
24
24
 
25
25
  describe 'to_s' do
26
26
  it 'returns the cache path with the default file extension' do
27
- file.to_s.should == 'Picky::Backends::File::Marshal(some/cache/path/to/file.dump)'
27
+ file.to_s.should == 'Picky::Backends::Memory::Marshal(some/cache/path/to/file.memory.dump)'
28
28
  end
29
29
  end
30
30
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Backends::File::Text do
3
+ describe Picky::Backends::Memory::Text do
4
4
 
5
5
  before(:each) do
6
6
  @file = described_class.new "some_cache_path"
@@ -10,10 +10,10 @@ describe Picky::Backends::Memory do
10
10
 
11
11
  describe 'create_...' do
12
12
  [
13
- [:inverted, Picky::Backends::File::JSON],
14
- [:weights, Picky::Backends::File::JSON],
15
- [:similarity, Picky::Backends::File::Marshal],
16
- [:configuration, Picky::Backends::File::JSON]
13
+ [:inverted, Picky::Backends::Memory::JSON],
14
+ [:weights, Picky::Backends::Memory::JSON],
15
+ [:similarity, Picky::Backends::Memory::Marshal],
16
+ [:configuration, Picky::Backends::Memory::JSON]
17
17
  ].each do |type, kind|
18
18
  it "creates and returns a(n) #{type} index" do
19
19
  @backend.send(:"create_#{type}",
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Backends::Redis::FloatHash do
3
+ describe Picky::Backends::Redis::Float do
4
4
 
5
5
  let(:client) { stub :client }
6
6
  let(:backend) { described_class.new client, :some_namespace }
@@ -31,7 +31,7 @@ describe Picky::Backends::Redis::FloatHash do
31
31
 
32
32
  describe 'to_s' do
33
33
  it 'returns the cache path with the default file extension' do
34
- backend.to_s.should == 'Picky::Backends::Redis::FloatHash(some_namespace:*)'
34
+ backend.to_s.should == 'Picky::Backends::Redis::Float(some_namespace:*)'
35
35
  end
36
36
  end
37
37
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Backends::Redis::ListHash do
3
+ describe Picky::Backends::Redis::List do
4
4
 
5
5
  let(:client) { stub :client }
6
6
  let(:index) { described_class.new client, :some_namespace }
@@ -20,7 +20,7 @@ describe Picky::Backends::Redis::ListHash do
20
20
 
21
21
  describe 'to_s' do
22
22
  it 'returns the cache path with the default file extension' do
23
- index.to_s.should == 'Picky::Backends::Redis::ListHash(some_namespace:*)'
23
+ index.to_s.should == 'Picky::Backends::Redis::List(some_namespace:*)'
24
24
  end
25
25
  end
26
26
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Backends::Redis::StringHash do
3
+ describe Picky::Backends::Redis::String do
4
4
 
5
5
  let(:client) { stub :client }
6
6
  let(:backend) { described_class.new client, :some_namespace }
@@ -31,7 +31,7 @@ describe Picky::Backends::Redis::StringHash do
31
31
 
32
32
  describe 'to_s' do
33
33
  it 'returns the cache path with the default file extension' do
34
- backend.to_s.should == 'Picky::Backends::Redis::StringHash(some_namespace:*)'
34
+ backend.to_s.should == 'Picky::Backends::Redis::String(some_namespace:*)'
35
35
  end
36
36
  end
37
37
 
@@ -10,10 +10,10 @@ describe Picky::Backends::Redis do
10
10
 
11
11
  describe 'create_...' do
12
12
  [
13
- [:inverted, Picky::Backends::Redis::ListHash],
14
- [:weights, Picky::Backends::Redis::FloatHash],
15
- [:similarity, Picky::Backends::Redis::ListHash],
16
- [:configuration, Picky::Backends::Redis::StringHash]
13
+ [:inverted, Picky::Backends::Redis::List],
14
+ [:weights, Picky::Backends::Redis::Float],
15
+ [:similarity, Picky::Backends::Redis::List],
16
+ [:configuration, Picky::Backends::Redis::String]
17
17
  ].each do |type, kind|
18
18
  it "creates and returns a(n) #{type} index" do
19
19
  @backend.send(:"create_#{type}",
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Bundle do
4
+
5
+ before(:each) do
6
+ @index = Picky::Index.new :some_index
7
+ @category = Picky::Category.new :some_category, @index
8
+ @similarity = Picky::Similarity::DoubleMetaphone.new 3
9
+ end
10
+ let(:bundle) { described_class.new :some_name, @category, Picky::Backends::Memory.new, @similarity }
11
+
12
+ describe 'identifier' do
13
+ it 'is correct' do
14
+ bundle.identifier.should == 'test:some_index:some_category:some_name'
15
+ end
16
+ end
17
+
18
+ describe 'index_path' do
19
+ it 'is correct' do
20
+ bundle.index_path(:some_type).should == 'spec/test_directory/index/test/some_index/some_category_some_name_some_type'
21
+ end
22
+ it 'is correct' do
23
+ bundle.index_path.should == 'spec/test_directory/index/test/some_index/some_category_some_name'
24
+ end
25
+ end
26
+
27
+ end
@@ -9,9 +9,245 @@ describe Symbol do
9
9
  before(:each) do
10
10
  @token = (((0..9).to_a)*10).to_s.to_sym
11
11
  end
12
- it "should be fast" do
12
+ it "is fast" do
13
13
  performance_of { @token.each_subtoken { |subtoken| } }.should < 0.00065
14
14
  end
15
+ it 'is fast enough' do
16
+ performance_of { @token.each_intoken { |intoken| } }.should < 0.025 # TODO Slow!
17
+ end
18
+ end
19
+
20
+ describe 'each_intoken' do
21
+ context 'normal symbol' do
22
+ before(:each) do
23
+ @sym = :picky
24
+ end
25
+ context 'no params' do
26
+ it "yields the right elements" do
27
+ result = []
28
+ @sym.each_intoken do |subtoken|
29
+ result << subtoken
30
+ end
31
+ result.should == [:picky, :pick, :icky, :pic, :ick, :cky, :pi, :ic, :ck, :ky, :p, :i, :c, :k, :y]
32
+ end
33
+ end
34
+ context 'with min_length == 0' do
35
+ it "yields the right elements" do
36
+ result = []
37
+ @sym.each_intoken(0) do |subtoken|
38
+ result << subtoken
39
+ end
40
+ result.should == [:picky, :pick, :icky, :pic, :ick, :cky, :pi, :ic, :ck, :ky, :p, :i, :c, :k, :y]
41
+ end
42
+ context 'max_length == 0' do
43
+ it 'yields the right elements' do
44
+ result = []
45
+ @sym.each_intoken(0, 0) do |subtoken|
46
+ result << subtoken
47
+ end
48
+ result.should == [:p, :i, :c, :k, :y]
49
+ end
50
+ end
51
+ context 'max_length == 1' do
52
+ it 'yields the right elements' do
53
+ result = []
54
+ @sym.each_intoken(0, 1) do |subtoken|
55
+ result << subtoken
56
+ end
57
+ result.should == [:p, :i, :c, :k, :y]
58
+ end
59
+ end
60
+ context 'max_length == 2' do
61
+ it 'yields the right elements' do
62
+ result = []
63
+ @sym.each_intoken(0, 2) do |subtoken|
64
+ result << subtoken
65
+ end
66
+ result.should == [:pi, :ic, :ck, :ky, :p, :i, :c, :k, :y]
67
+ end
68
+ end
69
+ context 'max_length == 10' do
70
+ it 'yields the right elements' do
71
+ result = []
72
+ @sym.each_intoken(0, 10) do |subtoken|
73
+ result << subtoken
74
+ end
75
+ result.should == [:picky, :pick, :icky, :pic, :ick, :cky, :pi, :ic, :ck, :ky, :p, :i, :c, :k, :y]
76
+ end
77
+ end
78
+ context 'max_length == -1' do
79
+ it 'yields the right elements' do
80
+ result = []
81
+ @sym.each_intoken(0, -1) do |subtoken|
82
+ result << subtoken
83
+ end
84
+ result.should == [:picky, :pick, :icky, :pic, :ick, :cky, :pi, :ic, :ck, :ky, :p, :i, :c, :k, :y]
85
+ end
86
+ end
87
+ end
88
+ context 'with min_length == sym.size' do
89
+ it "yields the right elements" do
90
+ result = []
91
+ @sym.each_intoken(@sym.size) do |subtoken|
92
+ result << subtoken
93
+ end
94
+ result.should == [:picky]
95
+ end
96
+ context 'max_length == 0' do
97
+ it 'yields the right elements' do
98
+ result = []
99
+ @sym.each_intoken(@sym.size, 0) do |subtoken|
100
+ result << subtoken
101
+ end
102
+ result.should == []
103
+ end
104
+ end
105
+ context 'max_length == 1' do
106
+ it 'yields the right elements' do
107
+ result = []
108
+ @sym.each_intoken(@sym.size, 1) do |subtoken|
109
+ result << subtoken
110
+ end
111
+ result.should == []
112
+ end
113
+ end
114
+ context 'max_length == 2' do
115
+ it 'yields the right elements' do
116
+ result = []
117
+ @sym.each_intoken(@sym.size, 2) do |subtoken|
118
+ result << subtoken
119
+ end
120
+ result.should == []
121
+ end
122
+ end
123
+ context 'max_length == 10' do
124
+ it 'yields the right elements' do
125
+ result = []
126
+ @sym.each_intoken(@sym.size, 10) do |subtoken|
127
+ result << subtoken
128
+ end
129
+ result.should == [:picky]
130
+ end
131
+ end
132
+ context 'max_length == -1' do
133
+ it 'yields the right elements' do
134
+ result = []
135
+ @sym.each_intoken(@sym.size, -1) do |subtoken|
136
+ result << subtoken
137
+ end
138
+ result.should == [:picky]
139
+ end
140
+ end
141
+ end
142
+ context 'with min_length > sym.size' do
143
+ it "yields the right elements" do
144
+ result = []
145
+ @sym.each_intoken(@sym.size+1) do |subtoken|
146
+ result << subtoken
147
+ end
148
+ result.should == []
149
+ end
150
+ context 'max_length == 0' do
151
+ it 'yields the right elements' do
152
+ result = []
153
+ @sym.each_intoken(@sym.size+1, 0) do |subtoken|
154
+ result << subtoken
155
+ end
156
+ result.should == []
157
+ end
158
+ end
159
+ context 'max_length == 1' do
160
+ it 'yields the right elements' do
161
+ result = []
162
+ @sym.each_intoken(@sym.size+1, 1) do |subtoken|
163
+ result << subtoken
164
+ end
165
+ result.should == []
166
+ end
167
+ end
168
+ context 'max_length == 2' do
169
+ it 'yields the right elements' do
170
+ result = []
171
+ @sym.each_intoken(@sym.size+1, 2) do |subtoken|
172
+ result << subtoken
173
+ end
174
+ result.should == []
175
+ end
176
+ end
177
+ context 'max_length == 10' do
178
+ it 'yields the right elements' do
179
+ result = []
180
+ @sym.each_intoken(@sym.size+1, 10) do |subtoken|
181
+ result << subtoken
182
+ end
183
+ result.should == []
184
+ end
185
+ end
186
+ context 'max_length == -1' do
187
+ it 'yields the right elements' do
188
+ result = []
189
+ @sym.each_intoken(@sym.size+1, -1) do |subtoken|
190
+ result << subtoken
191
+ end
192
+ result.should == []
193
+ end
194
+ end
195
+ end
196
+ context 'with min_length < 0' do
197
+ it "yields the right elements" do
198
+ result = []
199
+ @sym.each_intoken(-2) do |subtoken|
200
+ result << subtoken
201
+ end
202
+ result.should == [:picky, :pick, :icky]
203
+ end
204
+ context 'max_length == 0' do
205
+ it 'yields the right elements' do
206
+ result = []
207
+ @sym.each_intoken(-2, 0) do |subtoken|
208
+ result << subtoken
209
+ end
210
+ result.should == []
211
+ end
212
+ end
213
+ context 'max_length == 1' do
214
+ it 'yields the right elements' do
215
+ result = []
216
+ @sym.each_intoken(-2, 1) do |subtoken|
217
+ result << subtoken
218
+ end
219
+ result.should == []
220
+ end
221
+ end
222
+ context 'max_length == 2' do
223
+ it 'yields the right elements' do
224
+ result = []
225
+ @sym.each_intoken(-2, 2) do |subtoken|
226
+ result << subtoken
227
+ end
228
+ result.should == []
229
+ end
230
+ end
231
+ context 'max_length == 10' do
232
+ it 'yields the right elements' do
233
+ result = []
234
+ @sym.each_intoken(-2, 10) do |subtoken|
235
+ result << subtoken
236
+ end
237
+ result.should == [:picky, :pick, :icky]
238
+ end
239
+ end
240
+ context 'max_length == -1' do
241
+ it 'yields the right elements' do
242
+ result = []
243
+ @sym.each_intoken(-2, -1) do |subtoken|
244
+ result << subtoken
245
+ end
246
+ result.should == [:picky, :pick, :icky]
247
+ end
248
+ end
249
+ end
250
+ end
15
251
  end
16
252
 
17
253
  describe "each_subtoken" do