livetext 0.9.21 → 0.9.22

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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/imports/bookish.rb +8 -10
  3. data/imports/pyggish.rb +2 -34
  4. data/imports/tutorial.rb +2 -2
  5. data/lib/cmdargs.rb +2 -3
  6. data/lib/formatline.rb +101 -73
  7. data/lib/functions.rb +16 -1
  8. data/lib/handler/{icanhaz.rb → import.rb} +1 -1
  9. data/lib/handler.rb +1 -1
  10. data/lib/helpers.rb +10 -10
  11. data/lib/livetext.rb +12 -5
  12. data/lib/parser/set.rb +1 -3
  13. data/lib/parser/string.rb +2 -2
  14. data/lib/processor.rb +6 -2
  15. data/lib/standard.rb +15 -15
  16. data/lib/userapi.rb +4 -2
  17. data/plugin/bookish.rb +4 -5
  18. data/plugin/pyggish.rb +45 -77
  19. data/plugin/tutorial.rb +0 -1
  20. data/test/snapshots/error_inc_line_num/actual-error.txt +14 -0
  21. data/test/snapshots/error_inc_line_num/actual-output.txt +7 -0
  22. data/test/snapshots/error_inc_line_num/out-sdiff.txt +14 -0
  23. data/test/snapshots/error_invalid_name/actual-error.txt +10 -0
  24. data/test/snapshots/{icanhaz2/expected-error.txt → error_invalid_name/actual-output.txt} +0 -0
  25. data/test/snapshots/error_invalid_name/out-sdiff.txt +6 -0
  26. data/test/snapshots/error_missing_end/actual-error.txt +10 -0
  27. data/test/snapshots/error_missing_end/actual-output.txt +0 -0
  28. data/test/snapshots/error_missing_end/out-sdiff.txt +6 -0
  29. data/test/snapshots/error_no_such_copy/actual-error.txt +10 -0
  30. data/test/snapshots/error_no_such_copy/actual-output.txt +0 -0
  31. data/test/snapshots/error_no_such_inc/actual-error.txt +10 -0
  32. data/test/snapshots/error_no_such_inc/actual-output.txt +0 -0
  33. data/test/snapshots/error_no_such_mixin/actual-error.txt +13 -0
  34. data/test/snapshots/error_no_such_mixin/actual-output.txt +0 -0
  35. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +6 -0
  36. data/test/snapshots/import/actual-error.txt +13 -0
  37. data/test/snapshots/import/actual-output.txt +0 -0
  38. data/test/snapshots/{icanhaz → import}/expected-output.txt +0 -0
  39. data/test/snapshots/{icanhaz → import}/match-error.txt +0 -0
  40. data/test/snapshots/import/out-sdiff.txt +6 -0
  41. data/test/snapshots/{icanhaz → import}/simple_import.rb +0 -0
  42. data/test/snapshots/{icanhaz → import}/source.lt3 +2 -2
  43. data/test/snapshots/import2/expected-error.txt +0 -0
  44. data/test/snapshots/{icanhaz2 → import2}/expected-output.txt +3 -1
  45. data/test/snapshots/{icanhaz2/simple_canhaz.rb → import2/simple_import.rb} +0 -0
  46. data/test/snapshots/import2/source.lt3 +8 -0
  47. data/test/snapshots/more_functions/expected-error.txt +0 -0
  48. data/test/snapshots/more_functions/expected-output.txt +37 -0
  49. data/test/snapshots/more_functions/source.lt3 +40 -0
  50. data/test/snapshots/simple_import/expected-output.txt +2 -0
  51. data/test/snapshots/simple_import/source.lt3 +3 -1
  52. data/test/snapshots/subset.txt +11 -12
  53. data/test/snapshots/wtf_bookish/expected-error.txt +0 -0
  54. data/test/snapshots/wtf_bookish/expected-output.txt +10 -0
  55. data/test/snapshots/wtf_bookish/source.lt3 +7 -0
  56. data/test/snapshots/wtf_bookish/toc.tmp +0 -0
  57. data/test/snapshots.rb +6 -7
  58. data/test/unit/formatline.rb +252 -135
  59. data/test/unit/parser/set.rb +6 -10
  60. data/test/unit/parser/string.rb +5 -5
  61. data/test/unit/standard.rb +0 -1
  62. metadata +37 -13
  63. data/lib/livetext/importable.rb +0 -2
  64. data/lib/parser/import.rb +0 -15
  65. data/test/snapshots/icanhaz2/source.lt3 +0 -6
