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