eye-of-newt 0.0.9 → 0.0.10
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.
- checksums.yaml +4 -4
- data/lib/eye_of_newt/ingredient.rb +11 -3
- data/lib/eye_of_newt/parser.rb +134 -123
- data/lib/eye_of_newt/parser.y +21 -17
- data/lib/eye_of_newt/tokenizer.rb +3 -0
- data/lib/eye_of_newt/version.rb +1 -1
- data/test/examples.txt +1 -0
- data/test/eye_of_newt/tokenizer_test.rb +8 -0
- data/test/eye_of_newt_test.rb +4 -4
- data/test/test_helper.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a22153a502ff31dcf2c78bbc353759a09e3a972d
|
4
|
+
data.tar.gz: 9942d74541ae7d441540ef11c99ef39d44a106c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf13232d805fc460a0e5accb943d6841fa17b9ad3eb7ccc5d11eb1d4e93dac5b5408a31ea5afa3c6be1ab38903b6aa32f8b3b48e3e3b14f133b33ea5e993de48
|
7
|
+
data.tar.gz: 677735c13e5b2d58cae5523c86fef5a2d328166e9cedef99682a47612999c59d75d8f635b4481a328a131b7630b96cfd6a354c2ddadd355b3f4577fee3e72723
|
@@ -1,14 +1,22 @@
|
|
1
1
|
module EyeOfNewt
|
2
2
|
class Ingredient
|
3
|
-
attr_accessor :amount, :unit, :unit_modifier, :
|
3
|
+
attr_accessor :amount, :unit, :unit_modifier, :names, :style, :note
|
4
4
|
|
5
|
-
def initialize(amount: nil, unit: nil, unit_modifier: nil,
|
5
|
+
def initialize(amount: nil, unit: nil, unit_modifier: nil, names: [], style: nil, note: nil)
|
6
6
|
self.amount = amount
|
7
7
|
self.unit = unit
|
8
8
|
self.unit_modifier = unit_modifier
|
9
|
-
self.
|
9
|
+
self.names = names
|
10
10
|
self.style = style
|
11
11
|
self.note = note
|
12
12
|
end
|
13
|
+
|
14
|
+
def name
|
15
|
+
names.first
|
16
|
+
end
|
17
|
+
|
18
|
+
def name=(n)
|
19
|
+
self.names = [n]
|
20
|
+
end
|
13
21
|
end
|
14
22
|
end
|
data/lib/eye_of_newt/parser.rb
CHANGED
@@ -37,117 +37,121 @@ module EyeOfNewt
|
|
37
37
|
##### State transition tables begin ###
|
38
38
|
|
39
39
|
racc_action_table = [
|
40
|
-
-
|
41
|
-
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
-47, 44, 19, 21, 12, 42, 20, -47, 11, -47,
|
41
|
+
13, -47, 14, 19, 19, 39, 40, 20, 20, 24,
|
42
|
+
24, 25, 25, 19, 12, -35, 35, 20, 48, 24,
|
43
|
+
36, 25, 14, 29, 38, 30, 31, 12, 12, 58,
|
44
|
+
30, 31, 46, 47, 30, 31, 31, 42, 42, 32,
|
45
|
+
22, 59, 60, 21, 21, 63, 46, 64, 65, 31,
|
46
|
+
31, 68, 69 ]
|
46
47
|
|
47
48
|
racc_action_check = [
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
3, 8,
|
52
|
-
|
53
|
-
|
49
|
+
11, 15, 0, 0, 0, 14, 0, 11, 0, 11,
|
50
|
+
0, 11, 0, 2, 18, 9, 9, 2, 18, 2,
|
51
|
+
18, 2, 18, 32, 6, 13, 6, 32, 22, 32,
|
52
|
+
6, 32, 6, 3, 8, 3, 3, 33, 7, 33,
|
53
|
+
23, 23, 21, 21, 26, 26, 27, 30, 31, 4,
|
54
|
+
1, 34, 37, 39, 40, 41, 44, 46, 47, 49,
|
55
|
+
51, 55, 57 ]
|
54
56
|
|
55
57
|
racc_action_pointer = [
|
56
|
-
0,
|
57
|
-
0, nil,
|
58
|
-
|
59
|
-
|
60
|
-
nil, nil,
|
61
|
-
nil, nil, nil,
|
62
|
-
nil, nil, nil, nil, nil, nil, nil ]
|
58
|
+
0, 50, 11, 24, 42, nil, 20, 34, 28, 1,
|
59
|
+
nil, 0, nil, 21, 0, -2, nil, nil, 12, nil,
|
60
|
+
nil, 26, 28, 29, nil, nil, 33, 34, nil, nil,
|
61
|
+
42, 43, 21, 33, 45, nil, nil, 46, nil, 50,
|
62
|
+
51, 42, nil, nil, 40, nil, 54, 55, nil, 47,
|
63
|
+
nil, 48, nil, nil, nil, 48, nil, 56, nil, nil,
|
64
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil ]
|
63
65
|
|
64
66
|
racc_action_default = [
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-48, -
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
67
|
+
-53, -53, -53, -12, -14, -15, -23, -53, -27, -28,
|
68
|
+
-29, -30, -31, -49, -53, -39, -41, -42, -44, -46,
|
69
|
+
-48, -50, -53, -8, -47, -49, -10, -11, -6, -32,
|
70
|
+
-53, -53, -53, -21, -19, -22, -35, -25, -26, -53,
|
71
|
+
-53, -53, -45, -40, -53, -43, -53, -53, 70, -7,
|
72
|
+
-2, -9, -4, -5, -33, -53, -13, -17, -20, -18,
|
73
|
+
-24, -37, -38, -36, -51, -52, -1, -3, -34, -16 ]
|
72
74
|
|
73
75
|
racc_goto_table = [
|
74
|
-
|
75
|
-
|
76
|
-
52, 53,
|
77
|
-
nil, nil, nil,
|
78
|
-
nil, nil, nil, nil,
|
76
|
+
28, 9, 8, 6, 3, 27, 23, 7, 34, 37,
|
77
|
+
41, 45, 26, 33, 1, 10, 2, 43, nil, nil,
|
78
|
+
50, nil, nil, 52, 53, 49, 54, 55, 51, nil,
|
79
|
+
nil, nil, nil, nil, nil, 57, 56, nil, nil, nil,
|
80
|
+
61, 62, nil, nil, nil, nil, 66, nil, 67 ]
|
79
81
|
|
80
82
|
racc_goto_check = [
|
81
|
-
5,
|
82
|
-
|
83
|
-
|
84
|
-
nil, nil, nil,
|
85
|
-
nil, nil, nil, nil, 5, nil, 5 ]
|
83
|
+
5, 12, 11, 9, 3, 4, 3, 10, 11, 11,
|
84
|
+
14, 8, 6, 10, 1, 13, 2, 16, nil, nil,
|
85
|
+
5, nil, nil, 5, 5, 4, 14, 14, 4, nil,
|
86
|
+
nil, nil, nil, nil, nil, 11, 3, nil, nil, nil,
|
87
|
+
12, 12, nil, nil, nil, nil, 5, nil, 5 ]
|
86
88
|
|
87
89
|
racc_goto_pointer = [
|
88
|
-
nil, 14, 16,
|
89
|
-
2, 1, 15, -
|
90
|
+
nil, 14, 16, 4, 2, -3, 9, nil, -7, 3,
|
91
|
+
7, 2, 1, 15, -4, nil, 2, nil, nil ]
|
90
92
|
|
91
93
|
racc_goto_default = [
|
92
|
-
nil, nil, nil, nil, nil, nil, nil, 4,
|
93
|
-
nil, nil, nil, nil,
|
94
|
+
nil, nil, nil, nil, nil, nil, nil, 4, 5, nil,
|
95
|
+
nil, nil, nil, nil, nil, 15, 16, 17, 18 ]
|
94
96
|
|
95
97
|
racc_reduce_table = [
|
96
98
|
0, 0, :racc_error,
|
97
|
-
4, 18, :_reduce_none,
|
98
|
-
3, 18, :_reduce_none,
|
99
|
-
4, 18, :_reduce_none,
|
100
|
-
3, 18, :_reduce_none,
|
101
|
-
3, 18, :_reduce_none,
|
102
|
-
2, 18, :_reduce_none,
|
103
|
-
3, 18, :_reduce_none,
|
104
|
-
2, 18, :_reduce_none,
|
105
|
-
3, 18, :_reduce_none,
|
106
|
-
2, 18, :_reduce_none,
|
107
|
-
2, 18, :_reduce_none,
|
108
|
-
1, 18, :_reduce_none,
|
109
|
-
1, 20, :_reduce_13,
|
110
99
|
4, 19, :_reduce_none,
|
111
100
|
3, 19, :_reduce_none,
|
101
|
+
4, 19, :_reduce_none,
|
112
102
|
3, 19, :_reduce_none,
|
113
|
-
2, 19, :_reduce_none,
|
114
103
|
3, 19, :_reduce_none,
|
115
104
|
2, 19, :_reduce_none,
|
105
|
+
3, 19, :_reduce_none,
|
116
106
|
2, 19, :_reduce_none,
|
117
|
-
1, 19, :_reduce_none,
|
118
107
|
3, 19, :_reduce_none,
|
119
108
|
2, 19, :_reduce_none,
|
120
109
|
2, 19, :_reduce_none,
|
121
110
|
1, 19, :_reduce_none,
|
122
|
-
|
123
|
-
1,
|
124
|
-
1, 25, :
|
111
|
+
3, 21, :_reduce_none,
|
112
|
+
1, 21, :_reduce_none,
|
113
|
+
1, 25, :_reduce_15,
|
114
|
+
4, 20, :_reduce_none,
|
115
|
+
3, 20, :_reduce_none,
|
116
|
+
3, 20, :_reduce_none,
|
117
|
+
2, 20, :_reduce_none,
|
118
|
+
3, 20, :_reduce_none,
|
119
|
+
2, 20, :_reduce_none,
|
120
|
+
2, 20, :_reduce_none,
|
121
|
+
1, 20, :_reduce_none,
|
122
|
+
3, 20, :_reduce_none,
|
123
|
+
2, 20, :_reduce_none,
|
124
|
+
2, 20, :_reduce_none,
|
125
|
+
1, 20, :_reduce_none,
|
126
|
+
1, 27, :_reduce_28,
|
125
127
|
1, 27, :_reduce_29,
|
126
|
-
1,
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
3,
|
131
|
-
|
132
|
-
3,
|
133
|
-
|
134
|
-
|
135
|
-
1,
|
136
|
-
|
137
|
-
|
138
|
-
1, 24, :_reduce_none,
|
128
|
+
1, 27, :_reduce_30,
|
129
|
+
1, 29, :_reduce_31,
|
130
|
+
1, 24, :_reduce_32,
|
131
|
+
2, 22, :_reduce_33,
|
132
|
+
3, 23, :_reduce_34,
|
133
|
+
1, 28, :_reduce_35,
|
134
|
+
3, 28, :_reduce_36,
|
135
|
+
3, 31, :_reduce_37,
|
136
|
+
3, 31, :_reduce_38,
|
137
|
+
1, 30, :_reduce_none,
|
138
|
+
2, 30, :_reduce_40,
|
139
|
+
1, 30, :_reduce_none,
|
139
140
|
1, 30, :_reduce_none,
|
140
|
-
|
141
|
-
1,
|
142
|
-
1,
|
143
|
-
1,
|
144
|
-
1,
|
145
|
-
|
146
|
-
|
141
|
+
2, 26, :_reduce_43,
|
142
|
+
1, 26, :_reduce_none,
|
143
|
+
1, 32, :_reduce_none,
|
144
|
+
1, 36, :_reduce_none,
|
145
|
+
1, 36, :_reduce_none,
|
146
|
+
1, 36, :_reduce_none,
|
147
|
+
1, 36, :_reduce_none,
|
148
|
+
1, 33, :_reduce_50,
|
149
|
+
3, 34, :_reduce_51,
|
150
|
+
3, 35, :_reduce_52 ]
|
147
151
|
|
148
|
-
racc_reduce_n =
|
152
|
+
racc_reduce_n = 53
|
149
153
|
|
150
|
-
racc_shift_n =
|
154
|
+
racc_shift_n = 70
|
151
155
|
|
152
156
|
racc_token_table = {
|
153
157
|
false => 0,
|
@@ -157,18 +161,19 @@ racc_token_table = {
|
|
157
161
|
:UNIT => 4,
|
158
162
|
:TEXT => 5,
|
159
163
|
:OF => 6,
|
160
|
-
:
|
161
|
-
:
|
162
|
-
:
|
163
|
-
|
164
|
-
"
|
165
|
-
"
|
166
|
-
"
|
167
|
-
"
|
168
|
-
"
|
169
|
-
"
|
170
|
-
|
171
|
-
|
164
|
+
:OR => 7,
|
165
|
+
:A => 8,
|
166
|
+
:TO_TASTE => 9,
|
167
|
+
:UNIT_MODIFIER => 10,
|
168
|
+
"," => 11,
|
169
|
+
"(" => 12,
|
170
|
+
")" => 13,
|
171
|
+
"-" => 14,
|
172
|
+
"\u{2013}" => 15,
|
173
|
+
"/" => 16,
|
174
|
+
"." => 17 }
|
175
|
+
|
176
|
+
racc_nt_base = 18
|
172
177
|
|
173
178
|
racc_use_result_var = true
|
174
179
|
|
@@ -196,6 +201,7 @@ Racc_token_to_s_table = [
|
|
196
201
|
"UNIT",
|
197
202
|
"TEXT",
|
198
203
|
"OF",
|
204
|
+
"OR",
|
199
205
|
"A",
|
200
206
|
"TO_TASTE",
|
201
207
|
"UNIT_MODIFIER",
|
@@ -209,11 +215,12 @@ Racc_token_to_s_table = [
|
|
209
215
|
"$start",
|
210
216
|
"ingredient",
|
211
217
|
"quantity",
|
212
|
-
"
|
218
|
+
"ingredient_names",
|
213
219
|
"style",
|
214
220
|
"note",
|
215
221
|
"to_taste",
|
216
|
-
"
|
222
|
+
"ingredient_name",
|
223
|
+
"ingredient_words",
|
217
224
|
"amount",
|
218
225
|
"unit_modifier",
|
219
226
|
"unit",
|
@@ -223,7 +230,7 @@ Racc_token_to_s_table = [
|
|
223
230
|
"number",
|
224
231
|
"fraction",
|
225
232
|
"decimal",
|
226
|
-
"
|
233
|
+
"ingredient_word" ]
|
227
234
|
|
228
235
|
Racc_debug_parser = false
|
229
236
|
|
@@ -255,14 +262,14 @@ Racc_debug_parser = false
|
|
255
262
|
|
256
263
|
# reduce 12 omitted
|
257
264
|
|
258
|
-
|
259
|
-
@ingredient.name = result
|
260
|
-
result
|
261
|
-
end
|
265
|
+
# reduce 13 omitted
|
262
266
|
|
263
267
|
# reduce 14 omitted
|
264
268
|
|
265
|
-
|
269
|
+
def _reduce_15(val, _values, result)
|
270
|
+
@ingredient.names << result
|
271
|
+
result
|
272
|
+
end
|
266
273
|
|
267
274
|
# reduce 16 omitted
|
268
275
|
|
@@ -284,81 +291,81 @@ end
|
|
284
291
|
|
285
292
|
# reduce 25 omitted
|
286
293
|
|
287
|
-
|
294
|
+
# reduce 26 omitted
|
295
|
+
|
296
|
+
# reduce 27 omitted
|
297
|
+
|
298
|
+
def _reduce_28(val, _values, result)
|
288
299
|
@ingredient.amount = result
|
289
300
|
result
|
290
301
|
end
|
291
302
|
|
292
|
-
def
|
303
|
+
def _reduce_29(val, _values, result)
|
293
304
|
@ingredient.amount = result
|
294
305
|
result
|
295
306
|
end
|
296
307
|
|
297
|
-
def
|
308
|
+
def _reduce_30(val, _values, result)
|
298
309
|
@ingredient.amount = 1
|
299
310
|
result
|
300
311
|
end
|
301
312
|
|
302
|
-
def
|
313
|
+
def _reduce_31(val, _values, result)
|
303
314
|
@ingredient.unit = to_unit(result)
|
304
315
|
result
|
305
316
|
end
|
306
317
|
|
307
|
-
def
|
318
|
+
def _reduce_32(val, _values, result)
|
308
319
|
@ingredient.unit = to_unit(result)
|
309
320
|
result
|
310
321
|
end
|
311
322
|
|
312
|
-
def
|
323
|
+
def _reduce_33(val, _values, result)
|
313
324
|
@ingredient.style = val[1]
|
314
325
|
result
|
315
326
|
end
|
316
327
|
|
317
|
-
def
|
328
|
+
def _reduce_34(val, _values, result)
|
318
329
|
@ingredient.note = val[1]
|
319
330
|
result
|
320
331
|
end
|
321
332
|
|
322
|
-
def
|
333
|
+
def _reduce_35(val, _values, result)
|
323
334
|
@ingredient.unit_modifier = val[0]
|
324
335
|
result
|
325
336
|
end
|
326
337
|
|
327
|
-
def
|
338
|
+
def _reduce_36(val, _values, result)
|
328
339
|
@ingredient.unit_modifier = val[1]
|
329
340
|
result
|
330
341
|
end
|
331
342
|
|
332
|
-
def
|
343
|
+
def _reduce_37(val, _values, result)
|
333
344
|
result = [val[0], val[2]]
|
334
345
|
result
|
335
346
|
end
|
336
347
|
|
337
|
-
def
|
348
|
+
def _reduce_38(val, _values, result)
|
338
349
|
result = [val[0], val[2]]
|
339
350
|
result
|
340
351
|
end
|
341
352
|
|
342
|
-
# reduce
|
353
|
+
# reduce 39 omitted
|
343
354
|
|
344
|
-
def
|
355
|
+
def _reduce_40(val, _values, result)
|
345
356
|
result = val[0] + val[1]
|
346
357
|
result
|
347
358
|
end
|
348
359
|
|
349
|
-
# reduce
|
360
|
+
# reduce 41 omitted
|
350
361
|
|
351
|
-
# reduce
|
362
|
+
# reduce 42 omitted
|
352
363
|
|
353
|
-
def
|
364
|
+
def _reduce_43(val, _values, result)
|
354
365
|
result = val.join(' ')
|
355
366
|
result
|
356
367
|
end
|
357
368
|
|
358
|
-
# reduce 42 omitted
|
359
|
-
|
360
|
-
# reduce 43 omitted
|
361
|
-
|
362
369
|
# reduce 44 omitted
|
363
370
|
|
364
371
|
# reduce 45 omitted
|
@@ -367,17 +374,21 @@ end
|
|
367
374
|
|
368
375
|
# reduce 47 omitted
|
369
376
|
|
370
|
-
|
377
|
+
# reduce 48 omitted
|
378
|
+
|
379
|
+
# reduce 49 omitted
|
380
|
+
|
381
|
+
def _reduce_50(val, _values, result)
|
371
382
|
result = val[0].to_i
|
372
383
|
result
|
373
384
|
end
|
374
385
|
|
375
|
-
def
|
386
|
+
def _reduce_51(val, _values, result)
|
376
387
|
result = val[0].to_f / val[2].to_f
|
377
388
|
result
|
378
389
|
end
|
379
390
|
|
380
|
-
def
|
391
|
+
def _reduce_52(val, _values, result)
|
381
392
|
result = val.join.to_f
|
382
393
|
result
|
383
394
|
end
|
data/lib/eye_of_newt/parser.y
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
class EyeOfNewt::Parser
|
2
|
-
token WORD NUMBER UNIT TEXT OF A TO_TASTE UNIT_MODIFIER
|
2
|
+
token WORD NUMBER UNIT TEXT OF OR A TO_TASTE UNIT_MODIFIER
|
3
3
|
rule
|
4
4
|
ingredient
|
5
|
-
: quantity
|
6
|
-
| quantity
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| quantity
|
12
|
-
| quantity
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
: quantity ingredient_names style note
|
6
|
+
| quantity ingredient_names note
|
7
|
+
| ingredient_names to_taste style note
|
8
|
+
| ingredient_names to_taste note
|
9
|
+
| ingredient_names style note
|
10
|
+
| ingredient_names note
|
11
|
+
| quantity ingredient_names style
|
12
|
+
| quantity ingredient_names
|
13
|
+
| ingredient_names to_taste style
|
14
|
+
| ingredient_names to_taste
|
15
|
+
| ingredient_names style
|
16
|
+
| ingredient_names
|
17
|
+
;
|
18
|
+
ingredient_names
|
19
|
+
: ingredient_name OR ingredient_names
|
16
20
|
| ingredient_name
|
17
21
|
;
|
18
22
|
ingredient_name
|
19
|
-
:
|
23
|
+
: ingredient_words { @ingredient.names << result }
|
20
24
|
;
|
21
25
|
quantity
|
22
26
|
: amount unit_modifier unit OF
|
@@ -55,12 +59,12 @@ rule
|
|
55
59
|
| fraction
|
56
60
|
| decimal
|
57
61
|
;
|
58
|
-
|
59
|
-
:
|
60
|
-
|
|
62
|
+
ingredient_words
|
63
|
+
: ingredient_word ingredient_words { result = val.join(' ') }
|
64
|
+
| ingredient_word
|
61
65
|
;
|
62
66
|
text : TEXT ;
|
63
|
-
|
67
|
+
ingredient_word : WORD | A | OF | UNIT_MODIFIER ;
|
64
68
|
number : NUMBER { result = val[0].to_i } ;
|
65
69
|
fraction : NUMBER '/' NUMBER { result = val[0].to_f / val[2].to_f } ;
|
66
70
|
decimal : NUMBER '.' NUMBER { result = val.join.to_f } ;
|
@@ -9,6 +9,7 @@ module EyeOfNewt
|
|
9
9
|
WORD = /\w+(-\w+)*/
|
10
10
|
NUMBER = /\d+/
|
11
11
|
OF = /of/
|
12
|
+
OR = /or/
|
12
13
|
A = /an?/
|
13
14
|
TO_TASTE = /to taste/
|
14
15
|
|
@@ -36,6 +37,8 @@ module EyeOfNewt
|
|
36
37
|
[:OF, text]
|
37
38
|
when text = @ss.scan(/#{A}\b/)
|
38
39
|
[:A, text]
|
40
|
+
when text = @ss.scan(/#{OR}\b/)
|
41
|
+
[:OR, text]
|
39
42
|
when text = @ss.scan(/#{TO_TASTE}\b/)
|
40
43
|
[:TO_TASTE, text]
|
41
44
|
when text = @ss.scan(/#{unit_matcher}\b/)
|
data/lib/eye_of_newt/version.rb
CHANGED
data/test/examples.txt
CHANGED
@@ -27,3 +27,4 @@ heaping tablespoon of sugar | sugar | 1 | tbsp | | | heaping
|
|
27
27
|
1 pound of large beans | large beans | 1 | lb
|
28
28
|
4-5 handfuls of spinach, very roughly chopped | spinach | 4-5 | handfuls | very roughly chopped
|
29
29
|
1 (46 oz) can tomato juice | tomato juice | 1 | cans | | | 46 oz
|
30
|
+
kale or chard or spinach | kale,chard,spinach | 1 | units
|
@@ -59,6 +59,14 @@ class EyeOfNewt::TokenizerTest < ActiveSupport::TestCase
|
|
59
59
|
assert_nil t.next_token
|
60
60
|
end
|
61
61
|
|
62
|
+
test "tokenizes OR" do
|
63
|
+
t = tok("this or that")
|
64
|
+
assert_equal [:WORD, "this"], t.next_token
|
65
|
+
assert_equal [:OR, "or"], t.next_token
|
66
|
+
assert_equal [:WORD, "that"], t.next_token
|
67
|
+
assert_nil t.next_token
|
68
|
+
end
|
69
|
+
|
62
70
|
test "tokenizes fractions" do
|
63
71
|
t = tok("1 1/2")
|
64
72
|
assert_equal [:NUMBER, "1"], t.next_token
|
data/test/eye_of_newt_test.rb
CHANGED
@@ -11,14 +11,14 @@ class EyeOfNewtTest < ActiveSupport::TestCase
|
|
11
11
|
|
12
12
|
tokens = line.split('|').map(&:strip)
|
13
13
|
line = tokens.shift
|
14
|
-
|
14
|
+
names = tokens.shift.split(',').map(&:strip)
|
15
15
|
amount = tokens.shift.split('-').map(&:to_f)
|
16
16
|
amount = amount.first unless amount.many?
|
17
17
|
unit = tokens.shift.presence
|
18
18
|
style = tokens.shift.presence
|
19
19
|
note = tokens.shift.presence
|
20
20
|
unit_modifier = tokens.shift.presence
|
21
|
-
expected = [
|
21
|
+
expected = [names, amount, unit, style, note, unit_modifier]
|
22
22
|
[line, expected]
|
23
23
|
}.compact
|
24
24
|
end
|
@@ -27,8 +27,8 @@ class EyeOfNewtTest < ActiveSupport::TestCase
|
|
27
27
|
examples.each do |line, expected|
|
28
28
|
test "parses #{line} correctly" do
|
29
29
|
ingr = EyeOfNewt.parse(line)
|
30
|
-
|
31
|
-
assert_equal
|
30
|
+
names, amount, unit, style, note, unit_modifier = *expected
|
31
|
+
assert_equal names, ingr.names, %Q{incorrect names}
|
32
32
|
assert_equal amount, ingr.amount, %Q{incorrect amount}
|
33
33
|
assert_equal unit, ingr.unit, %Q{incorrect unit}
|
34
34
|
assert_equal style, ingr.style, %Q{incorrect style}
|
data/test/test_helper.rb
CHANGED