@@ -4,94 +4,188 @@ require_relative '../../lib/livetext'
4
4
 
5
5
  class TestingLivetext < MiniTest::Test
6
6
 
7
- # Some (most) methods were generated via...
7
+ # Some (most) methods were generated via the code
8
+ # seen in the comment at the bottom of this file...
8
9
 
9
- =begin
10
- TestLines = []
11
-
12
- items = []
13
- formatting_tests = File.open("test/snapshots/formatting-tests.txt")
14
- loop do
15
- 4.times { items << formatting_tests.gets.chomp }
16
- # Blank line terminates each "stanza"
17
- raise "Oops? #{items.inspect}" unless items.last.empty?
18
- TestLines << items
19
- break if formatting_tests.eof?
10
+ def test_simple_string
11
+ parse = FormatLine.new("only testing")
12
+ tokens = parse.tokenize
13
+ assert_equal tokens, [[:str, "only testing"]], "Tokens were: #{tokens.inspect}"
14
+ expected = "only testing"
15
+ result = parse.evaluate
16
+ assert_equal expected, result
20
17
  end
21
18
 
22
- STDERR.puts <<~RUBY
23
- require 'minitest/autorun'
19
+ def test_variable_interpolation
20
+ parse = FormatLine.new("File is $File and user is $User")
21
+ tokens = parse.tokenize
22
+ expected_tokens = [[:str, "File is "],
23
+ [:var, "File"],
24
+ [:str, " and user is "],
25
+ [:var, "User"]]
26
+ assert_equal expected_tokens, tokens
27
+ result = parse.evaluate
28
+ expected = "File is [File is undefined] and user is [User is undefined]"
29
+ assert_equal expected, result
30
+ end
24
31
 
25
- require_relative '../lib/livetext'
32
+ def test_func_expansion
33
+ parse = FormatLine.new("myfunc() results in $$myfunc apparently.")
34
+ tokens = parse.tokenize
35
+ expected_tokens = [[:str, "myfunc() results in "],
36
+ [:func, "myfunc"],
37
+ [:str, " apparently."]]
38
+ assert_equal expected_tokens, tokens
39
+ result = parse.evaluate
40
+ expected = "myfunc() results in [Error evaluating $$myfunc()] apparently."
41
+ assert_equal expected, result
42
+ end
43
+
44
+ # These tests follow this form:
45
+ #
46
+ # def test_func_SUFFIX
47
+ # str = "WHATEVER"
48
+ # parse = FormatLine.new(str)
49
+ # tokens_expected = [[], [], ...]
50
+ # tokens = parse.tokenize
51
+ # assert_equal tokens_expected, tokens
52
+ # result = parse.evaluate
53
+ # regex_expected = /Today is ....-..-../
54
+ # assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
55
+ # end
56
+
57
+ def test_func_2
58
+ str = "Today is $$date"
59
+ parse = FormatLine.new(str)
60
+ tokens_expected = [[:str, "Today is "], [:func, "date"]]
61
+ tokens = parse.tokenize
62
+ assert_equal tokens_expected, tokens, "Tokens were: #{tokens.inspect}"
63
+ result = parse.evaluate
64
+ regex_expected = /Today is ....-..-../
65
+ assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
66
+ end
26
67
 
