livetext 0.9.21 → 0.9.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +8 -8
- data/bin/livetext +57 -40
- data/imports/bookish.rb +89 -90
- data/imports/calibre.rb +3 -3
- data/imports/livemagick.rb +17 -17
- data/imports/markdown.rb +10 -10
- data/imports/pyggish.rb +15 -47
- data/imports/tutorial.rb +18 -18
- data/lib/cmdargs.rb +10 -6
- data/lib/{errors.rb → livetext/errors.rb} +1 -1
- data/lib/{formatline.rb → livetext/formatline.rb} +69 -125
- data/lib/livetext/funcall.rb +84 -0
- data/lib/{functions.rb → livetext/functions.rb} +16 -3
- data/lib/livetext/global_helpers.rb +37 -0
- data/lib/livetext/handler/import.rb +44 -0
- data/lib/livetext/handler/mixin.rb +37 -0
- data/lib/livetext/handler.rb +3 -0
- data/lib/{helpers.rb → livetext/helpers.rb} +89 -67
- data/lib/{html.rb → livetext/html.rb} +3 -2
- data/lib/{parser → livetext/parser}/general.rb +0 -3
- data/lib/{parser → livetext/parser}/set.rb +1 -6
- data/lib/{parser → livetext/parser}/string.rb +2 -2
- data/lib/{parser.rb → livetext/parser.rb} +0 -1
- data/lib/livetext/parsing.rb +29 -0
- data/lib/livetext/paths.rb +13 -0
- data/lib/livetext/processor.rb +89 -0
- data/lib/livetext/reopen.rb +12 -0
- data/lib/livetext/skeleton.rb +17 -0
- data/lib/{standard.rb → livetext/standard.rb} +152 -122
- data/lib/livetext/userapi.rb +153 -0
- data/lib/livetext/version.rb +6 -0
- data/lib/livetext.rb +66 -27
- data/plugin/bookish.rb +85 -85
- data/plugin/calibre.rb +3 -3
- data/plugin/livemagick.rb +17 -17
- data/plugin/markdown.rb +10 -10
- data/plugin/pyggish.rb +131 -162
- data/plugin/tutorial.rb +15 -16
- data/test/all.rb +6 -0
- data/test/snapshots/def_method/expected-output.txt +2 -0
- data/test/snapshots/def_method/source.lt3 +4 -2
- data/test/snapshots/error_inc_line_num/OUT +17 -0
- data/test/snapshots/error_inc_line_num/README.txt +20 -0
- data/test/snapshots/error_inc_line_num/expected-output.txt +0 -6
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -1
- data/test/snapshots/error_line_num/match-error.txt +1 -1
- data/test/snapshots/error_missing_end/expected-output.txt +0 -1
- data/test/snapshots/error_name_not_permitted/expected-output.txt +4 -0
- data/test/snapshots/error_name_not_permitted/match-error.txt +1 -1
- data/test/snapshots/error_no_such_copy/duh +26 -0
- data/test/snapshots/error_no_such_copy/expected-output.txt +1 -0
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -1
- data/test/snapshots/error_no_such_copy/mystery.txt +36 -0
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -1
- data/test/snapshots/error_no_such_mixin/expected-output.txt +1 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -1
- data/test/snapshots/error_no_such_mixin/source.lt3 +1 -1
- data/test/snapshots/example_alpha/source.lt3 +2 -2
- data/test/snapshots/example_alpha2/expected-output.txt +0 -2
- data/test/snapshots/example_alpha2/source.lt3 +5 -4
- data/test/snapshots/{icanhaz → import}/expected-output.txt +2 -1
- data/test/snapshots/import/match-error.txt +1 -0
- data/test/snapshots/{icanhaz → import}/simple_import.rb +1 -1
- data/test/snapshots/{icanhaz → import}/source.lt3 +2 -2
- data/test/snapshots/{icanhaz2 → import2}/expected-error.txt +0 -0
- data/test/snapshots/{icanhaz2 → import2}/expected-output.txt +3 -1
- data/test/snapshots/{icanhaz2/simple_canhaz.rb → import2/simple_import.rb} +1 -1
- data/test/snapshots/import2/source.lt3 +8 -0
- data/test/snapshots/import_bookish/expected-error.txt +0 -0
- data/test/snapshots/import_bookish/expected-output.txt +10 -0
- data/test/snapshots/import_bookish/source.lt3 +7 -0
- data/test/snapshots/import_bookish/toc.tmp +0 -0
- data/test/snapshots/mixin_bookish/expected-error.txt +0 -0
- data/test/snapshots/mixin_bookish/expected-output.txt +10 -0
- data/test/snapshots/mixin_bookish/source.lt3 +7 -0
- data/test/snapshots/mixin_bookish/toc.tmp +0 -0
- data/test/snapshots/more_functions/expected-error.txt +0 -0
- data/test/snapshots/more_functions/expected-output.txt +37 -0
- data/test/snapshots/more_functions/source.lt3 +40 -0
- data/test/snapshots/raw_lines/expected-output.txt +0 -2
- data/test/snapshots/simple_import/expected-output.txt +2 -0
- data/test/snapshots/simple_import/simple_import.rb +1 -1
- data/test/snapshots/simple_import/source.lt3 +3 -1
- data/test/snapshots/simple_mixin/simple_mixin.rb +1 -1
- data/test/snapshots/single_raw_line/expected-output.txt +0 -2
- data/test/snapshots/subset.txt +14 -14
- data/test/snapshots.rb +30 -13
- data/test/unit/formatline.rb +253 -134
- data/test/unit/html.rb +2 -3
- data/test/unit/parser/general.rb +1 -2
- data/test/unit/parser/mixin.rb +1 -3
- data/test/unit/parser/set.rb +8 -12
- data/test/unit/parser/string.rb +6 -6
- data/test/unit/parser.rb +0 -1
- data/test/unit/standard.rb +0 -2
- metadata +47 -30
- data/imports/markdown_importable.rb +0 -45
- data/lib/handler/icanhaz.rb +0 -35
- data/lib/handler.rb +0 -1
- data/lib/livetext/importable.rb +0 -2
- data/lib/parser/file.rb +0 -8
- data/lib/parser/import.rb +0 -15
- data/lib/parser/mixin.rb +0 -38
- data/lib/processor.rb +0 -83
- data/lib/userapi.rb +0 -160
- data/test/snapshots/icanhaz/match-error.txt +0 -1
- data/test/snapshots/icanhaz2/source.lt3 +0 -6
- data/test/unit/parser/importable.rb +0 -19
data/test/unit/formatline.rb
CHANGED
@@ -4,94 +4,190 @@ require_relative '../../lib/livetext'
|
|
4
4
|
|
5
5
|
class TestingLivetext < MiniTest::Test
|
6
6
|
|
7
|
-
|
7
|
+
FormatLine = Livetext::FormatLine
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
# Some (most) methods were generated via the code
|
10
|
+
# seen in the comment at the bottom of this file...
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
break if formatting_tests.eof?
|
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
|
20
19
|
end
|
21
20
|
|
22
|
-
|
23
|
-
|
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
|
24
33
|
|
25
|
-
|
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
|
26
69
|
|
27
|
-
|
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
|
28
80
|
|
29
|
-
|
30
|
-
|
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
|
31
91
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
STUFF
|
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
|
43
102
|
|
44
|
-
|
45
|
-
|
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
|
103
|
+
# Next one is/will be a problem...
|
104
|
+
# I permit periods *inside* variable names
|
53
105
|
|
54
|
-
|
55
|
-
|
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}"
|
56
115
|
end
|
57
|
-
STDERR.puts "\nend"
|
58
|
-
end
|
59
|
-
=end
|
60
116
|
|
61
|
-
def
|
62
|
-
|
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"]]
|
63
121
|
tokens = parse.tokenize
|
64
|
-
assert_equal
|
65
|
-
expected = "only testing"
|
122
|
+
assert_equal tokens_expected, tokens
|
66
123
|
result = parse.evaluate
|
67
|
-
|
124
|
+
string_expected = "Square root of 225 is 15"
|
125
|
+
assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
68
126
|
end
|
69
127
|
|
70
|
-
def
|
71
|
-
|
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"]]
|
72
135
|
tokens = parse.tokenize
|
73
|
-
assert_equal
|
74
|
-
[:var, "File"],
|
75
|
-
[:str, " and user is "],
|
76
|
-
[:var, "User"]
|
77
|
-
]
|
136
|
+
assert_equal tokens_expected, tokens
|
78
137
|
result = parse.evaluate
|
79
|
-
|
80
|
-
|
138
|
+
string_expected = "Answer is 15 today"
|
139
|
+
assert_equal string_expected, result, "Found unexpected: #{result.inspect}"
|
81
140
|
end
|
82
141
|
|
83
|
-
|
84
|
-
|
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]
|
85
152
|
tokens = parse.tokenize
|
86
|
-
assert_equal
|
87
|
-
[:func, "myfunc"],
|
88
|
-
[:str, " apparently."]
|
89
|
-
]
|
153
|
+
assert_equal tokens_expected, tokens
|
90
154
|
result = parse.evaluate
|
91
|
-
|
92
|
-
|
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}"
|
93
187
|
end
|
94
188
|
|
189
|
+
# ...end of this group
|
190
|
+
|
95
191
|
def test_func_with_colon
|
96
192
|
parse = FormatLine.new("Calling $$myfunc:foo here.")
|
97
193
|
tokens = parse.tokenize
|
@@ -102,22 +198,22 @@ end
|
|
102
198
|
]
|
103
199
|
result = parse.evaluate
|
104
200
|
expected = "Calling [Error evaluating $$myfunc(foo)] here."
|
105
|
-
|
201
|
+
assert_equal expected, result
|
106
202
|
end
|
107
203
|
|
108
204
|
def test_func_with_brackets
|
109
205
|
parse = FormatLine.new("Calling $$myfunc2[foo bar] here.")
|
110
206
|
tokens = parse.tokenize
|
111
207
|
assert_kind_of Array, tokens
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
118
214
|
result = parse.evaluate
|
119
215
|
expected = "Calling [Error evaluating $$myfunc2(foo bar)] here."
|
120
|
-
|
216
|
+
assert_equal expected, result
|
121
217
|
end
|
122
218
|
|
123
219
|
def test_formatting_01 # Check output of $$date
|
@@ -128,8 +224,7 @@ end
|
|
128
224
|
STUFF
|
129
225
|
|
130
226
|
actual = FormatLine.parse!(src)
|
131
|
-
|
132
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
227
|
+
if exp[0] == "/"
|
133
228
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
134
229
|
assert_match(exp, actual, msg)
|
135
230
|
else
|
@@ -145,8 +240,7 @@ end
|
|
145
240
|
STUFF
|
146
241
|
|
147
242
|
actual = FormatLine.parse!(src)
|
148
|
-
|
149
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
243
|
+
if exp[0] == "/"
|
150
244
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
151
245
|
assert_match(exp, actual, msg)
|
152
246
|
else
|
@@ -162,8 +256,7 @@ end
|
|
162
256
|
STUFF
|
163
257
|
|
164
258
|
actual = FormatLine.parse!(src)
|
165
|
-
|
166
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
259
|
+
if exp[0] == "/"
|
167
260
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
168
261
|
assert_match(exp, actual, msg)
|
169
262
|
else
|
@@ -179,8 +272,7 @@ end
|
|
179
272
|
STUFF
|
180
273
|
|
181
274
|
actual = FormatLine.parse!(src)
|
182
|
-
|
183
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
275
|
+
if exp[0] == "/"
|
184
276
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
185
277
|
assert_match(exp, actual, msg)
|
186
278
|
else
|
@@ -196,8 +288,7 @@ end
|
|
196
288
|
STUFF
|
197
289
|
|
198
290
|
actual = FormatLine.parse!(src)
|
199
|
-
|
200
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
291
|
+
if exp[0] == "/"
|
201
292
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
202
293
|
assert_match(exp, actual, msg)
|
203
294
|
else
|
@@ -213,8 +304,7 @@ end
|
|
213
304
|
STUFF
|
214
305
|
|
215
306
|
actual = FormatLine.parse!(src)
|
216
|
-
|
217
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
307
|
+
if exp[0] == "/"
|
218
308
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
219
309
|
assert_match(exp, actual, msg)
|
220
310
|
else
|
@@ -230,8 +320,7 @@ end
|
|
230
320
|
STUFF
|
231
321
|
|
232
322
|
actual = FormatLine.parse!(src)
|
233
|
-
|
234
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
323
|
+
if exp[0] == "/"
|
235
324
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
236
325
|
assert_match(exp, actual, msg)
|
237
326
|
else
|
@@ -247,8 +336,7 @@ end
|
|
247
336
|
STUFF
|
248
337
|
|
249
338
|
actual = FormatLine.parse!(src)
|
250
|
-
|
251
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
339
|
+
if exp[0] == "/"
|
252
340
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
253
341
|
assert_match(exp, actual, msg)
|
254
342
|
else
|
@@ -264,8 +352,7 @@ end
|
|
264
352
|
STUFF
|
265
353
|
|
266
354
|
actual = FormatLine.parse!(src)
|
267
|
-
|
268
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
355
|
+
if exp[0] == "/"
|
269
356
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
270
357
|
assert_match(exp, actual, msg)
|
271
358
|
else
|
@@ -281,8 +368,7 @@ end
|
|
281
368
|
STUFF
|
282
369
|
|
283
370
|
actual = FormatLine.parse!(src)
|
284
|
-
|
285
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
371
|
+
if exp[0] == "/"
|
286
372
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
287
373
|
assert_match(exp, actual, msg)
|
288
374
|
else
|
@@ -298,8 +384,7 @@ end
|
|
298
384
|
STUFF
|
299
385
|
|
300
386
|
actual = FormatLine.parse!(src)
|
301
|
-
|
302
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
387
|
+
if exp[0] == "/"
|
303
388
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
304
389
|
assert_match(exp, actual, msg)
|
305
390
|
else
|
@@ -315,8 +400,7 @@ end
|
|
315
400
|
STUFF
|
316
401
|
|
317
402
|
actual = FormatLine.parse!(src)
|
318
|
-
|
319
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
403
|
+
if exp[0] == "/"
|
320
404
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
321
405
|
assert_match(exp, actual, msg)
|
322
406
|
else
|
@@ -332,8 +416,7 @@ end
|
|
332
416
|
STUFF
|
333
417
|
|
334
418
|
actual = FormatLine.parse!(src)
|
335
|
-
|
336
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
419
|
+
if exp[0] == "/"
|
337
420
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
338
421
|
assert_match(exp, actual, msg)
|
339
422
|
else
|
@@ -349,8 +432,7 @@ end
|
|
349
432
|
STUFF
|
350
433
|
|
351
434
|
actual = FormatLine.parse!(src)
|
352
|
-
|
353
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
435
|
+
if exp[0] == "/"
|
354
436
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
355
437
|
assert_match(exp, actual, msg)
|
356
438
|
else
|
@@ -366,8 +448,7 @@ end
|
|
366
448
|
STUFF
|
367
449
|
|
368
450
|
actual = FormatLine.parse!(src)
|
369
|
-
|
370
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
451
|
+
if exp[0] == "/"
|
371
452
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
372
453
|
assert_match(exp, actual, msg)
|
373
454
|
else
|
@@ -383,8 +464,7 @@ end
|
|
383
464
|
STUFF
|
384
465
|
|
385
466
|
actual = FormatLine.parse!(src)
|
386
|
-
|
387
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
467
|
+
if exp[0] == "/"
|
388
468
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
389
469
|
assert_match(exp, actual, msg)
|
390
470
|
else
|
@@ -400,8 +480,7 @@ end
|
|
400
480
|
STUFF
|
401
481
|
|
402
482
|
actual = FormatLine.parse!(src)
|
403
|
-
|
404
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
483
|
+
if exp[0] == "/"
|
405
484
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
406
485
|
assert_match(exp, actual, msg)
|
407
486
|
else
|
@@ -417,8 +496,7 @@ end
|
|
417
496
|
STUFF
|
418
497
|
|
419
498
|
actual = FormatLine.parse!(src)
|
420
|
-
|
421
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
499
|
+
if exp[0] == "/"
|
422
500
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
423
501
|
assert_match(exp, actual, msg)
|
424
502
|
else
|
@@ -434,8 +512,7 @@ end
|
|
434
512
|
STUFF
|
435
513
|
|
436
514
|
actual = FormatLine.parse!(src)
|
437
|
-
|
438
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
515
|
+
if exp[0] == "/"
|
439
516
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
440
517
|
assert_match(exp, actual, msg)
|
441
518
|
else
|
@@ -451,8 +528,7 @@ end
|
|
451
528
|
STUFF
|
452
529
|
|
453
530
|
actual = FormatLine.parse!(src)
|
454
|
-
|
455
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
531
|
+
if exp[0] == "/"
|
456
532
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
457
533
|
assert_match(exp, actual, msg)
|
458
534
|
else
|
@@ -468,8 +544,7 @@ end
|
|
468
544
|
STUFF
|
469
545
|
|
470
546
|
actual = FormatLine.parse!(src)
|
471
|
-
|
472
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
547
|
+
if exp[0] == "/"
|
473
548
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
474
549
|
assert_match(exp, actual, msg)
|
475
550
|
else
|
@@ -485,8 +560,7 @@ end
|
|
485
560
|
STUFF
|
486
561
|
|
487
562
|
actual = FormatLine.parse!(src)
|
488
|
-
|
489
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
563
|
+
if exp[0] == "/"
|
490
564
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
491
565
|
assert_match(exp, actual, msg)
|
492
566
|
else
|
@@ -502,8 +576,7 @@ end
|
|
502
576
|
STUFF
|
503
577
|
|
504
578
|
actual = FormatLine.parse!(src)
|
505
|
-
|
506
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
579
|
+
if exp[0] == "/"
|
507
580
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
508
581
|
assert_match(exp, actual, msg)
|
509
582
|
else
|
@@ -519,8 +592,7 @@ end
|
|
519
592
|
STUFF
|
520
593
|
|
521
594
|
actual = FormatLine.parse!(src)
|
522
|
-
|
523
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
595
|
+
if exp[0] == "/"
|
524
596
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
525
597
|
assert_match(exp, actual, msg)
|
526
598
|
else
|
@@ -536,8 +608,7 @@ end
|
|
536
608
|
STUFF
|
537
609
|
|
538
610
|
actual = FormatLine.parse!(src)
|
539
|
-
|
540
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
611
|
+
if exp[0] == "/"
|
541
612
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
542
613
|
assert_match(exp, actual, msg)
|
543
614
|
else
|
@@ -553,8 +624,7 @@ end
|
|
553
624
|
STUFF
|
554
625
|
|
555
626
|
actual = FormatLine.parse!(src)
|
556
|
-
|
557
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
627
|
+
if exp[0] == "/"
|
558
628
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
559
629
|
assert_match(exp, actual, msg)
|
560
630
|
else
|
@@ -570,8 +640,7 @@ end
|
|
570
640
|
STUFF
|
571
641
|
|
572
642
|
actual = FormatLine.parse!(src)
|
573
|
-
|
574
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
643
|
+
if exp[0] == "/"
|
575
644
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
576
645
|
assert_match(exp, actual, msg)
|
577
646
|
else
|
@@ -587,8 +656,7 @@ end
|
|
587
656
|
STUFF
|
588
657
|
|
589
658
|
actual = FormatLine.parse!(src)
|
590
|
-
|
591
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
659
|
+
if exp[0] == "/"
|
592
660
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
593
661
|
assert_match(exp, actual, msg)
|
594
662
|
else
|
@@ -604,8 +672,7 @@ end
|
|
604
672
|
STUFF
|
605
673
|
|
606
674
|
actual = FormatLine.parse!(src)
|
607
|
-
|
608
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
675
|
+
if exp[0] == "/"
|
609
676
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
610
677
|
assert_match(exp, actual, msg)
|
611
678
|
else
|
@@ -621,8 +688,7 @@ end
|
|
621
688
|
STUFF
|
622
689
|
|
623
690
|
actual = FormatLine.parse!(src)
|
624
|
-
|
625
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
691
|
+
if exp[0] == "/"
|
626
692
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
627
693
|
assert_match(exp, actual, msg)
|
628
694
|
else
|
@@ -638,8 +704,7 @@ end
|
|
638
704
|
STUFF
|
639
705
|
|
640
706
|
actual = FormatLine.parse!(src)
|
641
|
-
|
642
|
-
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
707
|
+
if exp[0] == "/"
|
643
708
|
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
644
709
|
assert_match(exp, actual, msg)
|
645
710
|
else
|
@@ -648,3 +713,57 @@ end
|
|
648
713
|
end
|
649
714
|
|
650
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
|
data/test/unit/html.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'livetext'
|
4
4
|
|
5
5
|
class TestingLivetext < MiniTest::Test
|
6
6
|
include Livetext::Standard
|
7
|
-
include Livetext::UserAPI
|
8
7
|
|
9
8
|
# Some of these methods being tested "really" belong elsewhere?
|
10
9
|
# Same is probably true of the methods that are testing them.
|
@@ -32,7 +31,7 @@ class TestingLivetext < MiniTest::Test
|
|
32
31
|
def xtest_wrap
|
33
32
|
# bogus!
|
34
33
|
wrap(:ul) { 2.times {|i| _out i } }
|
35
|
-
puts @body
|
34
|
+
dump # puts @body
|
36
35
|
end
|
37
36
|
|
38
37
|
end
|
data/test/unit/parser/general.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
require 'minitest/autorun'
|
3
3
|
|
4
|
-
require_relative '
|
4
|
+
require_relative '../parser' # nested
|
5
5
|
|
6
6
|
ParseGeneral = ::Livetext::ParseGeneral
|
7
7
|
|
@@ -53,7 +53,6 @@ class TestParseGeneral < MiniTest::Test
|
|
53
53
|
vars = ["alpha 'simple string'", 'beta "another string"']
|
54
54
|
expect = [["this.that.alpha", "'simple string'"], ["this.that.beta", '"another string"']]
|
55
55
|
assert_equal ParseGeneral.parse_vars(vars, prefix: "this.that"), expect
|
56
|
-
|
57
56
|
end
|
58
57
|
|
59
58
|
end
|