livetext 0.9.10 → 0.9.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cmdargs.rb +93 -0
  3. data/lib/errors.rb +15 -0
  4. data/lib/formatline.rb +59 -88
  5. data/lib/functions.rb +6 -2
  6. data/lib/helpers.rb +163 -0
  7. data/lib/html.rb +32 -0
  8. data/lib/livetext/importable.rb +2 -0
  9. data/lib/livetext.rb +30 -148
  10. data/lib/parser/file.rb +8 -0
  11. data/lib/parser/general.rb +38 -0
  12. data/lib/parser/import.rb +17 -0
  13. data/lib/parser/mixin.rb +53 -0
  14. data/lib/parser/set.rb +145 -0
  15. data/lib/parser/string.rb +70 -0
  16. data/lib/parser.rb +5 -0
  17. data/lib/processor.rb +23 -27
  18. data/lib/standard.rb +155 -348
  19. data/lib/userapi.rb +2 -5
  20. data/livetext.gemspec +1 -2
  21. data/plugin/bookish.rb +26 -22
  22. data/plugin/calibre.rb +1 -1
  23. data/plugin/livemagick.rb +10 -10
  24. data/plugin/markdown.rb +13 -11
  25. data/plugin/pyggish.rb +94 -84
  26. data/plugin/tutorial.rb +10 -5
  27. data/test/all.rb +3 -0
  28. data/test/snapshots/OMIT.txt +9 -0
  29. data/test/{data → snapshots}/basic_formatting/expected-error.txt +0 -0
  30. data/test/{data → snapshots}/basic_formatting/expected-output.txt +0 -0
  31. data/test/{data → snapshots}/basic_formatting/source.lt3 +0 -0
  32. data/test/{data → snapshots}/block_comment/expected-error.txt +0 -0
  33. data/test/{data → snapshots}/block_comment/expected-output.txt +0 -0
  34. data/test/{data → snapshots}/block_comment/source.lt3 +0 -0
  35. data/test/snapshots/clusion.txt +35 -0
  36. data/test/{data → snapshots}/comments_ignored_1/expected-error.txt +0 -0
  37. data/test/{data → snapshots}/comments_ignored_1/expected-output.txt +0 -0
  38. data/test/{data → snapshots}/comments_ignored_1/source.lt3 +0 -0
  39. data/test/{data → snapshots}/copy_is_raw/expected-error.txt +0 -0
  40. data/test/{data → snapshots}/copy_is_raw/expected-output.txt +0 -0
  41. data/test/{data → snapshots}/copy_is_raw/rawtext.inc +0 -0
  42. data/test/{data → snapshots}/copy_is_raw/source.lt3 +0 -0
  43. data/test/{data → snapshots}/crap +0 -0
  44. data/test/{data → snapshots}/def_method/expected-error.txt +0 -0
  45. data/test/{data → snapshots}/def_method/expected-output.txt +0 -0
  46. data/test/{data → snapshots}/def_method/source.lt3 +0 -0
  47. data/test/snapshots/error_inc_line_num/actual-error.txt +14 -0
  48. data/test/{data/error_inc_line_num/expected-output.txt → snapshots/error_inc_line_num/actual-output.txt} +0 -0
  49. data/test/snapshots/error_inc_line_num/expected-output.txt +13 -0
  50. data/test/{data → snapshots}/error_inc_line_num/file2.lt3 +0 -0
  51. data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
  52. data/test/snapshots/error_inc_line_num/out-sdiff.txt +14 -0
  53. data/test/{data → snapshots}/error_inc_line_num/source.lt3 +0 -0
  54. data/test/snapshots/error_invalid_name/actual-error.txt +10 -0
  55. data/test/{data/error_no_such_mixin/expected-output.txt → snapshots/error_invalid_name/actual-output.txt} +0 -0
  56. data/test/{data → snapshots}/error_invalid_name/expected-output.txt +0 -0
  57. data/test/snapshots/error_invalid_name/match-error.txt +1 -0
  58. data/test/snapshots/error_invalid_name/out-sdiff.txt +6 -0
  59. data/test/{data → snapshots}/error_invalid_name/source.lt3 +0 -0
  60. data/test/{data → snapshots}/error_line_num/expected-output.txt +0 -0
  61. data/test/snapshots/error_line_num/match-error.txt +1 -0
  62. data/test/{data → snapshots}/error_line_num/source.lt3 +0 -0
  63. data/test/{data → snapshots}/error_mismatched_end/expected-output.txt +0 -0
  64. data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
  65. data/test/{data → snapshots}/error_mismatched_end/source.lt3 +0 -0
  66. data/test/snapshots/error_missing_end/actual-error.txt +10 -0
  67. data/test/{data/example_alpha/expected-error.txt → snapshots/error_missing_end/actual-output.txt} +0 -0
  68. data/test/{data → snapshots}/error_missing_end/expected-output.txt +1 -0
  69. data/test/snapshots/error_missing_end/match-error.txt +1 -0
  70. data/test/snapshots/error_missing_end/out-sdiff.txt +6 -0
  71. data/test/{data → snapshots}/error_missing_end/source.lt3 +0 -0
  72. data/test/{data/example_alpha2/expected-error.txt → snapshots/error_name_not_permitted/expected-output.txt} +0 -0
  73. data/test/snapshots/error_name_not_permitted/match-error.txt +1 -0
  74. data/test/{data → snapshots}/error_name_not_permitted/source.lt3 +0 -0
  75. data/test/snapshots/error_no_such_copy/actual-error.txt +10 -0
  76. data/test/{data/functions/expected-error.txt → snapshots/error_no_such_copy/actual-output.txt} +0 -0
  77. data/test/{data → snapshots}/error_no_such_copy/expected-output.txt +0 -1
  78. data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
  79. data/test/snapshots/error_no_such_copy/out-sdiff.txt +5 -0
  80. data/test/{data → snapshots}/error_no_such_copy/source.lt3 +0 -0
  81. data/test/snapshots/error_no_such_inc/actual-error.txt +10 -0
  82. data/test/{data/hello_world/expected-error.txt → snapshots/error_no_such_inc/actual-output.txt} +0 -0
  83. data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -0
  84. data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
  85. data/test/snapshots/error_no_such_inc/out-sdiff.txt +6 -0
  86. data/test/{data → snapshots}/error_no_such_inc/source.lt3 +0 -0
  87. data/test/snapshots/error_no_such_mixin/actual-error.txt +37 -0
  88. data/test/{data/more_complex_vars/expected-error.txt → snapshots/error_no_such_mixin/actual-output.txt} +0 -0
  89. data/test/snapshots/error_no_such_mixin/expected-output.txt +5 -0
  90. data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
  91. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +6 -0
  92. data/test/{data → snapshots}/error_no_such_mixin/source.lt3 +0 -0
  93. data/test/{data/raw_lines → snapshots/example_alpha}/expected-error.txt +0 -0
  94. data/test/{data → snapshots}/example_alpha/expected-output.txt +0 -0
  95. data/test/{data → snapshots}/example_alpha/source.lt3 +0 -0
  96. data/test/{data/raw_text_block → snapshots/example_alpha2}/expected-error.txt +0 -0
  97. data/test/{data → snapshots}/example_alpha2/expected-output.txt +0 -0
  98. data/test/{data → snapshots}/example_alpha2/source.lt3 +0 -0
  99. data/test/{data → snapshots}/fixit +0 -0
  100. data/test/{data/simple_copy → snapshots/functions}/expected-error.txt +0 -0
  101. data/test/{data → snapshots}/functions/expected-output.txt +0 -0
  102. data/test/{data → snapshots}/functions/source.lt3 +0 -0
  103. data/test/{data/simple_include → snapshots/hello_world}/expected-error.txt +0 -0
  104. data/test/{data → snapshots}/hello_world/expected-output.txt +0 -0
  105. data/test/{data → snapshots}/hello_world/source.lt3 +0 -0
  106. data/test/{data/simple_mixin → snapshots/more_complex_vars}/expected-error.txt +0 -0
  107. data/test/{data → snapshots}/more_complex_vars/expected-output.txt +0 -0
  108. data/test/{data → snapshots}/more_complex_vars/source.lt3 +0 -0
  109. data/test/{data/simple_vars → snapshots/predef_vars}/expected-error.txt +0 -0
  110. data/test/snapshots/predef_vars/match-output.txt +6 -0
  111. data/test/snapshots/predef_vars/source.lt3 +6 -0
  112. data/test/{data/single_raw_line → snapshots/raw_lines}/expected-error.txt +0 -0
  113. data/test/{data → snapshots}/raw_lines/expected-output.txt +0 -0
  114. data/test/{data → snapshots}/raw_lines/source.lt3 +0 -0
  115. data/test/{data/table_with_heredocs → snapshots/raw_text_block}/expected-error.txt +0 -0
  116. data/test/{data → snapshots}/raw_text_block/expected-output.txt +0 -0
  117. data/test/{data → snapshots}/raw_text_block/rawtext.inc +0 -0
  118. data/test/{data → snapshots}/raw_text_block/source.lt3 +0 -0
  119. data/test/{data/subset.txt → snapshots/simple_copy/expected-error.txt} +0 -0
  120. data/test/{data → snapshots}/simple_copy/expected-output.txt +0 -0
  121. data/test/{data → snapshots}/simple_copy/simplefile.inc +0 -0
  122. data/test/{data → snapshots}/simple_copy/source.lt3 +0 -0
  123. data/test/snapshots/simple_import/actual-error.txt +8 -0
  124. data/test/snapshots/simple_import/actual-output.txt +3 -0
  125. data/test/snapshots/simple_import/err-sdiff.txt +9 -0
  126. data/test/snapshots/simple_import/expected-error.txt +0 -0
  127. data/test/snapshots/simple_import/expected-output.txt +7 -0
  128. data/test/snapshots/simple_import/out-sdiff.txt +9 -0
  129. data/test/snapshots/simple_import/simple_import.rb +5 -0
  130. data/test/snapshots/simple_import/source.lt3 +7 -0
  131. data/test/snapshots/simple_include/expected-error.txt +0 -0
  132. data/test/{data → snapshots}/simple_include/expected-output.txt +0 -0
  133. data/test/{data → snapshots}/simple_include/simplefile.inc +0 -0
  134. data/test/{data → snapshots}/simple_include/source.lt3 +0 -1
  135. data/test/snapshots/simple_mixin/expected-error.txt +0 -0
  136. data/test/{data → snapshots}/simple_mixin/expected-output.txt +0 -0
  137. data/test/{data → snapshots}/simple_mixin/simple_mixin.rb +0 -0
  138. data/test/{data → snapshots}/simple_mixin/source.lt3 +0 -0
  139. data/test/snapshots/simple_vars/expected-error.txt +0 -0
  140. data/test/{data → snapshots}/simple_vars/expected-output.txt +0 -0
  141. data/test/{data → snapshots}/simple_vars/source.lt3 +0 -0
  142. data/test/snapshots/single_raw_line/expected-error.txt +0 -0
  143. data/test/{data → snapshots}/single_raw_line/expected-output.txt +0 -0
  144. data/test/{data → snapshots}/single_raw_line/source.lt3 +0 -0
  145. data/test/snapshots/subset.txt +0 -0
  146. data/test/snapshots/table_with_heredocs/expected-error.txt +0 -0
  147. data/test/{data → snapshots}/table_with_heredocs/expected-output.txt +0 -0
  148. data/test/{data → snapshots}/table_with_heredocs/source.lt3 +0 -0
  149. data/test/snapshots.rb +169 -0
  150. data/test/testlines.rb +17 -7
  151. data/test/unit/all.rb +4 -0
  152. data/test/unit/formatline.rb +650 -0
  153. data/test/unit/html.rb +38 -0
  154. data/test/unit/parser/all.rb +3 -0
  155. data/test/unit/parser/general.rb +59 -0
  156. data/test/unit/parser/importable.rb +19 -0
  157. data/test/unit/parser/mixin.rb +19 -0
  158. data/test/unit/parser/set.rb +164 -0
  159. data/test/unit/parser/string.rb +130 -0
  160. data/test/unit/parser.rb +6 -0
  161. data/test/unit/standard.rb +23 -0
  162. data/test/unit/stringparser.rb +140 -0
  163. metadata +150 -97
  164. data/test/data/error_inc_line_num/expected-err-line1match.txt +0 -1
  165. data/test/data/error_invalid_name/expected-err-line1match.txt +0 -1
  166. data/test/data/error_line_num/expected-err-line1match.txt +0 -1
  167. data/test/data/error_mismatched_end/expected-err-line1match.txt +0 -1
  168. data/test/data/error_missing_end/expected-err-line1match.txt +0 -1
  169. data/test/data/error_name_not_permitted/expected-error.txt +0 -1
  170. data/test/data/error_name_not_permitted/expected-output.txt +0 -4
  171. data/test/data/error_no_such_copy/expected-err-line1match.txt +0 -1
  172. data/test/data/error_no_such_inc/expected-err-line1match.txt +0 -1
  173. data/test/data/error_no_such_mixin/expected-err-line1match.txt +0 -1
  174. data/test/data/lines.txt +0 -120
  175. data/test/extratests.txt +0 -20
  176. data/test/formatting.rb +0 -110
  177. data/test/test.rb +0 -140