27
- # Just another testing class. Chill.
68
+ def test_var_before_comma
69
+ str = "User name is $User, and all is well"
70
+ parse = FormatLine.new(str)
71
+ tokens_expected = [[:str, "User name is "], [:var, "User"], [:str, ", and all is well"]]
72
+ tokens = parse.tokenize
73
+ assert_equal tokens_expected, tokens, "Tokens were: #{tokens.inspect}"
74
+ result = parse.evaluate
75
+ regex_expected = /User name is .*, /
76
+ assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
77
+ end
28
78
 
29
- class TestingLivetext < MiniTest::Test
30
- RUBY
79
+ def test_var_at_EOS
80
+ str = "File name is $File"
81
+ parse = FormatLine.new(str)
82
+ tokens_expected = [[:str, "File name is "], [:var, "File"]]
83
+ tokens = parse.tokenize
84
+ assert_equal tokens_expected, tokens
85
+ result = parse.evaluate
86
+ string_expected = "File name is [File is undefined]"
87
+ assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
88
+ end
31
89
 
32
- TestLines.each.with_index do |item, num|
33
- msg, src, exp, blank = *item
34
- # generate tests...
35
- name = "test_formatting_#{'%02d' % (num + 1)}"
36
- method_source = <<~RUBY
37
- def #{name} # #{msg}
38
- msg, src, exp = <<~STUFF.split("\\n")
39
- #{msg}
40
- #{src}
41
- #{exp}
42
- STUFF
90
+ def test_var_starts_string
91
+ str = "$File is my file name"
92
+ parse = FormatLine.new(str)
93
+ tokens_expected = [[:var, "File"], [:str, " is my file name"]]
94
+ tokens = parse.tokenize
95
+ assert_equal tokens_expected, tokens
96
+ result = parse.evaluate
97
+ string_expected = "[File is undefined] is my file name"
98
+ assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
99
+ end
43
100
 
44
- actual = FormatLine.parse!(src)
45
- # FIXME could simplify assert logic?
46
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
47
- exp = Regexp.compile(exp[1..-2]) # skip slashes
48
- assert_match(exp, actual, msg)
49
- else
50
- assert_equal(exp, actual, msg)
51
- end
52
- end
101
+ # Next one is/will be a problem...
102
+ # I permit periods *inside* variable names
53
103
 
54
- RUBY
55
- STDERR.puts method_source
104
+ def test_var_before_period
105
+ str = "This is $File."
106
+ parse = FormatLine.new(str)
107
+ tokens_expected = [[:str, "This is "], [:var, "File"], [:str, "."]]
108
+ tokens = parse.tokenize
109
+ assert_equal tokens_expected, tokens
110
+ result = parse.evaluate
111
+ string_expected = "This is [File is undefined]."
112
+ assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
56
113
  end
57
- STDERR.puts "\nend"
58
- end
59
- =end
60
114
 
61
- def test_simple_string
62
- parse = FormatLine.new("only testing")
115
+ def test_func_needing_parameter_colon_eos # colon, param, EOS
116
+ str = "Square root of 225 is $$isqrt:225"
117
+ parse = FormatLine.new(str)
118
+ tokens_expected = [[:str, "Square root of 225 is "], [:func, "isqrt"], [:colon, "225"]]
63
119
  tokens = parse.tokenize
64
- assert_equal tokens, [[:str, "only testing"]]
65
- expected = "only testing"
120
+ assert_equal tokens_expected, tokens
66
121
  result = parse.evaluate
67
- assert result == expected
122
+ string_expected = "Square root of 225 is 15"
123
+ assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
68
124
  end
69
125
 
70
- def test_variable_interpolation
71
- parse = FormatLine.new("File is $File and user is $User")
126
+ def test_func_needing_parameter_colon # colon, param, more chars
127
+ str = "Answer is $$isqrt:225 today"
128
+ parse = FormatLine.new(str)
129
+ tokens_expected = [[:str, "Answer is "],
130
+ [:func, "isqrt"],
131
+ [:colon, "225"],
132
+ [:str, " today"]]
72
133
  tokens = parse.tokenize
