public
Fork of bruce/keyword_search
Description: Generic support for extracting GMail-style search keywords/values from strings
Homepage: http://codefluency.rubyforge.org/keyword_search
Clone URL: git://github.com/technoweenie/keyword_search.git
Ragel conversion; prep for 1.3.0

git-svn-id: 
svn+ssh://rubyforge.org/var/svn/codefluency/keyword_search/trunk@33 
a36c4c08-a44a-49c9-8a5d-6074d9d18ea7
wbruce (author)
Tue Oct 09 00:49:35 -0700 2007
commit  f0cad1153e1f62e7b031b34140f1249fd2e8a55d
tree    0d50188f6d4568908ba553bce81c0e01da5d06a6
parent  8c68fbc89ba31c5d2a5dabdeaf63c6c1ece19b50
...
 
 
 
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -1,3 +1,11 @@
0
+= 1.3.0 / 2007-10-09
0
+
0
+* Conversion to Ragel-based parser (faster, less resource-intensive)
0
+* Better support for other character sets, allow apostrophes in
0
+ unquoted words
0
+* Test suite now uses test/spec
0
+* API Should be backwards compatible
0
+
0
 = 1.2.0 / 2007-05-09
0
 
0
 * Raises KeywordSearch::ParseError instead of returning an empty Hash if an error occurs during parsing
...
3
4
5
 
6
7
8
9
10
11
12
...
3
4
5
6
7
 
 
 
 
8
9
0
@@ -3,9 +3,6 @@ Manifest.txt
0
 README.txt
0
 Rakefile
0
 lib/keyword_search.rb
0
+lib/keyword_search.rl
0
 lib/keyword_search/definition.rb
0
-lib/keyword_search/evaluator.rb
0
-lib/keyword_search/grammar.rb
0
-lib/keyword_search/parser.rb
0
-lib/keyword_search/tokenizer.rb
0
 test/test_keyword_search.rb
0
\ No newline at end of file
...
17
18
19
20
21
22
23
24
...
59
60
61
62
63
64
65
...
17
18
19
 
 
20
21
22
...
57
58
59
 
60
61
62
0
@@ -17,8 +17,6 @@ Various notes:
0
 * Input is automatically downcased (both keywords and values should be assumed to be in lowercase)
0
 
0
 Development Roadmap:
0
-1.1:: Expand supported character set for keywords and values
0
- (currently supports a-z)
0
 2.0:: Add negation and grouping (will break API backwards compatibility)
0
 
0
 == SYNOPSIS:
0
@@ -59,7 +57,6 @@ Here's an example of usage from Rails (though the library is generic, and could
0
 
0
 == REQUIREMENTS:
0
 
0
-* dhaka
0
 * hoe
0
 
0
 == INSTALL:
...
2
3
4
5
6
7
 
8
9
10
...
12
13
14
15
16
17
18
19
20
21
22
23
 
 
24
25
26
27
 
28
...
2
3
4
 
5
 
6
7
8
9
...
11
12
13
 
14
15
 
 
 
 
 
 
16
17
18
19
 
 
20
21
0
@@ -2,9 +2,8 @@
0
 
0
 require 'rubygems'
0
 require 'hoe'
0
-require './lib/keyword_search.rb'
0
 
0
-Hoe.new('keyword_search', KeywordSearch::VERSION) do |p|
0
+Hoe.new('keyword_search', '1.3.0') do |p|
0
   p.rubyforge_name = 'codefluency'
0
   p.summary = 'Generic support for extracting GMail-style search keywords/values from strings'
0
   p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
0
@@ -12,16 +11,10 @@ Hoe.new('keyword_search', KeywordSearch::VERSION) do |p|
0
   p.author = 'Bruce Williams'
0
   p.email = 'bruce@codefluency.com'
0
   p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
0
- p.extra_deps = [['dhaka', '= 2.1.0']]
0
 end
0
 
