livetext 0.9.25 → 0.9.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +3 -2
  3. data/imports/bookish.rb +1 -2
  4. data/lib/livetext/errors.rb +3 -0
  5. data/lib/livetext/expansion.rb +106 -0
  6. data/lib/livetext/formatter.rb +104 -0
  7. data/lib/livetext/functions.rb +9 -0
  8. data/lib/livetext/global_helpers.rb +5 -0
  9. data/lib/livetext/handler/import.rb +2 -6
  10. data/lib/livetext/handler/mixin.rb +2 -6
  11. data/lib/livetext/helpers.rb +30 -27
  12. data/lib/livetext/html.rb +73 -0
  13. data/lib/livetext/more.rb +178 -0
  14. data/lib/livetext/parser/general.rb +1 -1
  15. data/lib/livetext/parser/set.rb +10 -3
  16. data/lib/livetext/parser/string.rb +14 -5
  17. data/lib/livetext/processor.rb +8 -1
  18. data/lib/livetext/skeleton.rb +2 -1
  19. data/lib/livetext/standard.rb +30 -16
  20. data/lib/livetext/userapi.rb +61 -22
  21. data/lib/livetext/version.rb +1 -1
  22. data/lib/livetext.rb +2 -152
  23. data/plugin/bootstrap_menu.rb +140 -0
  24. data/plugin/misc/navbar.rb +162 -0
  25. data/test/snapshots/basic_formatting/expected-output.txt +1 -2
  26. data/test/snapshots/{import_bookish/toc.tmp → bootstrap_menu/expected-error.txt} +0 -0
  27. data/test/snapshots/bootstrap_menu/expected-output.txt +4 -0
  28. data/test/snapshots/bootstrap_menu/source.lt3 +17 -0
  29. data/test/snapshots/error_invalid_name/foo +5 -0
  30. data/test/snapshots/import_bookish/expected-output.txt +4 -4
  31. data/test/snapshots/more_functions/expected-output.txt +1 -1
  32. data/test/snapshots/more_functions/source.lt3 +1 -1
  33. data/test/snapshots/subset.txt +50 -46
  34. data/test/snapshots/{mixin_bookish/toc.tmp → var_into_func/expected-error.txt} +0 -0
  35. data/test/snapshots/var_into_func/expected-output.txt +16 -0
  36. data/test/snapshots/var_into_func/source.lt3 +16 -0
  37. data/test/unit/all.rb +2 -1
  38. data/test/unit/lineparser.rb +359 -0
  39. data/test/unit/new_lineparser.rb +359 -0
  40. data/test/unit/parser/general.rb +2 -2
  41. data/test/unit/parser/set.rb +12 -20
  42. metadata +16 -11
  43. data/lib/livetext/formatline.rb +0 -321
  44. data/lib/livetext/funcall.rb +0 -84
  45. data/test/snapshots/error_inc_line_num/OUT +0 -17
  46. data/test/snapshots/error_no_such_copy/duh +0 -26
  47. data/test/snapshots/error_no_such_copy/mystery.txt +0 -36
  48. data/test/testlines.rb +0 -37
  49. data/test/unit/formatline.rb +0 -769