73
- assert_equal tokens, [[:str, "File is "],
74
- [:var, "File"],
75
- [:str, " and user is "],
76
- [:var, "User"]
77
- ]
134
+ assert_equal tokens_expected, tokens
78
135
  result = parse.evaluate
79
- expected = "File is [File is undefined] and user is [User is undefined]"
80
- assert result == expected
136
+ string_expected = "Answer is 15 today"
137
+ assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
81
138
  end
82
139
 
83
- def test_func_expansion
84
- parse = FormatLine.new("myfunc() results in $$myfunc apparently.")
140
+ # isqrt: Not real tests??
141
+
142
+ def test_isqrt_empty_colon_param
143
+ str = "Calculate $$isqrt:"
144
+ parse = FormatLine.new(str)
145
+ tokens_expected = [[:str, "Calculate "],
146
+ [:func, "isqrt"] # , [:colon, ""]
147
+ ]
148
+ # If param is null, we don't get [:colon, value]!
149
+ # ^ FIXME function should be more like: [:func, name, param]
85
150
  tokens = parse.tokenize
86
- assert_equal tokens, [[:str, "myfunc() results in "],
87
- [:func, "myfunc"],
88
- [:str, " apparently."]
89
- ]
151
+ assert_equal tokens_expected, tokens
90
152
  result = parse.evaluate
91
- expected = "myfunc() results in [Error evaluating $$myfunc()] apparently."
92
- assert result == expected
153
+ string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]"
154
+ assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
155
+ end
156
+
157
+ def test_isqrt_empty_bracket_param
158
+ str = "Calculate $$isqrt[]"
159
+ parse = FormatLine.new(str)
160
+ tokens_expected = [[:str, "Calculate "],
161
+ [:func, "isqrt"] # , [:colon, ""]
162
+ ]
163
+ # If param is null, we don't get [:colon, value]!
164
+ # ^ FIXME function should be more like: [:func, name, param]
165
+ tokens = parse.tokenize
166
+ assert_equal tokens_expected, tokens
167
+ result = parse.evaluate
168
+ string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]"
169
+ assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
170
+ end
171
+
172
+ def test_isqrt_malformed_number
173
+ str = "Calculate $$isqrt[3a5]"
174
+ parse = FormatLine.new(str)
175
+ tokens_expected = [[:str, "Calculate "],
176
+ [:func, "isqrt"],
177
+ [:brackets, "3a5"]
178
+ ]
179
+ # ^ FIXME function should be more like: [:func, name, param]
180
+ tokens = parse.tokenize
181
+ assert_equal tokens_expected, tokens
182
+ result = parse.evaluate
183
+ string_expected = "Calculate [Error evaluating $$isqrt(3a5)]"
184
+ assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
93
185
  end
94
186
 
187
+ # ...end of this group
188
+
95
189
  def test_func_with_colon
96
190
  parse = FormatLine.new("Calling $$myfunc:foo here.")
97
191
  tokens = parse.tokenize
@@ -102,22 +196,22 @@ end
102
196
  ]
103
197
  result = parse.evaluate
104
198
  expected = "Calling [Error evaluating $$myfunc(foo)] here."
105
- assert result == expected
199
+ assert_equal expected, result
106
200
  end
107
201
 
108
202
  def test_func_with_brackets
109
203
  parse = FormatLine.new("Calling $$myfunc2[foo bar] here.")
110
204
  tokens = parse.tokenize
111
205
  assert_kind_of Array, tokens
112
- assert tokens.size == 4
113
- assert_equal tokens, [[:str, "Calling "],
114
- [:func, "myfunc2"],
115
- [:brackets, "foo bar"],
116
- [:str, " here."]
117
- ]
206
+ assert_equal 4, tokens.size
207
+ expected_tokens = [[:str, "Calling "],
208
+ [:func, "myfunc2"],
209
+ [:brackets, "foo bar"],
210
+ [:str, " here."]]
211
+ assert_equal expected_tokens, tokens
118
212
  result = parse.evaluate