0
-task :rebuild do
0
- require 'dhaka'
0
- parser = Dhaka::Parser.new(KeywordSearch::Grammar)
0
- File.open('lib/keyword_search/parser.rb', 'w') do |file|
0
- file << parser.compile_to_ruby_source_as('KeywordSearch::Parser')
0
- end
0
+rule '.rb' => '.rl' do |t|
0
+ sh "ragel -R #{t.source} | rlgen-ruby -o #{t.name}"
0
 end
0
 
0
-
0
-# vim: syntax=Ruby
0
+task :ragel => 'lib/keyword_search.rb'
0
\ No newline at end of file
...
1
2
3
4
5
6
 
 
7
8
9
10
11
12
13
 
 
 
14
 
 
 
15
16
17
18
19
20
21
22
23
24
25
26
 
 
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
30
31
32
 
 
 
...
 
 
 
 
 
 
1
2
3
4
 
 
 
 
 
5
6
7
8
9
10
11
12
 
13
 
 
 
 
 
 
 
 
 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
 
263
264
265
266
0
@@ -1,31 +1,265 @@
0
-require 'dhaka'
0
-
0
-dirname = File.join(File.dirname(__FILE__), 'keyword_search')
0
-%w|grammar parser tokenizer evaluator definition|.each do |dependency|
0
- require File.join(dirname, dependency)
0
-end
0
+# line 1 "lib/keyword_search.rl"
0
+require File.dirname(__FILE__) << '/keyword_search/definition.rb'
0
 
0
 module KeywordSearch
0
-
0
- class ParseError < ::SyntaxError; end
0
-
0
- VERSION = '1.2.1'
0
-
0
+
0
+ class ParseError < ::SyntaxError; end
0
+
0
   class << self
0
+
0
+ # line 44 "lib/keyword_search.rl"
0
+
0
     def search(input_string, definition=nil, &block)
0
- @evaluator ||= Evaluator.new
0
       definition ||= Definition.new(&block)
0
- parse_result = Parser.parse(Tokenizer.tokenize(input_string))
0
- unless parse_result.has_error?
0
- results = @evaluator.evaluate(parse_result.parse_tree)
0
- results.each do |key, terms|
0
- definition.handle(key, terms)
0
- end
0
- results
0
- else
0
- raise ParseError, "Unexpected token #{parse_result.unexpected_token.inspect}"
0
+ results = parse(input_string)
0
+ results.each do |key, terms|
0
+ definition.handle(key, terms)
0
       end