@@ -0,0 +1,650 @@
1
+ require 'minitest/autorun'
2
+
3
+ require_relative '../../lib/livetext'
4
+
5
+ class TestingLivetext < MiniTest::Test
6
+
7
+ # Some (most) methods were generated via...
8
+
9
+ =begin
10
+ TestLines = []
11
+
12
+ items = []
13
+ formatting_tests = File.open("test/snapshots/formatting-tests.txt")
14
+ loop do
15
+ 4.times { items << formatting_tests.gets.chomp }
16
+ # Blank line terminates each "stanza"
17
+ raise "Oops? #{items.inspect}" unless items.last.empty?
18
+ TestLines << items
19
+ break if formatting_tests.eof?
20
+ end
21
+
22
+ STDERR.puts <<~RUBY
23
+ require 'minitest/autorun'
24
+
25
+ require_relative '../lib/livetext'
26
+
27
+ # Just another testing class. Chill.
28
+
29
+ class TestingLivetext < MiniTest::Test
30
+ RUBY
31
+
32
+ TestLines.each.with_index do |item, num|
33
+ msg, src, exp, blank = *item
34
+ # generate tests...
35
+ name = "test_formatting_#{'%02d' % (num + 1)}"
36
+ method_source = <<~RUBY
37
+ def #{name} # #{msg}
38
+ msg, src, exp = <<~STUFF.split("\\n")
39
+ #{msg}
40
+ #{src}
41
+ #{exp}
42
+ STUFF
43
+
44
+ actual = FormatLine.parse!(src)
45
+ # FIXME could simplify assert logic?
46
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
47
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
48
+ assert_match(exp, actual, msg)
49
+ else
50
+ assert_equal(exp, actual, msg)
51
+ end
52
+ end
53
+
54
+ RUBY
55
+ STDERR.puts method_source
56
+ end
57
+ STDERR.puts "\nend"
58
+ end
59
+ =end
60
+
61
+ def test_simple_string
62
+ parse = FormatLine.new("only testing")
63
+ tokens = parse.tokenize
64
+ assert_equal tokens, [[:str, "only testing"]]
65
+ expected = "only testing"
66
+ result = parse.evaluate
67
+ assert result == expected
68
+ end
69
+
70
+ def test_variable_interpolation
71
+ parse = FormatLine.new("File is $File and user is $User")
72
+ tokens = parse.tokenize
73
+ assert_equal tokens, [[:str, "File is "],
74
+ [:var, "File"],
75
+ [:str, " and user is "],
76
+ [:var, "User"]
77
+ ]
78
+ result = parse.evaluate
79
+ expected = "File is [File is undefined] and user is [User is undefined]"
80
+ assert result == expected
81
+ end
82
+
83
+ def test_func_expansion
84
+ parse = FormatLine.new("myfunc() results in $$myfunc apparently.")
85
+ tokens = parse.tokenize
86
+ assert_equal tokens, [[:str, "myfunc() results in "],
87
+ [:func, "myfunc"],
88
+ [:str, " apparently."]
89
+ ]
90
+ result = parse.evaluate
91
+ expected = "myfunc() results in [Error evaluating $$myfunc()] apparently."
92
+ assert result == expected
93
+ end
94
+
95
+ def test_func_with_colon
96
+ parse = FormatLine.new("Calling $$myfunc:foo here.")
97
+ tokens = parse.tokenize
98
+ assert_equal tokens, [[:str, "Calling "],
99
+ [:func, "myfunc"],
100
+ [:colon, "foo"],
101
+ [:str, " here."]
102
+ ]
103
+ result = parse.evaluate
104
+ expected = "Calling [Error evaluating $$myfunc(foo)] here."
105
+ assert result == expected
106
+ end
107
+
108
+ def test_func_with_brackets
109
+ parse = FormatLine.new("Calling $$myfunc2[foo bar] here.")
110
+ tokens = parse.tokenize
111
+ assert_kind_of Array, tokens
112
+ assert tokens.size == 4
113
+ assert_equal tokens, [[:str, "Calling "],
114
+ [:func, "myfunc2"],
115
+ [:brackets, "foo bar"],
116
+ [:str, " here."]
117
+ ]
118
+ result = parse.evaluate
119
+ expected = "Calling [Error evaluating $$myfunc2(foo bar)] here."
120
+ assert result == expected
121
+ end
122
+
123
+ def test_formatting_01 # Check output of $$date
124
+ msg, src, exp = <<~STUFF.split("\n")
125
+ Check output of $$date
126
+ Today is $$date, I guess
127
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
128
+ STUFF
129
+
130
+ actual = FormatLine.parse!(src)
131
+ # FIXME could simplify assert logic?
132
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
133
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
134
+ assert_match(exp, actual, msg)
135
+ else
136
+ assert_equal(exp, actual, msg)
137
+ end
138
+ end
139
+
140
+ def test_formatting_02 # Check output of $$date
141
+ msg, src, exp = <<~STUFF.split("\n")
142
+ Check output of $$date
143
+ Today is $$date, I guess
144
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
145
+ STUFF
146
+
147
+ actual = FormatLine.parse!(src)
148
+ # FIXME could simplify assert logic?
149
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
150
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
151
+ assert_match(exp, actual, msg)
152
+ else
153
+ assert_equal(exp, actual, msg)
154
+ end
155
+ end
156
+
157
+ def test_formatting_03 # Check output of $$date
158
+ msg, src, exp = <<~STUFF.split("\n")
159
+ Check output of $$date
160
+ Today is $$date, I guess
161
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
162
+ STUFF
163
+
164
+ actual = FormatLine.parse!(src)
165
+ # FIXME could simplify assert logic?
166
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
167
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
168
+ assert_match(exp, actual, msg)
169
+ else
170
+ assert_equal(exp, actual, msg)
171
+ end
172
+ end
173
+
174
+ def test_formatting_04 # Check output of $$date
175
+ msg, src, exp = <<~STUFF.split("\n")
176
+ Check output of $$date
177
+ Today is $$date, I guess
178
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
179
+ STUFF
180
+
181
+ actual = FormatLine.parse!(src)
182
+ # FIXME could simplify assert logic?
183
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
184
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
185
+ assert_match(exp, actual, msg)
186
+ else
187
+ assert_equal(exp, actual, msg)
188
+ end
189
+ end
190
+
191
+ def test_formatting_05 # Check output of $$date
192
+ msg, src, exp = <<~STUFF.split("\n")
193
+ Check output of $$date
194
+ Today is $$date, I guess
195
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
196
+ STUFF
197
+
198
+ actual = FormatLine.parse!(src)
199
+ # FIXME could simplify assert logic?
200
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
201
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
202
+ assert_match(exp, actual, msg)
203
+ else
204
+ assert_equal(exp, actual, msg)
205
+ end
206
+ end
207
+
208
+ def test_formatting_06 # Check output of $$date
209
+ msg, src, exp = <<~STUFF.split("\n")
210
+ Check output of $$date
211
+ Today is $$date, I guess
212
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
213
+ STUFF
214
+
215
+ actual = FormatLine.parse!(src)
216
+ # FIXME could simplify assert logic?
217
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
218
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
219
+ assert_match(exp, actual, msg)
220
+ else
221
+ assert_equal(exp, actual, msg)
222
+ end
223
+ end
224
+
225
+ def test_formatting_07 # Check output of $$date
226
+ msg, src, exp = <<~STUFF.split("\n")
227
+ Check output of $$date
228
+ Today is $$date, I guess
229
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
230
+ STUFF
231
+
232
+ actual = FormatLine.parse!(src)
233
+ # FIXME could simplify assert logic?
234
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
235
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
236
+ assert_match(exp, actual, msg)
237
+ else
238
+ assert_equal(exp, actual, msg)
239
+ end
240
+ end
241
+
242
+ def test_formatting_08 # Check output of $$date
243
+ msg, src, exp = <<~STUFF.split("\n")
244
+ Check output of $$date
245
+ Today is $$date, I guess
246
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
247
+ STUFF
248
+
249
+ actual = FormatLine.parse!(src)
250
+ # FIXME could simplify assert logic?
251
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
252
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
253
+ assert_match(exp, actual, msg)
254
+ else
255
+ assert_equal(exp, actual, msg)
256
+ end
257
+ end
258
+
259
+ def test_formatting_09 # Check output of $$date
260
+ msg, src, exp = <<~STUFF.split("\n")
261
+ Check output of $$date
262
+ Today is $$date, I guess
263
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
264
+ STUFF
265
+
266
+ actual = FormatLine.parse!(src)
267
+ # FIXME could simplify assert logic?
268
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
269
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
270
+ assert_match(exp, actual, msg)
271
+ else
272
+ assert_equal(exp, actual, msg)
273
+ end
274
+ end
275
+
276
+ def test_formatting_10 # Check output of $$date
277
+ msg, src, exp = <<~STUFF.split("\n")
278
+ Check output of $$date
279
+ Today is $$date, I guess
280
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
281
+ STUFF
282
+
283
+ actual = FormatLine.parse!(src)
284
+ # FIXME could simplify assert logic?
285
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
286
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
287
+ assert_match(exp, actual, msg)
288
+ else
289
+ assert_equal(exp, actual, msg)
290
+ end
291
+ end
292
+
293
+ def test_formatting_11 # Check output of $$date
294
+ msg, src, exp = <<~STUFF.split("\n")
295
+ Check output of $$date
296
+ Today is $$date, I guess
297
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
298
+ STUFF
299
+
300
+ actual = FormatLine.parse!(src)
301
+ # FIXME could simplify assert logic?
302
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
303
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
304
+ assert_match(exp, actual, msg)
305
+ else
306
+ assert_equal(exp, actual, msg)
307
+ end
308
+ end
309
+
310
+ def test_formatting_12 # Check output of $$date
311
+ msg, src, exp = <<~STUFF.split("\n")
312
+ Check output of $$date
313
+ Today is $$date, I guess
314
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
315
+ STUFF
316
+
317
+ actual = FormatLine.parse!(src)
318
+ # FIXME could simplify assert logic?
319
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
320
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
321
+ assert_match(exp, actual, msg)
322
+ else
323
+ assert_equal(exp, actual, msg)
324
+ end
325
+ end
326
+
327
+ def test_formatting_13 # Check output of $$date
328
+ msg, src, exp = <<~STUFF.split("\n")
329
+ Check output of $$date
330
+ Today is $$date, I guess
331
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
332
+ STUFF
333
+
334
+ actual = FormatLine.parse!(src)
335
+ # FIXME could simplify assert logic?
336
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
337
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
338
+ assert_match(exp, actual, msg)
339
+ else
340
+ assert_equal(exp, actual, msg)
341
+ end
342
+ end
343
+
344
+ def test_formatting_14 # Check output of $$date
345
+ msg, src, exp = <<~STUFF.split("\n")
346
+ Check output of $$date
347
+ Today is $$date, I guess
348
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
349
+ STUFF
350
+
351
+ actual = FormatLine.parse!(src)
352
+ # FIXME could simplify assert logic?
353
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
354
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
355
+ assert_match(exp, actual, msg)
356
+ else
357
+ assert_equal(exp, actual, msg)
358
+ end
359
+ end
360
+
361
+ def test_formatting_15 # Check output of $$date
362
+ msg, src, exp = <<~STUFF.split("\n")
363
+ Check output of $$date
364
+ Today is $$date, I guess
365
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
366
+ STUFF
367
+
368
+ actual = FormatLine.parse!(src)
369
+ # FIXME could simplify assert logic?
370
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
371
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
372
+ assert_match(exp, actual, msg)
373
+ else
374
+ assert_equal(exp, actual, msg)
375
+ end
376
+ end
377
+
378
+ def test_formatting_16 # 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
+
385
+ actual = FormatLine.parse!(src)
386
+ # FIXME could simplify assert logic?
387
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
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_17 # 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
+ # FIXME could simplify assert logic?
404
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
405
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
406
+ assert_match(exp, actual, msg)
407
+ else
408
+ assert_equal(exp, actual, msg)
409
+ end
410
+ end
411
+
412
+ def test_formatting_18 # Check output of $$date
413
+ msg, src, exp = <<~STUFF.split("\n")
414
+ Check output of $$date
415
+ Today is $$date, I guess
416
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
417
+ STUFF
418
+
419
+ actual = FormatLine.parse!(src)
420
+ # FIXME could simplify assert logic?
421
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
422
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
423
+ assert_match(exp, actual, msg)
424
+ else
425
+ assert_equal(exp, actual, msg)
426
+ end
427
+ end
428
+
429
+ def test_formatting_19 # Check output of $$date
430
+ msg, src, exp = <<~STUFF.split("\n")
431
+ Check output of $$date
432
+ Today is $$date, I guess
433
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
434
+ STUFF
435
+
436
+ actual = FormatLine.parse!(src)
437
+ # FIXME could simplify assert logic?
438
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
439
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
440
+ assert_match(exp, actual, msg)
441
+ else
442
+ assert_equal(exp, actual, msg)
443
+ end
444
+ end
445
+
446
+ def test_formatting_20 # Check output of $$date
447
+ msg, src, exp = <<~STUFF.split("\n")
448
+ Check output of $$date
449
+ Today is $$date, I guess
450
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
451
+ STUFF
452
+
453
+ actual = FormatLine.parse!(src)
454
+ # FIXME could simplify assert logic?
455
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
456
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
457
+ assert_match(exp, actual, msg)
458
+ else
459
+ assert_equal(exp, actual, msg)
460
+ end
461
+ end
462
+
463
+ def test_formatting_21 # Check output of $$date
464
+ msg, src, exp = <<~STUFF.split("\n")
465
+ Check output of $$date
466
+ Today is $$date, I guess
467
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
468
+ STUFF
469
+
470
+ actual = FormatLine.parse!(src)
471
+ # FIXME could simplify assert logic?
472
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
473
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
474
+ assert_match(exp, actual, msg)
475
+ else
476
+ assert_equal(exp, actual, msg)
477
+ end
478
+ end
479
+
480
+ def test_formatting_22 # Check output of $$date
481
+ msg, src, exp = <<~STUFF.split("\n")
482
+ Check output of $$date
483
+ Today is $$date, I guess
484
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
485
+ STUFF
486
+
487
+ actual = FormatLine.parse!(src)
488
+ # FIXME could simplify assert logic?
489
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
490
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
491
+ assert_match(exp, actual, msg)
492
+ else
493
+ assert_equal(exp, actual, msg)
494
+ end
495
+ end
496
+
497
+ def test_formatting_23 # 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
+
504
+ actual = FormatLine.parse!(src)
505
+ # FIXME could simplify assert logic?
506
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
507
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
508
+ assert_match(exp, actual, msg)
509
+ else
510
+ assert_equal(exp, actual, msg)
511
+ end
512
+ end
513
+
514
+ def test_formatting_24 # Check output of $$date
515
+ msg, src, exp = <<~STUFF.split("\n")
516
+ Check output of $$date
517
+ Today is $$date, I guess
518
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
519
+ STUFF
520
+
521
+ actual = FormatLine.parse!(src)
522
+ # FIXME could simplify assert logic?
523
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
524
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
525
+ assert_match(exp, actual, msg)
526
+ else
527
+ assert_equal(exp, actual, msg)
528
+ end
529
+ end
530
+
531
+ def test_formatting_25 # Check output of $$date
532
+ msg, src, exp = <<~STUFF.split("\n")
533
+ Check output of $$date
534
+ Today is $$date, I guess
535
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
536
+ STUFF
537
+
538
+ actual = FormatLine.parse!(src)
539
+ # FIXME could simplify assert logic?
540
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
541
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
542
+ assert_match(exp, actual, msg)
543
+ else
544
+ assert_equal(exp, actual, msg)
545
+ end
546
+ end
547
+
548
+ def test_formatting_26 # Check output of $$date
549
+ msg, src, exp = <<~STUFF.split("\n")
550
+ Check output of $$date
551
+ Today is $$date, I guess
552
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
553
+ STUFF
554
+
555
+ actual = FormatLine.parse!(src)
556
+ # FIXME could simplify assert logic?
557
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
558
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
559
+ assert_match(exp, actual, msg)
560
+ else
561
+ assert_equal(exp, actual, msg)
562
+ end
563
+ end
564
+
565
+ def test_formatting_27 # Check output of $$date
566
+ msg, src, exp = <<~STUFF.split("\n")
567
+ Check output of $$date
568
+ Today is $$date, I guess
569
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
570
+ STUFF
571
+
572
+ actual = FormatLine.parse!(src)
573
+ # FIXME could simplify assert logic?
574
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
575
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
576
+ assert_match(exp, actual, msg)
577
+ else
578
+ assert_equal(exp, actual, msg)
579
+ end
580
+ end
581
+
582
+ def test_formatting_28 # Check output of $$date
583
+ msg, src, exp = <<~STUFF.split("\n")
584
+ Check output of $$date
585
+ Today is $$date, I guess
586
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
587
+ STUFF
588
+
589
+ actual = FormatLine.parse!(src)
590
+ # FIXME could simplify assert logic?
591
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
592
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
593
+ assert_match(exp, actual, msg)
594
+ else
595
+ assert_equal(exp, actual, msg)
596
+ end
597
+ end
598
+
599
+ def test_formatting_29 # Check output of $$date
600
+ msg, src, exp = <<~STUFF.split("\n")
601
+ Check output of $$date
602
+ Today is $$date, I guess
603
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
604
+ STUFF
605
+
606
+ actual = FormatLine.parse!(src)
607
+ # FIXME could simplify assert logic?
608
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
609
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
610
+ assert_match(exp, actual, msg)
611
+ else
612
+ assert_equal(exp, actual, msg)
613
+ end
614
+ end
615
+
616
+ def test_formatting_30 # Check output of $$date
617
+ msg, src, exp = <<~STUFF.split("\n")
618
+ Check output of $$date
619
+ Today is $$date, I guess
620
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
621
+ STUFF
622
+
623
+ actual = FormatLine.parse!(src)
624
+ # FIXME could simplify assert logic?
625
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
626
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
627
+ assert_match(exp, actual, msg)
628
+ else
629
+ assert_equal(exp, actual, msg)
630
+ end
631
+ end
632
+
633
+ def test_formatting_31 # Check output of $$date
634
+ msg, src, exp = <<~STUFF.split("\n")
635
+ Check output of $$date
636
+ Today is $$date, I guess
637
+ /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/
638
+ STUFF
639
+
640
+ actual = FormatLine.parse!(src)
641
+ # FIXME could simplify assert logic?
642
+ if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
643
+ exp = Regexp.compile(exp[1..-2]) # skip slashes
644
+ assert_match(exp, actual, msg)
645
+ else
646
+ assert_equal(exp, actual, msg)
647
+ end
648
+ end
649
+
650
+ end
data/test/unit/html.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'minitest/autorun'
2
+
3
+ require '../../lib/livetext'
4
+
5
+ class TestingLivetext < MiniTest::Test
6
+ include Livetext::Standard
7
+ include Livetext::UserAPI
8
+
9
+ # Some of these methods being tested "really" belong elsewhere?
10
+ # Same is probably true of the methods that are testing them.
11
+
12
+ def test_wrapped
13
+ cdata = "nothing much"
14
+ assert_equal wrapped(cdata, :b), "<b>#{cdata}</b>"
15
+ assert_equal wrapped(cdata, :b, :i), "<b><i>#{cdata}</i></b>"
16
+
17
+ assert_equal wrapped(cdata, :table, :tr, :td),
18
+ "<table><tr><td>#{cdata}</td></tr></table>"
19
+ end
20
+
21
+ def test_wrapped_bang
22
+ cdata = "nothing much"
23
+ assert_equal wrapped!(cdata, :td, valign: :top),
24
+ "<td valign='top'>#{cdata}</td>"
25
+ assert_equal wrapped!(cdata, :img, src: "foo.jpg"),
26
+ "<img src='foo.jpg'>#{cdata}</img>"
27
+ assert_equal wrapped!(cdata, :a, style: 'text-decoration: none',
28
+ href: 'foo.com'),
29
+ "<a style='text-decoration: none' href='foo.com'>#{cdata}</a>"
30
+ end
31
+
32
+ def xtest_wrap
33
+ # bogus!
34
+ wrap(:ul) { 2.times {|i| _out i } }
35
+ puts @body
36
+ end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+
2
+ require_relative '../standard'
3
+ require_relative '../parser' # nested