119
213
  expected = "Calling [Error evaluating $$myfunc2(foo bar)] here."
120
- assert result == expected
214
+ assert_equal expected, result
121
215
  end
122
216
 
123
217
  def test_formatting_01 # Check output of $$date
@@ -128,8 +222,7 @@ end
128
222
  STUFF
129
223
 
130
224
  actual = FormatLine.parse!(src)
131
- # FIXME could simplify assert logic?
132
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
225
+ if exp[0] == "/"
133
226
  exp = Regexp.compile(exp[1..-2]) # skip slashes
134
227
  assert_match(exp, actual, msg)
135
228
  else
@@ -145,8 +238,7 @@ end
145
238
  STUFF
146
239
 
147
240
  actual = FormatLine.parse!(src)
148
- # FIXME could simplify assert logic?
149
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
241
+ if exp[0] == "/"
150
242
  exp = Regexp.compile(exp[1..-2]) # skip slashes
151
243
  assert_match(exp, actual, msg)
152
244
  else
@@ -162,8 +254,7 @@ end
162
254
  STUFF
163
255
 
164
256
  actual = FormatLine.parse!(src)
165
- # FIXME could simplify assert logic?
166
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
257
+ if exp[0] == "/"
167
258
  exp = Regexp.compile(exp[1..-2]) # skip slashes
168
259
  assert_match(exp, actual, msg)
169
260
  else
@@ -179,8 +270,7 @@ end
179
270
  STUFF
180
271
 
181
272
  actual = FormatLine.parse!(src)
182
- # FIXME could simplify assert logic?
183
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
273
+ if exp[0] == "/"
184
274
  exp = Regexp.compile(exp[1..-2]) # skip slashes
185
275
  assert_match(exp, actual, msg)
186
276
  else
@@ -196,8 +286,7 @@ end
196
286
  STUFF
197
287
 
198
288
  actual = FormatLine.parse!(src)
199
- # FIXME could simplify assert logic?
200
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
289
+ if exp[0] == "/"
201
290
  exp = Regexp.compile(exp[1..-2]) # skip slashes
202
291
  assert_match(exp, actual, msg)
203
292
  else
@@ -213,8 +302,7 @@ end
213
302
  STUFF
214
303
 
215
304
  actual = FormatLine.parse!(src)
216
- # FIXME could simplify assert logic?
217
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
305
+ if exp[0] == "/"
218
306
  exp = Regexp.compile(exp[1..-2]) # skip slashes
219
307
  assert_match(exp, actual, msg)
220
308
  else
@@ -230,8 +318,7 @@ end
230
318
  STUFF
231
319
 
232
320
  actual = FormatLine.parse!(src)
233
- # FIXME could simplify assert logic?
234
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
321
+ if exp[0] == "/"
235
322
  exp = Regexp.compile(exp[1..-2]) # skip slashes
236
323
  assert_match(exp, actual, msg)
237
324
  else
@@ -247,8 +334,7 @@ end
247
334
  STUFF
248
335
 
249
336
  actual = FormatLine.parse!(src)
250
- # FIXME could simplify assert logic?
251
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
337
+ if exp[0] == "/"
252
338
  exp = Regexp.compile(exp[1..-2]) # skip slashes
253
339
  assert_match(exp, actual, msg)
254
340
  else
@@ -264,8 +350,7 @@ end
264
350
  STUFF
265
351
 
266
352
  actual = FormatLine.parse!(src)
267
- # FIXME could simplify assert logic?
268
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
353
+ if exp[0] == "/"
269
354
  exp = Regexp.compile(exp[1..-2]) # skip slashes
270
355
  assert_match(exp, actual, msg)
271
356
  else
@@ -281,8 +366,7 @@ end
281
366
  STUFF
282
367
 
283
368
  actual = FormatLine.parse!(src)