0
+ results
0
+ end
0
+
0
+ #######
0
+ private
0
+ #######
0
+
0
+ def parse(input) #:nodoc:
0
+ data = input + ' '
0
+
0
+# line 30 "lib/keyword_search.rb"
0
+class << self
0
+ attr_accessor :_parser_actions
0
+ private :_parser_actions, :_parser_actions=
0
+end
0
+self._parser_actions = [
0
+ 0, 1, 3, 1, 4, 2, 0, 2,
0
+ 2, 1, 0
0
+]
0
+
0
+class << self
0
+ attr_accessor :_parser_key_offsets
0
+ private :_parser_key_offsets, :_parser_key_offsets=
0
+end
0
+self._parser_key_offsets = [
0
+ 0, 0, 5, 8, 12, 15, 16, 17,
0
+ 18
0
+]
0
+
0
+class << self
0
+ attr_accessor :_parser_trans_keys
0
+ private :_parser_trans_keys, :_parser_trans_keys=
0
+end
0
+self._parser_trans_keys = [
0
+ 0, 32, 34, 39, 58, 32, 34, 58,
0
+ 32, 34, 39, 58, 32, 34, 58, 34,
0
+ 32, 39, 32, 34, 58, 0
0
+]
0
+
0
+class << self
0
+ attr_accessor :_parser_single_lengths
0
+ private :_parser_single_lengths, :_parser_single_lengths=
0
+end
0
+self._parser_single_lengths = [
0
+ 0, 5, 3, 4, 3, 1, 1, 1,
0
+ 3
0
+]
0
+
0
+class << self
0
+ attr_accessor :_parser_range_lengths
0
+ private :_parser_range_lengths, :_parser_range_lengths=
0
+end
0
+self._parser_range_lengths = [
0
+ 0, 0, 0, 0, 0, 0, 0, 0,
0
+ 0
0
+]
0
+
0
+class << self
0
+ attr_accessor :_parser_index_offsets
0
+ private :_parser_index_offsets, :_parser_index_offsets=
0
+end
0
+self._parser_index_offsets = [
0
+ 0, 0, 6, 10, 15, 19, 21, 23,
0
+ 25
0
+]
0
+
0
+class << self
0
+ attr_accessor :_parser_trans_targs_wi
0
+ private :_parser_trans_targs_wi, :_parser_trans_targs_wi=
0
+end
0
+self._parser_trans_targs_wi = [
0
+ 8, 0, 5, 7, 0, 2, 1, 0,
0
+ 3, 2, 0, 5, 7, 0, 4, 1,
0
+ 0, 0, 4, 6, 5, 1, 0, 6,
0
+ 7, 1, 0, 3, 2, 0
0
+]
0
+
0
+class << self
0
+ attr_accessor :_parser_trans_actions_wi
0
+ private :_parser_trans_actions_wi, :_parser_trans_actions_wi=
0
+end
0
+self._parser_trans_actions_wi = [
0
+ 5, 3, 5, 5, 3, 5, 1, 0,
0
+ 0, 0, 0, 8, 8, 0, 8, 1,
0
+ 0, 0, 0, 0, 0, 1, 0, 0,
0
+ 0, 1, 0, 0, 0, 0
0
+]
0
+
0
+class << self
0
+ attr_accessor :parser_start
0
+end
0
+self.parser_start = 1;
0
+class << self
0
+ attr_accessor :parser_first_final
0
+end
0
+self.parser_first_final = 8;
0
+class << self
0
+ attr_accessor :parser_error
0
+end
0
+self.parser_error = 0;
0
+
0
+class << self
0
+ attr_accessor :parser_en_main
0
+end
0
+self.parser_en_main = 1;
0
+
0
+# line 62 "lib/keyword_search.rl"
0
+ p = 0
0
+ pe = data.length
0
+ key = nil
0
+ tokstart = nil
0
+ results = {}
0
+
0
+# line 133 "lib/keyword_search.rb"
0
+begin
0
+ p ||= 0
0
+ pe ||= data.length
0
+ cs = parser_start
0
+end
0
+# line 68 "lib/keyword_search.rl"
0
+
0
+# line 141 "lib/keyword_search.rb"
0
+begin
0
+ _klen, _trans, _keys, _acts, _nacts = nil
0
+ if p != pe
0
+ if cs != 0
0
+ while true
0
+ _break_resume = false
0
+ begin
0
+ _break_again = false
0
+ _keys = _parser_key_offsets[cs]
0
+ _trans = _parser_index_offsets[cs]
0
+ _klen = _parser_single_lengths[cs]
0
+ _break_match = false
0
+
0
+ begin
0
+ if _klen > 0
0
+ _lower = _keys
0
+ _upper = _keys + _klen - 1
0
+
0
+ loop do
0
+ break if _upper < _lower
0
+ _mid = _lower + ( (_upper - _lower) >> 1 )
0
+
0
+ if data[p] < _parser_trans_keys[_mid]
0
+ _upper = _mid - 1
0
+ elsif data[p] > _parser_trans_keys[_mid]
0
+ _lower = _mid + 1
0
+ else
0
+ _trans += (_mid - _keys)
0
+ _break_match = true
0
+ break
0
+ end
0
+ end # loop
0
+ break if _break_match
0
+ _keys += _klen
0
+ _trans += _klen
0
+ end
0
+ _klen = _parser_range_lengths[cs]
0
+ if _klen > 0
0
+ _lower = _keys
0
+ _upper = _keys + (_klen << 1) - 2
0
+ loop do
0
+ break if _upper < _lower
0
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1)
0
+ if data[p] < _parser_trans_keys[_mid]
0
+ _upper = _mid - 2
0
+ elsif data[p] > _parser_trans_keys[_mid+1]
0
+ _lower = _mid + 2
0
+ else
0
+ _trans += ((_mid - _keys) >> 1)
0
+ _break_match = true
0
+ break
0
+ end
0
+ end # loop
0
+ break if _break_match
0
+ _trans += _klen
0
+ end
0
+ end while false
0
+ cs = _parser_trans_targs_wi[_trans]
0
+ break if _parser_trans_actions_wi[_trans] == 0
0
+ _acts = _parser_trans_actions_wi[_trans]
0
+ _nacts = _parser_actions[_acts]
0
+ _acts += 1
0
+ while _nacts > 0
0
+ _nacts -= 1
0
+ _acts += 1
0
+ case _parser_actions[_acts - 1]
0
+when 0:
0
+# line 13 "lib/keyword_search.rl"
0
+ begin
0
+
0
+ tokstart = p;
0
+ end
0
+# line 13 "lib/keyword_search.rl"
0
+when 1:
0
+# line 17 "lib/keyword_search.rl"
0
+ begin
0
+
0
+ key = data[tokstart...p-1]
0
+ results[key] ||= []
0
+ end
0
+# line 17 "lib/keyword_search.rl"
0
+when 2:
0
+# line 22 "lib/keyword_search.rl"
0
+ begin
0
+
0
+ key = nil
0
+ end
0
+# line 22 "lib/keyword_search.rl"
0
+when 3:
0
+# line 26 "lib/keyword_search.rl"
0
+ begin
0
+
0
+ value = data[tokstart..p-1]
0
+ value = value[1..-2] if ["'", '"'].include?(value[0,1])
0
+ (results[key || :default] ||= []) << value
0
+ end
0
+# line 26 "lib/keyword_search.rl"
0
+when 4:
0
+# line 42 "lib/keyword_search.rl"
0
+ begin
0
+ raise ParseError, "At offset #{p}, near: '#{data[p,10]}'" end
0
+# line 42 "lib/keyword_search.rl"
0
+# line 244 "lib/keyword_search.rb"
0
+ end # action switch
0
+ end
0
+ end while false
0
+ break if _break_resume
0
+ break if cs == 0
0
+ p += 1
0
+ break if p == pe
0
+ end
0
+ end
0
+ end
0
+ end
0
+# line 69 "lib/keyword_search.rl"
0
+
0
+# line 258 "lib/keyword_search.rb"
0
+# line 70 "lib/keyword_search.rl"
0
+ results
0
     end