@@ -1,769 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- require_relative '../../lib/livetext'
4
-
5
- class TestingLivetext < MiniTest::Test
6
-
7
- FormatLine = Livetext::FormatLine
8
-
9
- # Some (most) methods were generated via the code
10
- # seen in the comment at the bottom of this file...
11
-
12
- def test_simple_string
13
- parse = FormatLine.new("only testing")
14
- tokens = parse.tokenize
15
- assert_equal tokens, [[:str, "only testing"]], "Tokens were: #{tokens.inspect}"
16
- expected = "only testing"
17
- result = parse.evaluate
18
- assert_equal expected, result
19
- end
20
-
21
- def test_variable_interpolation
22
- parse = FormatLine.new("File is $File and user is $User")
23
- tokens = parse.tokenize
24
- expected_tokens = [[:str, "File is "],
25
- [:var, "File"],
26
- [:str, " and user is "],
27
- [:var, "User"]]
28
- assert_equal expected_tokens, tokens
29
- result = parse.evaluate
30
- expected = "File is [File is undefined] and user is Hal" # FIXME
31
- assert_equal expected, result
32
- end
33
-
34
- def test_func_expansion
35
- parse = FormatLine.new("myfunc() results in $$myfunc apparently.")
36
- tokens = parse.tokenize
37
- expected_tokens = [[:str, "myfunc() results in "],
38
- [:func, "myfunc"],
39
- [:str, " apparently."]]
40
- assert_equal expected_tokens, tokens
41
- result = parse.evaluate
42
- expected = "myfunc() results in [Error evaluating $$myfunc()] apparently."
43
- assert_equal expected, result
44
- end
45
-
46
- # These tests follow this form:
47
- #
48
- # def test_func_SUFFIX
49
- # str = "WHATEVER"
50
- # parse = FormatLine.new(str)
51
- # tokens_expected = [[], [], ...]
52
- # tokens = parse.tokenize
53
- # assert_equal tokens_expected, tokens
54
- # result = parse.evaluate
55
- # regex_expected = /Today is ....-..-../
56
- # assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
57
- # end
58
-
59
- def test_func_2
60
- str = "Today is $$date"
61
- parse = FormatLine.new(str)
62
- tokens_expected = [[:str, "Today is "], [:func, "date"]]
63
- tokens = parse.tokenize
64
- assert_equal tokens_expected, tokens, "Tokens were: #{tokens.inspect}"
65
- result = parse.evaluate
66
- regex_expected = /Today is ....-..-../
67
- assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
68
- end
69
-
70
- def test_var_before_comma
71
- str = "User name is $User, and all is well"
72
- parse = FormatLine.new(str)
73
- tokens_expected = [[:str, "User name is "], [:var, "User"], [:str, ", and all is well"]]
74
- tokens = parse.tokenize
75
- assert_equal tokens_expected, tokens, "Tokens were: #{tokens.inspect}"
76
- result = parse.evaluate
77
- regex_expected = /User name is .*, /
78
- assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
79
- end
80
-
81
- def test_var_at_EOS
82
- str = "File name is $File"
83
- parse = FormatLine.new(str)
84
- tokens_expected = [[:str, "File name is "], [:var, "File"]]
85
- tokens = parse.tokenize
86
- assert_equal tokens_expected, tokens
87
- result = parse.evaluate
88
- string_expected = "File name is [File is undefined]"
89
- assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
90
- end
91
-
92
- def test_var_starts_string
93
- str = "$File is my file name"
94
- parse = FormatLine.new(str)
95
- tokens_expected = [[:var, "File"], [:str, " is my file name"]]
96
- tokens = parse.tokenize
97
- assert_equal tokens_expected, tokens
98
- result = parse.evaluate
99
- string_expected = "[File is undefined] is my file name"
100
- assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
101
- end
102
-
103
- # Next one is/will be a problem...
104
- # I permit periods *inside* variable names
105
-
106
- def test_var_before_period
107
- str = "This is $File\\." # FIXME escaped for now...
108
- parse = FormatLine.new(str)
109
- tokens_expected = [[:str, "This is "], [:var, "File"], [:str, "."]]
110
- tokens = parse.tokenize
111
- assert_equal tokens_expected, tokens
112
- result = parse.evaluate
113
- string_expected = "This is [File is undefined]."
114
- assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
115
- end
116
-
117
- def test_func_needing_parameter_colon_eos # colon, param, EOS
118
- str = "Square root of 225 is $$isqrt:225"
119
- parse = FormatLine.new(str)
120
- tokens_expected = [[:str, "Square root of 225 is "], [:func, "isqrt"], [:colon, "225"]]
121
- tokens = parse.tokenize
122
- assert_equal tokens_expected, tokens
123
- result = parse.evaluate
124
- string_expected = "Square root of 225 is 15"
125
- assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
126
- end
127
-
128
- def test_func_needing_parameter_colon # colon, param, more chars
129
- str = "Answer is $$isqrt:225 today"
130
- parse = FormatLine.new(str)
131
- tokens_expected = [[:str, "Answer is "],
132
- [:func, "isqrt"],
133
- [:colon, "225"],
134
- [:str, " today"]]
135
- tokens = parse.tokenize
136
- assert_equal tokens_expected, tokens
137
- result = parse.evaluate
138
- string_expected = "Answer is 15 today"
139
- assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
140
- end
141
-
142
- # isqrt: Not real tests??
143
-
144
- def test_isqrt_empty_colon_param
145
- str = "Calculate $$isqrt:"
146
- parse = FormatLine.new(str)
147
- tokens_expected = [[:str, "Calculate "],
148
- [:func, "isqrt"] # , [:colon, ""]
149
- ]
150
- # If param is null, we don't get [:colon, value]!
151
- # ^ FIXME function should be more like: [:func, name, param]
152
- tokens = parse.tokenize
153
- assert_equal tokens_expected, tokens
154
- result = parse.evaluate
155
- string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]"
156
- assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
157
- end
158
-
159
- def test_isqrt_empty_bracket_param
160
- str = "Calculate $$isqrt[]"
161
- parse = FormatLine.new(str)
162
- tokens_expected = [[:str, "Calculate "],
163
- [:func, "isqrt"] # , [:colon, ""]
164
- ]
165
- # If param is null, we don't get [:colon, value]!
166
- # ^ FIXME function should be more like: [:func, name, param]
167
- tokens = parse.tokenize
168
- assert_equal tokens_expected, tokens
169
- result = parse.evaluate
170
- string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]"
171
- assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
172
- end
173
-
174
- def test_isqrt_malformed_number
175
- str = "Calculate $$isqrt[3a5]"
176
- parse = FormatLine.new(str)
177
- tokens_expected = [[:str, "Calculate "],
178
- [:func, "isqrt"],
179
- [:brackets, "3a5"]
180
- ]
181
- # ^ FIXME function should be more like: [:func, name, param]
182
- tokens = parse.tokenize
183
- assert_equal tokens_expected, tokens
184
- result = parse.evaluate
185
- string_expected = "Calculate [Error evaluating $$isqrt(3a5)]"
186
- assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
187
- end
188
-
189
- # ...end of this group
190
-
191
- def test_func_with_colon
192
- parse = FormatLine.new("Calling $$myfunc:foo here.")
193
- tokens = parse.tokenize
194
- assert_equal tokens, [[:str, "Calling "],
195
- [:func, "myfunc"],
196
- [:colon, "foo"],
197
- [:str, " here."]
198
- ]
199
- result = parse.evaluate
200
- expected = "Calling [Error evaluating $$myfunc(foo)] here."
201
- assert_equal expected, result
202
- end
203
-
204
- def test_func_with_brackets
205
- parse = FormatLine.new("Calling $$myfunc2[foo bar] here.")
206
- tokens = parse.tokenize
207
- assert_kind_of Array, tokens
208
- assert_equal 4, tokens.size
209
- expected_tokens = [[:str, "Calling "],
210
- [:func, "myfunc2"],
211
- [:brackets, "foo bar"],
212
- [:str, " here."]]
213
- assert_equal expected_tokens, tokens
214
- result = parse.evaluate
215
- expected = "Calling [Error evaluating $$myfunc2(foo bar)] here."
216
- assert_equal expected, result
217
- end
218
-
219
- def test_formatting_01 # Check output of $$date
220
- msg, src, exp = <<~STUFF.split("\n")
221
- Check output of $$date
222
- Today is $$date, I guess
223
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
224
- STUFF
225
-
226
- actual = FormatLine.parse!(src)
227
- if exp[0] == "/"
228
- exp = Regexp.compile(exp[1..-2]) # skip slashes
229
- assert_match(exp, actual, msg)
230
- else
231
- assert_equal(exp, actual, msg)
232
- end
233
- end
234
-
235
- def test_formatting_02 # Check output of $$date
236
- msg, src, exp = <<~STUFF.split("\n")
237
- Check output of $$date
238
- Today is $$date, I guess
239
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
240
- STUFF
241
-
242
- actual = FormatLine.parse!(src)
243
- if exp[0] == "/"
244
- exp = Regexp.compile(exp[1..-2]) # skip slashes
245
- assert_match(exp, actual, msg)
246
- else
247
- assert_equal(exp, actual, msg)
248
- end
249
- end
250
-
251
- def test_formatting_03 # Check output of $$date
252
- msg, src, exp = <<~STUFF.split("\n")
253
- Check output of $$date
254
- Today is $$date, I guess
255
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
256
- STUFF
257
-
258
- actual = FormatLine.parse!(src)
259
- if exp[0] == "/"
260
- exp = Regexp.compile(exp[1..-2]) # skip slashes
261
- assert_match(exp, actual, msg)
262
- else
263
- assert_equal(exp, actual, msg)
264
- end
265
- end
266
-
267
- def test_formatting_04 # Check output of $$date
268
- msg, src, exp = <<~STUFF.split("\n")
269
- Check output of $$date
270
- Today is $$date, I guess
271
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
272
- STUFF
273
-
274
- actual = FormatLine.parse!(src)
275
- if exp[0] == "/"
276
- exp = Regexp.compile(exp[1..-2]) # skip slashes
277
- assert_match(exp, actual, msg)
278
- else
279
- assert_equal(exp, actual, msg)
280
- end
281
- end
282
-
283
- def test_formatting_05 # Check output of $$date
284
- msg, src, exp = <<~STUFF.split("\n")
285
- Check output of $$date
286
- Today is $$date, I guess
287
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
288
- STUFF
289
-
290
- actual = FormatLine.parse!(src)
291
- if exp[0] == "/"
292
- exp = Regexp.compile(exp[1..-2]) # skip slashes
293
- assert_match(exp, actual, msg)
294
- else
295
- assert_equal(exp, actual, msg)
296
- end
297
- end
298
-
299
- def test_formatting_06 # Check output of $$date
300
- msg, src, exp = <<~STUFF.split("\n")
301
- Check output of $$date
302
- Today is $$date, I guess
303
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
304
- STUFF
305
-
306
- actual = FormatLine.parse!(src)
307
- if exp[0] == "/"
308
- exp = Regexp.compile(exp[1..-2]) # skip slashes
309
- assert_match(exp, actual, msg)
310
- else
311
- assert_equal(exp, actual, msg)
312
- end
313
- end
314
-
315
- def test_formatting_07 # Check output of $$date
316
- msg, src, exp = <<~STUFF.split("\n")
317
- Check output of $$date
318
- Today is $$date, I guess
319
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
320
- STUFF
321
-
322
- actual = FormatLine.parse!(src)
323
- if exp[0] == "/"
324
- exp = Regexp.compile(exp[1..-2]) # skip slashes
325
- assert_match(exp, actual, msg)
326
- else
327
- assert_equal(exp, actual, msg)
328
- end
329
- end
330
-
331
- def test_formatting_08 # Check output of $$date
332
- msg, src, exp = <<~STUFF.split("\n")
333
- Check output of $$date
334
- Today is $$date, I guess
335
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
336
- STUFF
337
-
338
- actual = FormatLine.parse!(src)
339
- if exp[0] == "/"
340
- exp = Regexp.compile(exp[1..-2]) # skip slashes
341
- assert_match(exp, actual, msg)
342
- else
343
- assert_equal(exp, actual, msg)
344
- end
345
- end
346
-
347
- def test_formatting_09 # Check output of $$date
348
- msg, src, exp = <<~STUFF.split("\n")
349
- Check output of $$date
350
- Today is $$date, I guess
351
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
352
- STUFF
353
-
354
- actual = FormatLine.parse!(src)
355
- if exp[0] == "/"
356
- exp = Regexp.compile(exp[1..-2]) # skip slashes
357
- assert_match(exp, actual, msg)
358
- else
359
- assert_equal(exp, actual, msg)
360
- end
361
- end
362
-
363
- def test_formatting_10 # Check output of $$date
364
- msg, src, exp = <<~STUFF.split("\n")
365
- Check output of $$date
366
- Today is $$date, I guess
367
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
368
- STUFF
369
-
370
- actual = FormatLine.parse!(src)
371
- if exp[0] == "/"
372
- exp = Regexp.compile(exp[1..-2]) # skip slashes
373
- assert_match(exp, actual, msg)
374
- else
375
- assert_equal(exp, actual, msg)
376
- end
377
- end
378
-
379
- def test_formatting_11 # Check output of $$date
380
- msg, src, exp = <<~STUFF.split("\n")
381
- Check output of $$date
382
- Today is $$date, I guess
383
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
384
- STUFF
385
-
386
- actual = FormatLine.parse!(src)
387
- if exp[0] == "/"
388
- exp = Regexp.compile(exp[1..-2]) # skip slashes
389
- assert_match(exp, actual, msg)
390
- else
391
- assert_equal(exp, actual, msg)
392
- end
393
- end
394
-
395
- def test_formatting_12 # Check output of $$date
396
- msg, src, exp = <<~STUFF.split("\n")
397
- Check output of $$date
398
- Today is $$date, I guess
399
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
400
- STUFF
401
-
402
- actual = FormatLine.parse!(src)
403
- if exp[0] == "/"
404
- exp = Regexp.compile(exp[1..-2]) # skip slashes
405
- assert_match(exp, actual, msg)
406
- else
407
- assert_equal(exp, actual, msg)
408
- end
409
- end
410
-
411
- def test_formatting_13 # Check output of $$date
412
- msg, src, exp = <<~STUFF.split("\n")
413
- Check output of $$date
414
- Today is $$date, I guess
415
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
416
- STUFF
417
-
418
- actual = FormatLine.parse!(src)
419
- if exp[0] == "/"
420
- exp = Regexp.compile(exp[1..-2]) # skip slashes
421
- assert_match(exp, actual, msg)
422
- else
423
- assert_equal(exp, actual, msg)
424
- end
425
- end
426
-
427
- def test_formatting_14 # Check output of $$date
428
- msg, src, exp = <<~STUFF.split("\n")
429
- Check output of $$date
430
- Today is $$date, I guess
431
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
432
- STUFF
433
-
434
- actual = FormatLine.parse!(src)
435
- if exp[0] == "/"
436
- exp = Regexp.compile(exp[1..-2]) # skip slashes
437
- assert_match(exp, actual, msg)
438
- else
439
- assert_equal(exp, actual, msg)
440
- end
441
- end
442
-
443
- def test_formatting_15 # Check output of $$date
444
- msg, src, exp = <<~STUFF.split("\n")
445
- Check output of $$date
446
- Today is $$date, I guess
447
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
448
- STUFF
449
-
450
- actual = FormatLine.parse!(src)
451
- if exp[0] == "/"
452
- exp = Regexp.compile(exp[1..-2]) # skip slashes
453
- assert_match(exp, actual, msg)
454
- else
455
- assert_equal(exp, actual, msg)
456
- end
457
- end
458
-
459
- def test_formatting_16 # Check output of $$date
460
- msg, src, exp = <<~STUFF.split("\n")
461
- Check output of $$date
462
- Today is $$date, I guess
463
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
464
- STUFF
465
-
466
- actual = FormatLine.parse!(src)
467
- if exp[0] == "/"
468
- exp = Regexp.compile(exp[1..-2]) # skip slashes
469
- assert_match(exp, actual, msg)
470
- else
471
- assert_equal(exp, actual, msg)
472
- end
473
- end
474
-
475
- def test_formatting_17 # Check output of $$date
476
- msg, src, exp = <<~STUFF.split("\n")
477
- Check output of $$date
478
- Today is $$date, I guess
479
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
480
- STUFF
481
-
482
- actual = FormatLine.parse!(src)
483
- if exp[0] == "/"
484
- exp = Regexp.compile(exp[1..-2]) # skip slashes
485
- assert_match(exp, actual, msg)
486
- else
487
- assert_equal(exp, actual, msg)
488
- end
489
- end
490
-
491
- def test_formatting_18 # Check output of $$date
492
- msg, src, exp = <<~STUFF.split("\n")
493
- Check output of $$date
494
- Today is $$date, I guess
495
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
496
- STUFF
497
-
498
- actual = FormatLine.parse!(src)
499
- if exp[0] == "/"
500
- exp = Regexp.compile(exp[1..-2]) # skip slashes
501
- assert_match(exp, actual, msg)
502
- else
503
- assert_equal(exp, actual, msg)
504
- end
505
- end
506
-
507
- def test_formatting_19 # Check output of $$date
508
- msg, src, exp = <<~STUFF.split("\n")
509
- Check output of $$date
510
- Today is $$date, I guess
511
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
512
- STUFF
513
-
514
- actual = FormatLine.parse!(src)
515
- if exp[0] == "/"
516
- exp = Regexp.compile(exp[1..-2]) # skip slashes
517
- assert_match(exp, actual, msg)
518
- else
519
- assert_equal(exp, actual, msg)
520
- end
521
- end
522
-
523
- def test_formatting_20 # Check output of $$date
524
- msg, src, exp = <<~STUFF.split("\n")
525
- Check output of $$date
526
- Today is $$date, I guess
527
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
528
- STUFF
529
-
530
- actual = FormatLine.parse!(src)
531
- if exp[0] == "/"
532
- exp = Regexp.compile(exp[1..-2]) # skip slashes
533
- assert_match(exp, actual, msg)
534
- else
535
- assert_equal(exp, actual, msg)
536
- end
537
- end
538
-
539
- def test_formatting_21 # Check output of $$date
540
- msg, src, exp = <<~STUFF.split("\n")
541
- Check output of $$date
542
- Today is $$date, I guess
543
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
544
- STUFF
545
-
546
- actual = FormatLine.parse!(src)
547
- if exp[0] == "/"
548
- exp = Regexp.compile(exp[1..-2]) # skip slashes
549
- assert_match(exp, actual, msg)
550
- else
551
- assert_equal(exp, actual, msg)
552
- end
553
- end
554
-
555
- def test_formatting_22 # Check output of $$date
556
- msg, src, exp = <<~STUFF.split("\n")
557
- Check output of $$date
558
- Today is $$date, I guess
559
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
560
- STUFF
561
-
562
- actual = FormatLine.parse!(src)
563
- if exp[0] == "/"
564
- exp = Regexp.compile(exp[1..-2]) # skip slashes
565
- assert_match(exp, actual, msg)
566
- else
567
- assert_equal(exp, actual, msg)
568
- end
569
- end
570
-
571
- def test_formatting_23 # Check output of $$date
572
- msg, src, exp = <<~STUFF.split("\n")
573
- Check output of $$date
574
- Today is $$date, I guess
575
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
576
- STUFF
577
-
578
- actual = FormatLine.parse!(src)
579
- if exp[0] == "/"
580
- exp = Regexp.compile(exp[1..-2]) # skip slashes
581
- assert_match(exp, actual, msg)
582
- else
583
- assert_equal(exp, actual, msg)
584
- end
585
- end
586
-
587
- def test_formatting_24 # Check output of $$date
588
- msg, src, exp = <<~STUFF.split("\n")
589
- Check output of $$date
590
- Today is $$date, I guess
591
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
592
- STUFF
593
-
594
- actual = FormatLine.parse!(src)
595
- if exp[0] == "/"
596
- exp = Regexp.compile(exp[1..-2]) # skip slashes
597
- assert_match(exp, actual, msg)
598
- else
599
- assert_equal(exp, actual, msg)
600
- end
601
- end
602
-
603
- def test_formatting_25 # Check output of $$date
604
- msg, src, exp = <<~STUFF.split("\n")
605
- Check output of $$date
606
- Today is $$date, I guess
607
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
608
- STUFF
609
-
610
- actual = FormatLine.parse!(src)
611
- if exp[0] == "/"
612
- exp = Regexp.compile(exp[1..-2]) # skip slashes
613
- assert_match(exp, actual, msg)
614
- else
615
- assert_equal(exp, actual, msg)
616
- end
617
- end
618
-
619
- def test_formatting_26 # Check output of $$date
620
- msg, src, exp = <<~STUFF.split("\n")
621
- Check output of $$date
622
- Today is $$date, I guess
623
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
624
- STUFF
625
-
626
- actual = FormatLine.parse!(src)
627
- if exp[0] == "/"
628
- exp = Regexp.compile(exp[1..-2]) # skip slashes
629
- assert_match(exp, actual, msg)
630
- else
631
- assert_equal(exp, actual, msg)
632
- end
633
- end
634
-
635
- def test_formatting_27 # Check output of $$date
636
- msg, src, exp = <<~STUFF.split("\n")
637
- Check output of $$date
638
- Today is $$date, I guess
639
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
640
- STUFF
641
-
642
- actual = FormatLine.parse!(src)
643
- if exp[0] == "/"
644
- exp = Regexp.compile(exp[1..-2]) # skip slashes
645
- assert_match(exp, actual, msg)
646
- else
647
- assert_equal(exp, actual, msg)
648
- end
649
- end
650
-
651
- def test_formatting_28 # Check output of $$date
652
- msg, src, exp = <<~STUFF.split("\n")
653
- Check output of $$date
654
- Today is $$date, I guess
655
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
656
- STUFF
657
-
658
- actual = FormatLine.parse!(src)
659
- if exp[0] == "/"
660
- exp = Regexp.compile(exp[1..-2]) # skip slashes
661
- assert_match(exp, actual, msg)
662
- else
663
- assert_equal(exp, actual, msg)
664
- end
665
- end
666
-
667
- def test_formatting_29 # Check output of $$date
668
- msg, src, exp = <<~STUFF.split("\n")
669
- Check output of $$date
670
- Today is $$date, I guess
671
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
672
- STUFF
673
-
674
- actual = FormatLine.parse!(src)
675
- if exp[0] == "/"
676
- exp = Regexp.compile(exp[1..-2]) # skip slashes
677
- assert_match(exp, actual, msg)
678
- else
679
- assert_equal(exp, actual, msg)
680
- end
681
- end
682
-
683
- def test_formatting_30 # Check output of $$date
684
- msg, src, exp = <<~STUFF.split("\n")
685
- Check output of $$date
686
- Today is $$date, I guess
687
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
688
- STUFF
689
-
690
- actual = FormatLine.parse!(src)
691
- if exp[0] == "/"
692
- exp = Regexp.compile(exp[1..-2]) # skip slashes
693
- assert_match(exp, actual, msg)
694
- else
695
- assert_equal(exp, actual, msg)
696
- end
697
- end
698
-
699
- def test_formatting_31 # Check output of $$date
700
- msg, src, exp = <<~STUFF.split("\n")
701
- Check output of $$date
702
- Today is $$date, I guess
703
- /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
704
- STUFF
705
-
706
- actual = FormatLine.parse!(src)
707
- if exp[0] == "/"
708
- exp = Regexp.compile(exp[1..-2]) # skip slashes
709
- assert_match(exp, actual, msg)
710
- else
711
- assert_equal(exp, actual, msg)
712
- end
713
- end
714
-
715
- end
716
-
717
- # Test generation logic:
718
-
719
- =begin
720
- TestLines = []
721
-
722
- items = []
723
- formatting_tests = File.open("test/snapshots/formatting-tests.txt")
724
- loop do
725
- 4.times { items << formatting_tests.gets.chomp }
726
- # Blank line terminates each "stanza"
727
- raise "Oops? #{items.inspect}" unless items.last.empty?
728
- TestLines << items
729
- break if formatting_tests.eof?
730
- end
731
-
732
- STDERR.puts <<~RUBY
733
- require 'minitest/autorun'
734
-
735
- require_relative '../lib/livetext'
736
-
737
- # Just another testing class. Chill.
738
-
739
- class TestingLivetext < MiniTest::Test
740
- RUBY
741
-
742
- TestLines.each.with_index do |item, num|
743
- msg, src, exp, blank = *item
744
- # generate tests...
745
- name = "test_formatting_#{'%02d' % (num + 1)}"
746
- method_source = <<~RUBY
747
- def #{name} # #{msg}
748
- msg, src, exp = <<~STUFF.split("\\n")
749
- #{msg}
750
- #{src}
751
- #{exp}
752
- STUFF
753
-
754
- actual = FormatLine.parse!(src)
755
- # FIXME could simplify assert logic?
756
- if exp[0] == "/"
757
- exp = Regexp.compile(exp[1..-2]) # skip slashes
758
- assert_match(exp, actual, msg)
759
- else
760
- assert_equal(exp, actual, msg)
761
- end
762
- end
763
-
764
- RUBY
765
- STDERR.puts method_source
766
- end
767
- STDERR.puts "\nend"
768
- end
769
- =end