284
- # FIXME could simplify assert logic?
285
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
369
+ if exp[0] == "/"
286
370
  exp = Regexp.compile(exp[1..-2]) # skip slashes
287
371
  assert_match(exp, actual, msg)
288
372
  else
@@ -298,8 +382,7 @@ end
298
382
  STUFF
299
383
 
300
384
  actual = FormatLine.parse!(src)
301
- # FIXME could simplify assert logic?
302
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
385
+ if exp[0] == "/"
303
386
  exp = Regexp.compile(exp[1..-2]) # skip slashes
304
387
  assert_match(exp, actual, msg)
305
388
  else
@@ -315,8 +398,7 @@ end
315
398
  STUFF
316
399
 
317
400
  actual = FormatLine.parse!(src)
318
- # FIXME could simplify assert logic?
319
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
401
+ if exp[0] == "/"
320
402
  exp = Regexp.compile(exp[1..-2]) # skip slashes
321
403
  assert_match(exp, actual, msg)
322
404
  else
@@ -332,8 +414,7 @@ end
332
414
  STUFF
333
415
 
334
416
  actual = FormatLine.parse!(src)
335
- # FIXME could simplify assert logic?
336
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
417
+ if exp[0] == "/"
337
418
  exp = Regexp.compile(exp[1..-2]) # skip slashes
338
419
  assert_match(exp, actual, msg)
339
420
  else
@@ -349,8 +430,7 @@ end
349
430
  STUFF
350
431
 
351
432
  actual = FormatLine.parse!(src)
352
- # FIXME could simplify assert logic?
353
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
433
+ if exp[0] == "/"
354
434
  exp = Regexp.compile(exp[1..-2]) # skip slashes
355
435
  assert_match(exp, actual, msg)
356
436
  else
@@ -366,8 +446,7 @@ end
366
446
  STUFF
367
447
 
368
448
  actual = FormatLine.parse!(src)
369
- # FIXME could simplify assert logic?
370
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
449
+ if exp[0] == "/"
371
450
  exp = Regexp.compile(exp[1..-2]) # skip slashes
372
451
  assert_match(exp, actual, msg)
373
452
  else
@@ -383,8 +462,7 @@ end
383
462
  STUFF
384
463
 
385
464
  actual = FormatLine.parse!(src)
386
- # FIXME could simplify assert logic?
387
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
465
+ if exp[0] == "/"
388
466
  exp = Regexp.compile(exp[1..-2]) # skip slashes
389
467
  assert_match(exp, actual, msg)
390
468
  else
@@ -400,8 +478,7 @@ end
400
478
  STUFF
401
479
 
402
480
  actual = FormatLine.parse!(src)
403
- # FIXME could simplify assert logic?
404
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
481
+ if exp[0] == "/"
405
482
  exp = Regexp.compile(exp[1..-2]) # skip slashes
406
483
  assert_match(exp, actual, msg)
407
484
  else
@@ -417,8 +494,7 @@ end
417
494
  STUFF
418
495
 
419
496
  actual = FormatLine.parse!(src)
420
- # FIXME could simplify assert logic?
421
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
497
+ if exp[0] == "/"
422
498
  exp = Regexp.compile(exp[1..-2]) # skip slashes
423
499
  assert_match(exp, actual, msg)
424
500
  else
@@ -434,8 +510,7 @@ end
434
510
  STUFF
435
511
 
436
512
  actual = FormatLine.parse!(src)
437
- # FIXME could simplify assert logic?
438
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
513
+ if exp[0] == "/"
439
514
  exp = Regexp.compile(exp[1..-2]) # skip slashes
440
515
  assert_match(exp, actual, msg)
441
516
  else
@@ -451,8 +526,7 @@ end
451
526
  STUFF
452
527
 
453
528
  actual = FormatLine.parse!(src)
454
- # FIXME could simplify assert logic?
455
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
529
+ if exp[0] == "/"
456
530
  exp = Regexp.compile(exp[1..-2]) # skip slashes