0
+
0
   end
0
   
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+
...
4
5
6
7
8
 
9
10
11
12
13
14
15
 
16
17
18
19
20
21
22
23
24
25
 
 
 
 
26
27
28
 
29
30
31
...
35
36
37
38
 
39
40
41
...
4
5
6
 
 
7
8
9
10
11
12
13
 
14
15
16
17
18
 
19
 
20
21
22
23
24
25
26
27
28
 
29
30
31
32
...
36
37
38
 
39
40
41
42
0
@@ -4,28 +4,29 @@ module KeywordSearch
0
     
0
     class Keyword
0
       
0
- attr_reader :name, :description
0
-
0
+ attr_reader :name, :description, :handler
0
       def initialize(name, description=nil, &handler)
0
         @name, @description = name, description
0
         @handler = handler
0
       end
0
       
0
       def handle(value)
0
- @handler.call(value)
0
+ handler.call(value)
0
       end
0
       
0
     end
0
 
0
- attr_reader :keywords
0
     def initialize
0
- @keywords = []
0
       @default_keyword = nil
0
       yield self if block_given?
0
     end
0
+
0
+ def keywords
0
+ @keywords ||= []
0
+ end
0
 
0
     def keyword(name, description=nil, &block)
0
- @keywords << Keyword.new(name, description, &block)
0
+ keywords << Keyword.new(name, description, &block)
0
     end
