livetext 0.9.27 → 0.9.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +3 -2
- data/imports/bookish.rb +1 -1
- data/lib/livetext/expansion.rb +108 -0
- data/lib/livetext/formatter.rb +223 -0
- data/lib/livetext/functions.rb +9 -0
- data/lib/livetext/helpers.rb +41 -29
- data/lib/livetext/html.rb +73 -0
- data/lib/livetext/more.rb +33 -13
- data/lib/livetext/parser/general.rb +1 -1
- data/lib/livetext/parser/set.rb +10 -3
- data/lib/livetext/processor.rb +5 -0
- data/lib/livetext/standard.rb +67 -67
- data/lib/livetext/userapi.rb +41 -19
- data/lib/livetext/version.rb +1 -1
- data/lib/livetext.rb +1 -1
- data/plugin/bookish.rb +1 -1
- data/plugin/bootstrap_menu.rb +140 -0
- data/plugin/misc/navbar.rb +162 -0
- data/test/extra/README.txt +149 -0
- data/test/extra/bracketed.rb +121 -0
- data/test/extra/bracketed.txt +44 -0
- data/test/extra/double.rb +121 -0
- data/test/extra/double.txt +44 -0
- data/test/extra/functions.rb +148 -0
- data/test/extra/functions.txt +58 -0
- data/test/extra/single.rb +139 -0
- data/test/extra/single.txt +52 -0
- data/test/extra/testgen.rb +104 -0
- data/test/extra/variables.rb +94 -0
- data/test/extra/variables.txt +35 -0
- data/test/snapshots/basic_formatting/expected-output.txt +2 -2
- data/test/snapshots/simple_vars/source.lt3 +1 -1
- data/test/snapshots/subset.txt +49 -49
- data/test/unit/all.rb +1 -2
- data/test/unit/parser/general.rb +2 -2
- data/test/unit/parser/set.rb +0 -9
- metadata +18 -34
- data/lib/livetext/funcall.rb +0 -87
- data/lib/livetext/lineparser.rb +0 -575
- data/test/snapshots/basic_formatting/actual-error.txt +0 -0
- data/test/snapshots/basic_formatting/actual-output.txt +0 -13
- data/test/snapshots/basic_formatting/err-sdiff.txt +0 -1
- data/test/snapshots/basic_formatting/out-sdiff.txt +0 -14
- data/test/snapshots/error_inc_line_num/README.txt +0 -20
- data/test/snapshots/error_invalid_name/foo +0 -5
- data/test/snapshots/functions/actual-error.txt +0 -19
- data/test/snapshots/functions/actual-output.txt +0 -0
- data/test/snapshots/functions/err-sdiff.txt +0 -20
- data/test/snapshots/more_complex_vars/actual-error.txt +0 -0
- data/test/snapshots/more_complex_vars/actual-output.txt +0 -4
- data/test/snapshots/more_complex_vars/err-sdiff.txt +0 -1
- data/test/snapshots/more_complex_vars/out-sdiff.txt +0 -5
- data/test/snapshots/more_functions/actual-error.txt +0 -19
- data/test/snapshots/more_functions/actual-output.txt +0 -0
- data/test/snapshots/more_functions/err-sdiff.txt +0 -20
- data/test/snapshots/raw_lines/actual-error.txt +0 -22
- data/test/snapshots/raw_lines/actual-output.txt +0 -0
- data/test/snapshots/raw_lines/err-sdiff.txt +0 -23
- data/test/snapshots/simple_vars/actual-error.txt +0 -0
- data/test/snapshots/simple_vars/actual-output.txt +0 -6
- data/test/snapshots/simple_vars/err-sdiff.txt +0 -1
- data/test/snapshots/simple_vars/out-sdiff.txt +0 -7
- data/test/snapshots/var_into_func/actual-error.txt +0 -19
- data/test/snapshots/var_into_func/actual-output.txt +0 -0
- data/test/snapshots/var_into_func/err-sdiff.txt +0 -20
- data/test/snapshots/var_into_func/out-sdiff.txt +0 -17
- data/test/unit/lineparser.rb +0 -359
- data/test/unit/new_lineparser.rb +0 -359
- data/test/unit/tokenizer.rb +0 -535
data/test/unit/new_lineparser.rb
DELETED
@@ -1,359 +0,0 @@
|
|
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.parse_variables # .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.parse_variables # 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_NEW_var_expansion
|
61
|
-
parse = LineParser.new("File is $File and user is $User")
|
62
|
-
expected = "File is [File is undefined] and user is Hal" # FIXME
|
63
|
-
str = parse.parse_variables
|
64
|
-
assert_equal expected, str
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_func_expansion
|
68
|
-
parse = LineParser.new("myfunc() results in $$myfunc apparently.")
|
69
|
-
tokens = parse.parse_functions # .tokenize
|
70
|
-
expected_tokens = [[:str, "myfunc() results in "],
|
71
|
-
[:func, "myfunc", nil, nil],
|
72
|
-
[:str, " apparently."]]
|
73
|
-
assert_equal expected_tokens, tokens
|
74
|
-
# result = parse.evaluate
|
75
|
-
# expected = "myfunc() results in [Error evaluating $$myfunc()] apparently."
|
76
|
-
# assert_equal expected, result
|
77
|
-
end
|
78
|
-
|
79
|
-
# These tests follow this form:
|
80
|
-
#
|
81
|
-
# def xtest_func_SUFFIX
|
82
|
-
# str = "WHATEVER"
|
83
|
-
# parse = LineParser.new(str)
|
84
|
-
# tokens_expected = [[], [], ...]
|
85
|
-
# tokens = parse.tokenize
|
86
|
-
# assert_equal tokens_expected, tokens
|
87
|
-
# result = parse.evaluate
|
88
|
-
# regex_expected = /Today is ....-..-../
|
89
|
-
# assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
|
90
|
-
# end
|
91
|
-
|
92
|
-
def test_func_2
|
93
|
-
str = "Today is $$date"
|
94
|
-
parse = LineParser.new(str)
|
95
|
-
tokens_expected = [[:str, "Today is "], [:func, "date", nil, nil]]
|
96
|
-
tokens = parse.parse_functions # tokenize
|
97
|
-
assert_equal tokens_expected, tokens, "Tokens were: #{tokens.inspect}"
|
98
|
-
result = parse.evaluate
|
99
|
-
regex_expected = /Today is ....-..-../
|
100
|
-
assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_var_before_comma
|
104
|
-
str = "User name is $User, and all is well"
|
105
|
-
parse = LineParser.new(str)
|
106
|
-
tokens_expected = [[:str, "User name is "], [:var, "User"], [:str, ", and all is well"]]
|
107
|
-
tokens = parse.parse_variables # tokenize
|
108
|
-
assert_equal tokens_expected, tokens, "Tokens were: #{tokens.inspect}"
|
109
|
-
result = parse.evaluate
|
110
|
-
regex_expected = /User name is .*, /
|
111
|
-
assert_match regex_expected, result, "Found unexpected: #{result.inspect}"
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_var_at_EOS
|
115
|
-
str = "File name is $File"
|
116
|
-
parse = LineParser.new(str)
|
117
|
-
tokens_expected = [[:str, "File name is "], [:var, "File"]]
|
118
|
-
tokens = parse.parse_variables # tokenize
|
119
|
-
assert_equal tokens_expected, tokens
|
120
|
-
result = parse.evaluate
|
121
|
-
string_expected = "File name is [File is undefined]"
|
122
|
-
assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_var_starts_string
|
126
|
-
str = "$File is my file name"
|
127
|
-
parse = LineParser.new(str)
|
128
|
-
tokens_expected = [[:var, "File"], [:str, " is my file name"]]
|
129
|
-
tokens = parse.parse_variables # tokenize
|
130
|
-
assert_equal tokens_expected, tokens
|
131
|
-
result = parse.evaluate
|
132
|
-
string_expected = "[File is undefined] is my file name"
|
133
|
-
assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
134
|
-
end
|
135
|
-
|
136
|
-
# Next one is/will be a problem...
|
137
|
-
# I permit periods *inside* variable names
|
138
|
-
|
139
|
-
def test_var_before_period
|
140
|
-
str = "This is $File\\." # FIXME escaped for now...
|
141
|
-
parse = LineParser.new(str)
|
142
|
-
tokens_expected = [[:str, "This is "], [:var, "File"], [:str, "."]]
|
143
|
-
tokens = parse.tokenize
|
144
|
-
assert_equal tokens_expected, tokens
|
145
|
-
result = parse.evaluate
|
146
|
-
string_expected = "This is [File is undefined]."
|
147
|
-
assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_func_needing_parameter_colon_eos # colon, param, EOS
|
151
|
-
str = "Square root of 225 is $$isqrt:225"
|
152
|
-
parse = LineParser.new(str)
|
153
|
-
tokens_expected = [[:str, "Square root of 225 is "], [:func, "isqrt", :colon, "225"]]
|
154
|
-
tokens = parse.parse_functions # tokenize
|
155
|
-
assert_equal tokens_expected, tokens
|
156
|
-
# result = parse.evaluate
|
157
|
-
# string_expected = "Square root of 225 is 15"
|
158
|
-
# assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_func_needing_parameter_colon # colon, param, more chars
|
162
|
-
str = "Answer is $$isqrt:225 today"
|
163
|
-
parse = LineParser.new(str)
|
164
|
-
tokens_expected = [[:str, "Answer is "],
|
165
|
-
[:func, "isqrt", :colon, "225"],
|
166
|
-
[:str, " today"]]
|
167
|
-
tokens = parse.parse_functions # tokenize
|
168
|
-
assert_equal tokens_expected, tokens
|
169
|
-
# result = parse.evaluate
|
170
|
-
# string_expected = "Answer is 15 today"
|
171
|
-
# assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
172
|
-
end
|
173
|
-
|
174
|
-
# isqrt: Not real tests??
|
175
|
-
|
176
|
-
def test_isqrt_empty_colon_param
|
177
|
-
str = "Calculate $$isqrt:"
|
178
|
-
parse = LineParser.new(str)
|
179
|
-
tokens_expected = [[:str, "Calculate "],
|
180
|
-
[:func, "isqrt", :colon, ""]]
|
181
|
-
tokens = parse.parse_functions # tokenize
|
182
|
-
assert_equal tokens_expected, tokens
|
183
|
-
# result = parse.evaluate
|
184
|
-
# string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]"
|
185
|
-
# assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
186
|
-
end
|
187
|
-
|
188
|
-
def test_isqrt_empty_bracket_param
|
189
|
-
str = "Calculate $$isqrt[]"
|
190
|
-
parse = LineParser.new(str)
|
191
|
-
tokens_expected = [[:str, "Calculate "],
|
192
|
-
[:func, "isqrt", :brackets, ""] # , [:colon, ""]
|
193
|
-
]
|
194
|
-
# If param is null, we don't get [:colon, value]!
|
195
|
-
# ^ FIXME function should be more like: [:func, name, param]
|
196
|
-
tokens = parse.parse_functions # tokenize
|
197
|
-
assert_equal tokens_expected, tokens
|
198
|
-
# result = parse.evaluate
|
199
|
-
# string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]"
|
200
|
-
# assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_isqrt_malformed_number
|
204
|
-
str = "Calculate $$isqrt[3a5]"
|
205
|
-
parse = LineParser.new(str)
|
206
|
-
tokens_expected = [[:str, "Calculate "],
|
207
|
-
[:func, "isqrt", :brackets, "3a5"]
|
208
|
-
]
|
209
|
-
# ^ FIXME function should be more like: [:func, name, param]
|
210
|
-
tokens = parse.parse_functions # tokenize
|
211
|
-
assert_equal tokens_expected, tokens
|
212
|
-
# result = parse.evaluate
|
213
|
-
# string_expected = "Calculate [Error evaluating $$isqrt(3a5)]"
|
214
|
-
# assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
215
|
-
end
|
216
|
-
|
217
|
-
# ...end of this group
|
218
|
-
|
219
|
-
def test_func_with_colon
|
220
|
-
parse = LineParser.new("Calling $$myfunc:foo here.")
|
221
|
-
tokens = parse.parse_functions # tokenize
|
222
|
-
assert_equal tokens, [[:str, "Calling "],
|
223
|
-
[:func, "myfunc", :colon, "foo"],
|
224
|
-
[:str, " here."]]
|
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.parse_functions # .tokenize
|
233
|
-
expected_tokens = [[:str, "Calling "],
|
234
|
-
[:func, "myfunc2", :brackets, "foo bar"],
|
235
|
-
[:str, " here."]]
|
236
|
-
assert_equal expected_tokens, tokens
|
237
|
-
# result = parse.evaluate
|
238
|
-
# expected = "Calling [Error evaluating $$myfunc2(foo bar)] here."
|
239
|
-
# assert_equal expected, result
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_parse_formatting
|
243
|
-
msg, src, exp = <<~STUFF.split("\n")
|
244
|
-
Check simple formatting
|
245
|
-
This is *bold and _italics ...
|
246
|
-
This is <b>bold</b> and <i>italics</i> ...
|
247
|
-
STUFF
|
248
|
-
invoke_test(msg, src, exp)
|
249
|
-
end
|
250
|
-
|
251
|
-
def test_formatting_01 # 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
|
-
invoke_test(msg, src, exp)
|
258
|
-
end
|
259
|
-
|
260
|
-
def test_formatting_32 # Check "real" dollar signs
|
261
|
-
msg, src, exp = <<~STUFF.split("\n")
|
262
|
-
Check "real" dollar signs
|
263
|
-
You paid $75 for that item.
|
264
|
-
You paid $75 for that item.
|
265
|
-
STUFF
|
266
|
-
invoke_test(msg, src, exp)
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_formatting_33 # Check dollar-space
|
270
|
-
msg, src, exp = <<~STUFF.split("\n")
|
271
|
-
Check dollar-space
|
272
|
-
He paid $ 76 for it...
|
273
|
-
He paid $ 76 for it...
|
274
|
-
STUFF
|
275
|
-
invoke_test(msg, src, exp)
|
276
|
-
end
|
277
|
-
|
278
|
-
def test_formatting_34 # Check escaped dollar signs
|
279
|
-
msg, src, exp = <<~STUFF.split("\n")
|
280
|
-
Check escaped dollar signs
|
281
|
-
Paid \\$78 yo
|
282
|
-
Paid $78 yo
|
283
|
-
STUFF
|
284
|
-
invoke_test(msg, src, exp)
|
285
|
-
end
|
286
|
-
|
287
|
-
def test_formatting_35 # Check ignored function param (bug or feature?)
|
288
|
-
msg, src, exp = <<~STUFF.split("\n")
|
289
|
-
Check ignored function param (bug or feature?)
|
290
|
-
Today is $$date:foobar, apparently.
|
291
|
-
/Today is \\d\\d\\d\\d.\\d\\d.\\d\\d apparently./
|
292
|
-
STUFF
|
293
|
-
invoke_test(msg, src, exp)
|
294
|
-
end
|
295
|
-
|
296
|
-
def test_formatting_36 # Check ignored function bracket param (bug or feature?)
|
297
|
-
msg, src, exp = <<~STUFF.split("\n")
|
298
|
-
Check ignored function bracket param (bug or feature?)
|
299
|
-
Today is $$date[a useless parameter], apparently.
|
300
|
-
/Today is \\d\\\d\\d\\d.\\d\\d.\\d\\d, apparently./
|
301
|
-
STUFF
|
302
|
-
invoke_test(msg, src, exp)
|
303
|
-
end
|
304
|
-
|
305
|
-
end
|
306
|
-
|
307
|
-
# Test generation logic:
|
308
|
-
|
309
|
-
=begin
|
310
|
-
TestLines = []
|
311
|
-
|
312
|
-
items = []
|
313
|
-
formatting_tests = File.open("test/snapshots/formatting-tests.txt")
|
314
|
-
loop do
|
315
|
-
4.times { items << formatting_tests.gets.chomp }
|
316
|
-
# Blank line terminates each "stanza"
|
317
|
-
raise "Oops? #{items.inspect}" unless items.last.empty?
|
318
|
-
TestLines << items
|
319
|
-
break if formatting_tests.eof?
|
320
|
-
end
|
321
|
-
|
322
|
-
STDERR.puts <<~RUBY
|
323
|
-
require 'minitest/autorun'
|
324
|
-
|
325
|
-
require_relative '../lib/livetext'
|
326
|
-
|
327
|
-
# Just another testing class. Chill.
|
328
|
-
|
329
|
-
class TestingLivetext < MiniTest::Test
|
330
|
-
RUBY
|
331
|
-
|
332
|
-
TestLines.each.with_index do |item, num|
|
333
|
-
msg, src, exp, blank = *item
|
334
|
-
# generate tests...
|
335
|
-
name = "test_formatting_#{'%02d' % (num + 1)}"
|
336
|
-
method_source = <<~RUBY
|
337
|
-
def #{name} # #{msg}
|
338
|
-
msg, src, exp = <<~STUFF.split("\\n")
|
339
|
-
#{msg}
|
340
|
-
#{src}
|
341
|
-
#{exp}
|
342
|
-
STUFF
|
343
|
-
|
344
|
-
actual = LineParser.parse!(src)
|
345
|
-
# FIXME could simplify assert logic?
|
346
|
-
if exp[0] == "/"
|
347
|
-
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
348
|
-
assert_match(exp, actual, msg)
|
349
|
-
else
|
350
|
-
assert_equal(exp, actual, msg)
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
RUBY
|
355
|
-
STDERR.puts method_source
|
356
|
-
end
|
357
|
-
STDERR.puts "\nend"
|
358
|
-
end
|
359
|
-
=end
|