457
531
  assert_match(exp, actual, msg)
458
532
  else
@@ -468,8 +542,7 @@ end
468
542
  STUFF
469
543
 
470
544
  actual = FormatLine.parse!(src)
471
- # FIXME could simplify assert logic?
472
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
545
+ if exp[0] == "/"
473
546
  exp = Regexp.compile(exp[1..-2]) # skip slashes
474
547
  assert_match(exp, actual, msg)
475
548
  else
@@ -485,8 +558,7 @@ end
485
558
  STUFF
486
559
 
487
560
  actual = FormatLine.parse!(src)
488
- # FIXME could simplify assert logic?
489
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
561
+ if exp[0] == "/"
490
562
  exp = Regexp.compile(exp[1..-2]) # skip slashes
491
563
  assert_match(exp, actual, msg)
492
564
  else
@@ -502,8 +574,7 @@ end
502
574
  STUFF
503
575
 
504
576
  actual = FormatLine.parse!(src)
505
- # FIXME could simplify assert logic?
506
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
577
+ if exp[0] == "/"
507
578
  exp = Regexp.compile(exp[1..-2]) # skip slashes
508
579
  assert_match(exp, actual, msg)
509
580
  else
@@ -519,8 +590,7 @@ end
519
590
  STUFF
520
591
 
521
592
  actual = FormatLine.parse!(src)
522
- # FIXME could simplify assert logic?
523
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
593
+ if exp[0] == "/"
524
594
  exp = Regexp.compile(exp[1..-2]) # skip slashes
525
595
  assert_match(exp, actual, msg)
526
596
  else
@@ -536,8 +606,7 @@ end
536
606
  STUFF
537
607
 
538
608
  actual = FormatLine.parse!(src)
539
- # FIXME could simplify assert logic?
540
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
609
+ if exp[0] == "/"
541
610
  exp = Regexp.compile(exp[1..-2]) # skip slashes
542
611
  assert_match(exp, actual, msg)
543
612
  else
@@ -553,8 +622,7 @@ end
553
622
  STUFF
554
623
 
555
624
  actual = FormatLine.parse!(src)
556
- # FIXME could simplify assert logic?
557
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
625
+ if exp[0] == "/"
558
626
  exp = Regexp.compile(exp[1..-2]) # skip slashes
559
627
  assert_match(exp, actual, msg)
560
628
  else
@@ -570,8 +638,7 @@ end
570
638
  STUFF
571
639
 
572
640
  actual = FormatLine.parse!(src)
573
- # FIXME could simplify assert logic?
574
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
641
+ if exp[0] == "/"
575
642
  exp = Regexp.compile(exp[1..-2]) # skip slashes
576
643
  assert_match(exp, actual, msg)
577
644
  else
@@ -587,8 +654,7 @@ end
587
654
  STUFF
588
655
 
589
656
  actual = FormatLine.parse!(src)
590
- # FIXME could simplify assert logic?
591
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
657
+ if exp[0] == "/"
592
658
  exp = Regexp.compile(exp[1..-2]) # skip slashes
593
659
  assert_match(exp, actual, msg)
594
660
  else
@@ -604,8 +670,7 @@ end
604
670
  STUFF
605
671
 
606
672
  actual = FormatLine.parse!(src)
607
- # FIXME could simplify assert logic?
608
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
673
+ if exp[0] == "/"
609
674
  exp = Regexp.compile(exp[1..-2]) # skip slashes
610
675
  assert_match(exp, actual, msg)
611
676
  else
@@ -621,8 +686,7 @@ end
621
686
  STUFF
622
687
 
623
688
  actual = FormatLine.parse!(src)
624
- # FIXME could simplify assert logic?
625
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
689
+ if exp[0] == "/"
626
690
  exp = Regexp.compile(exp[1..-2]) # skip slashes
627
691
  assert_match(exp, actual, msg)
628
692
  else
@@ -638,8 +702,7 @@ end
638
702
  STUFF