0
       
0
     def default_keyword(name)
0
@@ -35,7 +36,7 @@ module KeywordSearch
0
     def handle(key, values)
0
       key = @default_keyword if key == :default
0
       return false unless key
0
- if k = @keywords.detect{|kw| kw.name == key.to_sym}
0
+ if k = keywords.detect { |kw| kw.name == key.to_sym}
0
         k.handle(values)
0
       end
0
     end
...
1
 
 
 
 
2
3
4
 
5
6
7
...
10
11
12
13
 
14
15
16
...
21
22
23
24
 
25
26
27
...
31
32
33
34
 
35
36
37
...
42
43
44
45
 
46
47
48
...
52
53
54
55
 
56
57
58
...
63
64
65
66
67
68
 
 
 
69
70
71
...
74
75
76
77
 
78
79
80
...
85
86
87
88
 
89
90
91
...
96
97
98
99
 
100
101
102
...
107
108
109
110
 
111
112
113
...
118
119
120
121
 
122
123
124
...
129
130
131
132
 
133
134
135
...
140
141
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
144
145
...
1
2
3
4
5
6
7
 
8
9
10
11
...
14
15
16
 
17
18
19
20
...
25
26
27
 
28
29
30
31
...
35
36
37
 
38
39
40
41
...
46
47
48
 
49
50
51
52
...
56
57
58
 
59
60
61
62
...
67
68
69
 
 
 
70
71
72
73
74
75
...
78
79
80
 
81
82
83
84
...
89
90
91
 
92
93
94
95
...
100
101
102
 
103
104
105
106
...
111
112
113
 
114
115
116
117
...
122
123
124
 
125
126
127
128
...
133
134
135
 
136
137
138
139
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
0
@@ -1,7 +1,11 @@
0
 require 'test/unit'
0
+
0
+require 'rubygems' rescue nil
0
+require 'test/spec'
0
+
0
 require File.dirname(__FILE__) + '/../lib/keyword_search'
0
   
0
-class TestKeywordSearch < Test::Unit::TestCase
0
+context "KeywordSearch" do
0
   
0
   NAME_AND_AGE = %<bruce williams age:26>
0
   NAME_QUOTED_AND_AGE = %<"bruce williams" age:26>
0
@@ -10,7 +14,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
   DEFAULT_AGE_WITH_SINGLE_QUOTED_AGE = %<26 name:'bruce williams'>
0
   NAME_WITH_NESTED_SINGLE_QUOTES = %<"d'arcy d'uberville" age:28>
0
   
0
- def test_default_keyword
0
+ specify "default keyword" do
0
     result = nil
0
     KeywordSearch.search(NAME_AND_AGE) do |with|
0
       with.default_keyword :name
0
@@ -21,7 +25,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal 'bruce williams', result
0
   end
0
   
0
- def test_unquoted_keyword_term
0
+ specify "unquoted keyword term" do
0
     result = nil
0
     KeywordSearch.search(NAME_AND_AGE) do |with|
0
       with.keyword :age do |values|
0
@@ -31,7 +35,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal 26, result
0
   end
0
   
0
- def test_quoted_default_keyword_term
0
+ specify "quoted default keyword term" do
0
     result = nil
0
     KeywordSearch.search(NAME_QUOTED_AND_AGE) do |with|
0
       with.default_keyword :name
0
@@ -42,7 +46,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal 'bruce williams', result
0
   end
0
   
0
- def test_quoted_keyword_term
0
+ specify "quoted keyword term" do
0
     result = nil
0
     KeywordSearch.search(NAME_AND_QUOTED_AGE) do |with|
0
       with.keyword :age do |values|
0
@@ -52,7 +56,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal 26, result
0
   end
0
   
0
- def test_quoted_keyword_term_with_whitespace
0
+ specify "quoted keyword term with whitespace" do
0
     result = nil
0
     KeywordSearch.search(DEFAULT_AGE_WITH_QUOTED_AGE) do |with|
0
       with.default_keyword :age
0
@@ -63,9 +67,9 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal 'bruce williams', result
0
   end
0
   
0
- def test_single_quoted_keyword_term_with_whitespace
0
- result = nil
0
- KeywordSearch.search(DEFAULT_AGE_WITH_SINGLE_QUOTED_AGE) do |with|
0
+ specify "single quoted keyword term with whitespace" do
0
+ result = nil
0
+ r = KeywordSearch.search(DEFAULT_AGE_WITH_SINGLE_QUOTED_AGE) do |with|
0
       with.default_keyword :age
0
       with.keyword :name do |values|
0
         result = values.first
0
@@ -74,7 +78,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal 'bruce williams', result
0
   end
0
   
0
- def test_nested_single_quote_is_accumulated
0
+ specify "nested single quote is accumulated" do
0
     result = nil
0
     KeywordSearch.search(NAME_WITH_NESTED_SINGLE_QUOTES) do |with|
0
       with.default_keyword :name
0
@@ -85,7 +89,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal %<d'arcy d'uberville>, result
0
   end
0
   
0
- def test_nested_double_quote_is_accumulated
0
+ specify "nested double quote is accumulated" do
0
     result = nil
0
     KeywordSearch.search(%<'he was called "jake"'>) do |with|
0
       with.default_keyword :text
0
@@ -96,7 +100,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal %<he was called "jake">, result
0
   end
0
   
0
- def test_bare_single_quote_in_unquoted_literal_is_accumulated
0
+ specify "bare single quote in unquoted literal is accumulated" do
0
     result = nil
0
     KeywordSearch.search(%<bruce's age:27>) do |with|
0
       with.default_keyword :text
0
@@ -107,7 +111,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal %<bruce's>, result
0
   end
0
   
0
- def test_single_quoted_literal_is_accumulated
0
+ specify "single quoted literal is accumulated" do
0
     result = nil
0
     KeywordSearch.search(%<foo 'bruce williams' age:27>) do |with|
0
       with.default_keyword :text
0
@@ -118,7 +122,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal %<bruce williams>, result
0
   end
0
   
0
- def test_period_in_literal_is_accumulated
0
+ specify "period in literal is accumulated" do
0
     result = nil
0
     KeywordSearch.search(%<okay... age:27>) do |with|
0
       with.default_keyword :text
0
@@ -129,7 +133,7 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     assert_equal %<okay...>, result
0
   end
0
   
0
- def test_parse_error_results_in_exception
0
+ specify "parse error results in exception" do
0
     assert_raises(KeywordSearch::ParseError) do
0
       KeywordSearch.search(%<we_do_not_allow:! or ::>) do |with|
0
         with.default_keyword :text
0
@@ -140,6 +144,38 @@ class TestKeywordSearch < Test::Unit::TestCase
0
     end
0
   end
0
   
0
+ specify "can use apostrophes in unquoted literal" do
0
+ result = nil
0
+ KeywordSearch.search(%<d'correct>) do |with|
0
+ with.default_keyword :text
0
+ with.keyword :text do |values|
0
+ result = values.first
0
+ end
0
+ end
0
+ assert_equal "d'correct", result
0
+ end
0
+
0
+ specify "can use apostrophes in unquoted literal values" do
0
+ result = nil
0
+ KeywordSearch.search(%<text:d'correct>) do |with|
0
+ with.default_keyword :text
0
+ with.keyword :text do |values|
0
+ result = values.first
0
+ end
0
+ end
0
+ assert_equal "d'correct", result
0
+ end
0
+
0
+ specify "cannot use an apostrophe at the beginning on an unquoted literal" do
0
+ assert_raises(KeywordSearch::ParseError) do
0
+ KeywordSearch.search(%<'thisiswrong>) do |with|
0
+ with.default_keyword :text
0
+ with.keyword :text do |values|
0
+ result = values.first
0
+ end
0
+ end
0
+ end
0
+ end
0
 end
0
 
0
 

Comments

    No one has commented yet.