639
703
 
640
704
  actual = FormatLine.parse!(src)
641
- # FIXME could simplify assert logic?
642
- if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
705
+ if exp[0] == "/"
643
706
  exp = Regexp.compile(exp[1..-2]) # skip slashes
644
707
  assert_match(exp, actual, msg)
645
708
  else
@@ -648,3 +711,57 @@ end
648
711
  end
649
712
 
650
713
  end
714
+
715
+ # Test generation logic:
716
+
717
+ =begin
718
+ TestLines = []
719
+
720
+ items = []
721
+ formatting_tests = File.open("test/snapshots/formatting-tests.txt")
722
+ loop do
723
+ 4.times { items << formatting_tests.gets.chomp }
724
+ # Blank line terminates each "stanza"
725
+ raise "Oops? #{items.inspect}" unless items.last.empty?
726
+ TestLines << items
727
+ break if formatting_tests.eof?
728
+ end
729
+
730
+ STDERR.puts <<~RUBY
731
+ require 'minitest/autorun'
732
+
733
+ require_relative '../lib/livetext'
734
+
735
+ # Just another testing class. Chill.
736
+
737
+ class TestingLivetext < MiniTest::Test
738
+ RUBY
739
+
740
+ TestLines.each.with_index do |item, num|
741
+ msg, src, exp, blank = *item
742
+ # generate tests...
743
+ name = "test_formatting_#{'%02d' % (num + 1)}"
744
+ method_source = <<~RUBY
745
+ def #{name} # #{msg}
746
+ msg, src, exp = <<~STUFF.split("\\n")
747
+ #{msg}
748
+ #{src}
749
+ #{exp}
750
+ STUFF
751
+
752
+ actual = FormatLine.parse!(src)
753
+ # FIXME could simplify assert logic?
754
+ if exp[0] == "/"
755
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
756
+ assert_match(exp, actual, msg)
757
+ else
758
+ assert_equal(exp, actual, msg)
759
+ end
760
+ end
761
+
762
+ RUBY
763
+ STDERR.puts method_source
764
+ end
765
+ STDERR.puts "\nend"
766
+ end
767
+ =end
@@ -137,30 +137,26 @@ class TestParseSet < MiniTest::Test
137
137
  # - allow/disallow escaping??
138
138
  end
139
139
 
140
- # BUG: FormatLine doesn't know variables in this context!
141
-
142
140
  def test_var_eq_var
143
141
  set = ParseSet.new("file = $File").parse
144
142
  set = set.first # [["var", "value"]]
145
143
  assert_equal set.first, "file"
146
- refute set.last =~ /undefined/, "Found 'undefined' for variable value"
144
+ assert set.last =~ /undefined/, "Found 'undefined' for variable value"
145
+ # ^ ParseSet isn't smart enough to know about variables/functions
147
146
  end
148
147
 
149
- # BUG: ...or functions.
150
- # (Additional bug: Failing silently seems wrong.)
151
-
152
148
  def test_var_eq_func
153
149
  set = ParseSet.new("date = $$date").parse
154
150
  set = set.first # [["var", "value"]]
155
151
  assert_equal set.first, "date"
156
- refute set.last =~ /undefined/, "Found 'undefined' for variable value"
157
- assert set.last =~ /^\d\d.\d\d.\d\d/, "Did not find 6-digit date with two separators"
152
+ assert set.last =~ /undefined/, "Found 'undefined' for variable value"
153
+ # ^ ParseSet isn't smart enough to know about variables/functions
158
154
  end
159
155
 
160
156
  def test_two_strings
161
- line = %[bday="May_31", date="5/31"]
157
+ line = %[bday="May 31", date='5/31']
162
158
  set = ParseSet.new(line).parse
163
- assert set == [["bday", "May_31"], ["date", "5/31"]]
159
+ assert set == [["bday", "May 31"], ["date", "5/31"]]
164
160
  end
165
161
 
166
162
  end