livetext 0.9.11 → 0.9.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/errors.rb +13 -0
- data/lib/formatline.rb +3 -5
- data/lib/functions.rb +6 -2
- data/lib/helpers.rb +21 -0
- data/lib/html.rb +32 -0
- data/lib/livetext/importable.rb +2 -0
- data/lib/livetext.rb +44 -42
- data/lib/parser/general.rb +38 -0
- data/lib/parser/import.rb +17 -0
- data/lib/parser/mixin.rb +46 -0
- data/lib/parser/set.rb +136 -0
- data/lib/parser/string.rb +55 -0
- data/lib/parser.rb +5 -0
- data/lib/processor.rb +22 -16
- data/lib/standard.rb +144 -292
- data/lib/userapi.rb +2 -1
- data/livetext.gemspec +1 -2
- data/test/all.rb +3 -0
- data/test/formatting.rb +2 -9
- data/test/{data → snapshots}/basic_formatting/expected-error.txt +0 -0
- data/test/{data → snapshots}/basic_formatting/expected-output.txt +0 -0
- data/test/{data → snapshots}/basic_formatting/source.lt3 +0 -0
- data/test/{data → snapshots}/block_comment/expected-error.txt +0 -0
- data/test/{data → snapshots}/block_comment/expected-output.txt +0 -0
- data/test/{data → snapshots}/block_comment/source.lt3 +0 -0
- data/test/{data → snapshots}/comments_ignored_1/expected-error.txt +0 -0
- data/test/{data → snapshots}/comments_ignored_1/expected-output.txt +0 -0
- data/test/{data → snapshots}/comments_ignored_1/source.lt3 +0 -0
- data/test/{data → snapshots}/copy_is_raw/expected-error.txt +0 -0
- data/test/{data → snapshots}/copy_is_raw/expected-output.txt +0 -0
- data/test/{data → snapshots}/copy_is_raw/rawtext.inc +0 -0
- data/test/{data → snapshots}/copy_is_raw/source.lt3 +0 -0
- data/test/{data → snapshots}/crap +0 -0
- data/test/{data → snapshots}/def_method/expected-error.txt +0 -0
- data/test/{data → snapshots}/def_method/expected-output.txt +0 -0
- data/test/{data → snapshots}/def_method/source.lt3 +0 -0
- data/test/{data/error_inc_line_num/expected-err-line1match.txt → snapshots/error_inc_line_num/actual-error.txt} +0 -0
- data/test/{data/error_inc_line_num/expected-output.txt → snapshots/error_inc_line_num/actual-output.txt} +0 -0
- data/test/{data/error_line_num → snapshots/error_inc_line_num}/expected-err-line1match.txt +0 -0
- data/test/snapshots/error_inc_line_num/expected-output.txt +13 -0
- data/test/{data → snapshots}/error_inc_line_num/file2.lt3 +0 -0
- data/test/snapshots/error_inc_line_num/out-sdiff.txt +14 -0
- data/test/{data → snapshots}/error_inc_line_num/source.lt3 +0 -0
- data/test/snapshots/error_invalid_name/actual-error.txt +10 -0
- data/test/{data/error_no_such_mixin/expected-output.txt → snapshots/error_invalid_name/actual-output.txt} +0 -0
- data/test/{data → snapshots}/error_invalid_name/expected-err-line1match.txt +0 -0
- data/test/{data → snapshots}/error_invalid_name/expected-output.txt +0 -0
- data/test/snapshots/error_invalid_name/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/error_invalid_name/source.lt3 +0 -0
- data/test/snapshots/error_line_num/actual-error.txt +1 -0
- data/test/snapshots/error_line_num/actual-output.txt +5 -0
- data/test/snapshots/error_line_num/expected-err-line1match.txt +1 -0
- data/test/{data → snapshots}/error_line_num/expected-output.txt +0 -0
- data/test/snapshots/error_line_num/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/error_line_num/source.lt3 +0 -0
- data/test/snapshots/error_mismatched_end/actual-error.txt +1 -0
- data/test/{data/error_mismatched_end/expected-output.txt → snapshots/error_mismatched_end/actual-output.txt} +0 -0
- data/test/{data → snapshots}/error_mismatched_end/expected-err-line1match.txt +0 -0
- data/test/snapshots/error_mismatched_end/expected-output.txt +8 -0
- data/test/snapshots/error_mismatched_end/out-sdiff.txt +9 -0
- data/test/{data → snapshots}/error_mismatched_end/source.lt3 +0 -0
- data/test/{data/error_missing_end/expected-err-line1match.txt → snapshots/error_missing_end/actual-error.txt} +0 -0
- data/test/{data/error_missing_end/expected-output.txt → snapshots/error_missing_end/actual-output.txt} +0 -0
- data/test/snapshots/error_missing_end/expected-err-line1match.txt +1 -0
- data/test/snapshots/error_missing_end/expected-output.txt +5 -0
- data/test/snapshots/error_missing_end/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/error_missing_end/source.lt3 +0 -0
- data/test/{data/error_name_not_permitted/expected-output.txt → snapshots/error_name_not_permitted/OLD-exp-out} +0 -0
- data/test/{data/example_alpha/expected-error.txt → snapshots/error_name_not_permitted/expected-output.txt} +0 -0
- data/test/snapshots/error_name_not_permitted/match-error.txt +1 -0
- data/test/{data → snapshots}/error_name_not_permitted/source.lt3 +0 -0
- data/test/snapshots/error_no_such_copy/actual-error.txt +10 -0
- data/test/{data/example_alpha2/expected-error.txt → snapshots/error_no_such_copy/actual-output.txt} +0 -0
- data/test/snapshots/error_no_such_copy/expected-err-line1match.txt +1 -0
- data/test/{data → snapshots}/error_no_such_copy/expected-output.txt +0 -5
- data/test/snapshots/error_no_such_copy/out-sdiff.txt +5 -0
- data/test/{data → snapshots}/error_no_such_copy/source.lt3 +0 -0
- data/test/snapshots/error_no_such_inc/actual-error.txt +10 -0
- data/test/{data/functions/expected-error.txt → snapshots/error_no_such_inc/actual-output.txt} +0 -0
- data/test/snapshots/error_no_such_inc/expected-err-line1match.txt +1 -0
- data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -4
- data/test/snapshots/error_no_such_inc/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/error_no_such_inc/source.lt3 +0 -0
- data/test/snapshots/error_no_such_mixin/actual-error.txt +1 -0
- data/test/snapshots/error_no_such_mixin/actual-output.txt +11 -0
- data/test/{data → snapshots}/error_no_such_mixin/expected-err-line1match.txt +0 -0
- data/test/snapshots/error_no_such_mixin/expected-output.txt +5 -0
- data/test/snapshots/error_no_such_mixin/out-sdiff.txt +12 -0
- data/test/{data → snapshots}/error_no_such_mixin/source.lt3 +0 -0
- data/test/{data/hello_world → snapshots/example_alpha}/expected-error.txt +0 -0
- data/test/{data → snapshots}/example_alpha/expected-output.txt +0 -0
- data/test/{data → snapshots}/example_alpha/source.lt3 +0 -0
- data/test/{data/more_complex_vars → snapshots/example_alpha2}/expected-error.txt +0 -0
- data/test/{data → snapshots}/example_alpha2/expected-output.txt +0 -0
- data/test/{data → snapshots}/example_alpha2/source.lt3 +0 -0
- data/test/{data → snapshots}/fixit +0 -0
- data/test/{data/predef_vars → snapshots/functions}/expected-error.txt +0 -0
- data/test/{data → snapshots}/functions/expected-output.txt +0 -0
- data/test/{data → snapshots}/functions/source.lt3 +0 -0
- data/test/{data/raw_lines → snapshots/hello_world}/expected-error.txt +0 -0
- data/test/{data → snapshots}/hello_world/expected-output.txt +0 -0
- data/test/{data → snapshots}/hello_world/source.lt3 +0 -0
- data/test/{data → snapshots}/lines.txt +0 -0
- data/test/{data/raw_text_block → snapshots/more_complex_vars}/expected-error.txt +0 -0
- data/test/{data → snapshots}/more_complex_vars/expected-output.txt +0 -0
- data/test/{data → snapshots}/more_complex_vars/source.lt3 +0 -0
- data/test/{data/simple_copy/expected-error.txt → snapshots/predef_vars/actual-error.txt} +0 -0
- data/test/snapshots/predef_vars/actual-output.txt +6 -0
- data/test/{data/simple_include → snapshots/predef_vars}/expected-error.txt +0 -0
- data/test/{data → snapshots}/predef_vars/expected-output.txt +1 -1
- data/test/snapshots/predef_vars/out-sdiff.txt +7 -0
- data/test/{data → snapshots}/predef_vars/source.lt3 +0 -0
- data/test/{data/simple_mixin → snapshots/raw_lines}/expected-error.txt +0 -0
- data/test/{data → snapshots}/raw_lines/expected-output.txt +0 -0
- data/test/{data → snapshots}/raw_lines/source.lt3 +0 -0
- data/test/{data/simple_vars → snapshots/raw_text_block}/expected-error.txt +0 -0
- data/test/{data → snapshots}/raw_text_block/expected-output.txt +0 -0
- data/test/{data → snapshots}/raw_text_block/rawtext.inc +0 -0
- data/test/{data → snapshots}/raw_text_block/source.lt3 +0 -0
- data/test/{data/single_raw_line → snapshots/simple_copy}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_copy/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_copy/simplefile.inc +0 -0
- data/test/{data → snapshots}/simple_copy/source.lt3 +0 -0
- data/test/{data/table_with_heredocs → snapshots/simple_include}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_include/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_include/simplefile.inc +0 -0
- data/test/{data → snapshots}/simple_include/source.lt3 +0 -0
- data/test/snapshots/simple_mixin/actual-error.txt +2 -0
- data/test/snapshots/simple_mixin/actual-output.txt +4 -0
- data/test/{data/subset.txt → snapshots/simple_mixin/expected-error.txt} +0 -0
- data/test/{data → snapshots}/simple_mixin/expected-output.txt +0 -0
- data/test/snapshots/simple_mixin/out-sdiff.txt +6 -0
- data/test/{data → snapshots}/simple_mixin/simple_mixin.rb +0 -0
- data/test/{data → snapshots}/simple_mixin/source.lt3 +0 -0
- data/test/snapshots/simple_vars/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_vars/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_vars/source.lt3 +0 -0
- data/test/snapshots/single_raw_line/expected-error.txt +0 -0
- data/test/{data → snapshots}/single_raw_line/expected-output.txt +0 -0
- data/test/{data → snapshots}/single_raw_line/source.lt3 +0 -0
- data/test/snapshots/subset.txt +0 -0
- data/test/snapshots/table_with_heredocs/expected-error.txt +0 -0
- data/test/{data → snapshots}/table_with_heredocs/expected-output.txt +0 -0
- data/test/{data → snapshots}/table_with_heredocs/source.lt3 +0 -0
- data/test/snapshots.rb +219 -0
- data/test/testlines.rb +2 -2
- data/test/unit/all.rb +3 -0
- data/test/unit/html.rb +38 -0
- data/test/unit/parse_misc.rb +60 -0
- data/test/unit/parse_set.rb +157 -0
- data/test/unit/parser/all.rb +3 -0
- data/test/unit/parser/general.rb +59 -0
- data/test/unit/parser/importable.rb +19 -0
- data/test/unit/parser/mixin.rb +19 -0
- data/test/unit/parser/set.rb +157 -0
- data/test/unit/parser/string.rb +130 -0
- data/test/unit/parser.rb +4 -0
- data/test/unit/standard.rb +23 -0
- data/test/unit/stringparser.rb +140 -0
- metadata +152 -99
- data/test/data/error_inc_line_num/FOO +0 -21
- data/test/data/error_missing_end/ERR +0 -32
- data/test/data/error_name_not_permitted/expected-error.txt +0 -1
- data/test/data/error_no_such_copy/expected-err-line1match.txt +0 -1
- data/test/data/error_no_such_inc/expected-err-line1match.txt +0 -1
- data/test/test.rb +0 -140
data/test/snapshots.rb
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative '../lib/livetext'
|
4
|
+
|
5
|
+
=begin
|
6
|
+
Snapshots...
|
7
|
+
|
8
|
+
NOTE that the external_files method has been replaced by the Snapshot class.
|
9
|
+
|
10
|
+
You can add any ordinary test method above. But so far, most of these tests simply
|
11
|
+
call external_files.
|
12
|
+
|
13
|
+
The external_files method works this way:
|
14
|
+
- If the test (caller) method is test_my_silly_feature, then we will
|
15
|
+
look for a directory called snapshots/my_silly_feature
|
16
|
+
- In here, there must be a source.lt3, expected-output.txt, and expected-error.txt
|
17
|
+
- Technically, any of these can be empty
|
18
|
+
- We run livetext on the source and compare actual vs expected (stdout, stderr)
|
19
|
+
- The "real" output gets checked first
|
20
|
+
- Of course, both must compare correctly for the test to pass
|
21
|
+
- See also: match*
|
22
|
+
=end
|
23
|
+
|
24
|
+
|
25
|
+
# Just a testing class. Chill.
|
26
|
+
|
27
|
+
class TestingLivetext < MiniTest::Test
|
28
|
+
|
29
|
+
class Snapshot
|
30
|
+
SOURCE = "source.lt3"
|
31
|
+
# Will now keep "actual" output in same dir?
|
32
|
+
ACTUAL_OUT, ACTUAL_ERR = "actual-output.txt", "actual-error.txt"
|
33
|
+
EXP_OUT, EXP_ERR = "expected-output.txt", "expected-error.txt"
|
34
|
+
MATCH_OUT, MATCH_ERR = "match-output.txt", "match-error.txt"
|
35
|
+
|
36
|
+
def initialize(base, assertion = nil)
|
37
|
+
@assertion = assertion
|
38
|
+
@base = base
|
39
|
+
@errors = false
|
40
|
+
Dir.chdir(base) do
|
41
|
+
@literal_out = File.exist?(EXP_OUT)
|
42
|
+
@literal_err = File.exist?(EXP_ERR)
|
43
|
+
@match_out = File.exist?(MATCH_OUT)
|
44
|
+
@match_err = File.exist?(MATCH_ERR)
|
45
|
+
end
|
46
|
+
bad_files = (@literal_out && @match_out) || (@literal_err && @match_err)
|
47
|
+
raise "Inconsistent structure for #@base" if bad_files
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_matches(actual, control)
|
51
|
+
controls = File.readlines(control).map(&:chomp)
|
52
|
+
lines = File.readlines(actual).map(&:chomp)
|
53
|
+
lines.unshift("DUMMY LINE") # 1-based index! (for when I'm editing)
|
54
|
+
controls.each do |line|
|
55
|
+
line_num, item = line.split(" ", 2)
|
56
|
+
item = Regexp.new(item[1..-2]) if item[0] == "/" # Hmm, string can't start with /...
|
57
|
+
line_num = line_num.to_i
|
58
|
+
info = "Expected line #{line_num} of #{actual.inspect} to match #{item.inspect} (was: #{lines[line_num].inspect})"
|
59
|
+
good = item === lines[line_num]
|
60
|
+
@errors = true unless good
|
61
|
+
# assert item === lines[line_num], info # string or regex
|
62
|
+
@assertion.call item === lines[line_num], info # string or regex
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def sdiff(f1, f2, out)
|
67
|
+
File.open(out, "w") {|file| file.puts "#{'%-60s'% 'EXPECTED'}| #{'%-60s'% 'ACTUAL'}" }
|
68
|
+
system("/usr/bin/sdiff -t -w 121 #{f1} #{f2} >>#{out}")
|
69
|
+
end
|
70
|
+
|
71
|
+
def check_stdout
|
72
|
+
if @literal_out
|
73
|
+
actual, expected = File.read(ACTUAL_OUT), File.read(EXP_OUT)
|
74
|
+
same = actual == expected
|
75
|
+
@errors = true if not same
|
76
|
+
file = "out-sdiff.txt"
|
77
|
+
sdiff(ACTUAL_OUT, EXP_OUT, file)
|
78
|
+
# assert same, "Discrepancy in STDOUT - see #@base/#{file}"
|
79
|
+
@assertion.call same, "Discrepancy in STDOUT - see #@base/#{file}"
|
80
|
+
else
|
81
|
+
check_matches(ACTUAL_OUT, MATCH_OUT)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def check_stderr
|
86
|
+
if @literal_err
|
87
|
+
actual, expected = File.read(ACTUAL_ERR), File.read(EXP_ERR)
|
88
|
+
same = actual == expected
|
89
|
+
@errors = true if not same
|
90
|
+
file = "err-sdiff.txt"
|
91
|
+
sdiff(ACTUAL_ERR, EXP_ERR, file)
|
92
|
+
# assert same, "Discrepancy in STDERR - see #@base/#{file}"
|
93
|
+
@assertion.call same, "Discrepancy in STDERR - see #@base/#{file}"
|
94
|
+
else
|
95
|
+
check_matches(ACTUAL_ERR, MATCH_ERR)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def cleanup
|
100
|
+
return if @errors
|
101
|
+
system("rm -f #{ACTUAL_OUT} #{ACTUAL_ERR} *sdiff.txt")
|
102
|
+
end
|
103
|
+
|
104
|
+
def run
|
105
|
+
@errors = false # oops, need to reset
|
106
|
+
Dir.chdir(@base) do
|
107
|
+
cmd = "../../../bin/livetext #{SOURCE} >#{ACTUAL_OUT} 2>#{ACTUAL_ERR}"
|
108
|
+
system(cmd)
|
109
|
+
check_stdout
|
110
|
+
check_stderr
|
111
|
+
cleanup
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
TTY = File.open("/dev/tty","w")
|
117
|
+
|
118
|
+
cmdline = ARGV.first == "cmdline"
|
119
|
+
if cmdline
|
120
|
+
dir = "../"
|
121
|
+
Dir.chdir `livetext --path`.chomp.chomp
|
122
|
+
else
|
123
|
+
dir = ""
|
124
|
+
end
|
125
|
+
|
126
|
+
Data = "#{dir}test/snapshots"
|
127
|
+
TestLines = []
|
128
|
+
Dir.chdir(Data)
|
129
|
+
|
130
|
+
items = []
|
131
|
+
short_tests = File.open("lines.txt")
|
132
|
+
loop do
|
133
|
+
4.times { items << short_tests.gets.chomp }
|
134
|
+
# Blank line terminates each "stanza"
|
135
|
+
raise "Oops? #{items.inspect}" unless items.last.empty?
|
136
|
+
TestLines << items
|
137
|
+
break if short_tests.eof?
|
138
|
+
end
|
139
|
+
|
140
|
+
if File.size("subset.txt") == 0
|
141
|
+
puts "Defining via TestLines"
|
142
|
+
TestLines.each.with_index do |item, num|
|
143
|
+
msg, src, exp, blank = *item
|
144
|
+
define_method("test_formatting_#{num}") do
|
145
|
+
actual = FormatLine.parse!(src)
|
146
|
+
if exp[0] == "/" # regex!
|
147
|
+
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
148
|
+
assert_match(exp, actual, msg)
|
149
|
+
else
|
150
|
+
assert_equal(exp, actual, msg)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
|
157
|
+
selected = File.readlines("subset.txt").map(&:chomp)
|
158
|
+
Subset = selected.empty? ? TestDirs : selected
|
159
|
+
|
160
|
+
Subset.each do |tdir|
|
161
|
+
define_method("test_#{tdir}") do
|
162
|
+
myproc = Proc.new {|bool, info| assert bool, info }
|
163
|
+
this = Snapshot.new(tdir, myproc)
|
164
|
+
this.run
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def green(str)
|
169
|
+
"[32m" + str.to_s + "[0m"
|
170
|
+
end
|
171
|
+
|
172
|
+
def red(str)
|
173
|
+
"[31m" + str.to_s + "[0m"
|
174
|
+
end
|
175
|
+
|
176
|
+
def sdiff(which, f1, f2, out, rx)
|
177
|
+
return "\n >>> No match for std#{which}!" if rx
|
178
|
+
File.open(out, "w") {|file| file.puts "#{'%-60s'% 'EXPECTED'}| #{'%-60s'% 'ACTUAL'}" }
|
179
|
+
system("/usr/bin/sdiff -t -w 121 #{f1} #{f2} >>#{out}")
|
180
|
+
return "\n >>> Unexpected std#{which}! See #{out}"
|
181
|
+
end
|
182
|
+
|
183
|
+
def external_files(base)
|
184
|
+
Dir.chdir(base) do
|
185
|
+
src, out, exp = "source.lt3", "/tmp/#{base}--actual-output.txt", "expected-output.txt"
|
186
|
+
err, erx = "/tmp/#{base}--actual-error.txt", "expected-error.txt"
|
187
|
+
|
188
|
+
# New features - match out/err by regex
|
189
|
+
expout_regex = "expected-out-line1match.txt"
|
190
|
+
experr_regex = "expected-err-line1match.txt"
|
191
|
+
|
192
|
+
cmd = "livetext #{src} >#{out} 2>#{err}"
|
193
|
+
system(cmd)
|
194
|
+
|
195
|
+
output = File.read(out)
|
196
|
+
errors = File.read(err)
|
197
|
+
rx_out = rx_err = nil
|
198
|
+
|
199
|
+
expected = File.exist?(expout_regex) ? rx_out = /#{Regexp.escape(File.read(expout_regex).chomp)}/ : File.read(exp)
|
200
|
+
errexp = File.exist?(experr_regex) ? rx_err = /#{Regexp.escape(File.read(experr_regex).chomp)}/ : File.read(erx)
|
201
|
+
|
202
|
+
out_ok = rx_out ? output =~ rx_out : output == expected
|
203
|
+
err_ok = rx_err ? errors =~ rx_err : errors == errexp
|
204
|
+
|
205
|
+
system("mkdir -p /tmp/#{base}")
|
206
|
+
bad_out = bad_err = nil
|
207
|
+
bad_out = sdiff("out", exp, out, "/tmp/#{base}/exp.out.sdiff", rx_out) unless out_ok
|
208
|
+
bad_err = sdiff("err", erx, err, "/tmp/#{base}/exp.err.sdiff", rx_err) unless err_ok
|
209
|
+
|
210
|
+
assert(err_ok, bad_err)
|
211
|
+
assert(out_ok, bad_out)
|
212
|
+
# only on success
|
213
|
+
system("rm -rf #{out} #{err} /tmp/#{base}") if out_ok && err_ok
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
|
data/test/testlines.rb
CHANGED
data/test/unit/all.rb
ADDED
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,60 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
# FIXME delete??
|
4
|
+
|
5
|
+
require 'parse_misc'
|
6
|
+
|
7
|
+
ParseMisc = ::Livetext::ParseMisc
|
8
|
+
|
9
|
+
class TestParseMisc < MiniTest::Test
|
10
|
+
|
11
|
+
def setup
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_strip_quotes
|
18
|
+
assert_raises(NilValue) { ParseMisc.new(nil).strip_quotes }
|
19
|
+
assert_raises(NullString) { ParseMisc.new("").strip_quotes }
|
20
|
+
assert_raises(MismatchedQuotes) { ParseMisc.new(%['test]).strip_quotes }
|
21
|
+
# assert_raises(MismatchedQuotes) { ParseMisc.new(%[test']).strip_quotes }
|
22
|
+
assert_raises(MismatchedQuotes) { ParseMisc.new(%["test]).strip_quotes }
|
23
|
+
# assert_raises(MismatchedQuotes) { ParseMisc.new(%[test"]).strip_quotes }
|
24
|
+
assert_raises(MismatchedQuotes) { ParseMisc.new(%["test']).strip_quotes }
|
25
|
+
assert_raises(MismatchedQuotes) { ParseMisc.new(%['test"]).strip_quotes }
|
26
|
+
|
27
|
+
assert ParseMisc.new(%[24601]).strip_quotes == "24601", "Failure 1"
|
28
|
+
assert ParseMisc.new(%[3.14]).strip_quotes == "3.14", "Failure 2"
|
29
|
+
assert ParseMisc.new(%[test]).strip_quotes == "test", "Failure 3"
|
30
|
+
assert ParseMisc.new(%['test']).strip_quotes == "test", "Failure 4"
|
31
|
+
assert ParseMisc.new(%["test"]).strip_quotes == "test", "Failure 5"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_variables
|
35
|
+
vars = ["foo 234\n", "bar 456\n"]
|
36
|
+
expect = [%w[foo 234], %w[bar 456]]
|
37
|
+
assert_equal ParseMisc.parse_vars(vars), expect
|
38
|
+
|
39
|
+
vars = ["foo2 234", "bar2 456"] # newline irrelevant
|
40
|
+
expect = [%w[foo2 234], %w[bar2 456]]
|
41
|
+
assert_equal ParseMisc.parse_vars(vars), expect
|
42
|
+
|
43
|
+
# quotes are not stripped... hmm
|
44
|
+
vars = ["alpha 'simple string'", 'beta "another string"']
|
45
|
+
expect = [["alpha", "'simple string'"], ["beta", '"another string"']]
|
46
|
+
assert_equal ParseMisc.parse_vars(vars), expect
|
47
|
+
|
48
|
+
# prefix (namespacing)
|
49
|
+
vars = ["alpha 'simple string'", 'beta "another string"']
|
50
|
+
expect = [["this.alpha", "'simple string'"], ["this.beta", '"another string"']]
|
51
|
+
assert_equal ParseMisc.parse_vars(vars, prefix: "this"), expect
|
52
|
+
|
53
|
+
# prefix (namespacing)
|
54
|
+
vars = ["alpha 'simple string'", 'beta "another string"']
|
55
|
+
expect = [["this.that.alpha", "'simple string'"], ["this.that.beta", '"another string"']]
|
56
|
+
assert_equal ParseMisc.parse_vars(vars, prefix: "this.that"), expect
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
require_relative '../../lib/parse/set'
|
5
|
+
|
6
|
+
ParseSet = Livetext::ParseSet
|
7
|
+
|
8
|
+
class TestParseSet < MiniTest::Test
|
9
|
+
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_one_unquoted
|
17
|
+
set = ParseSet.new('my_var_123 = 789').parse
|
18
|
+
pair = set.first
|
19
|
+
assert_equal pair, %w[my_var_123 789]
|
20
|
+
|
21
|
+
set = ParseSet.new('var_234 = naked_string').parse
|
22
|
+
pair = set.first
|
23
|
+
assert_equal pair, %w[var_234 naked_string]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_one_single_quoted
|
27
|
+
set = ParseSet.new("fancy.var.name = 'simple string'").parse
|
28
|
+
pair = set.first
|
29
|
+
assert_equal pair, ["fancy.var.name", "simple string"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_one_double_quoted
|
33
|
+
set = ParseSet.new('fancy.var2 = "another string"').parse
|
34
|
+
pair = set.first
|
35
|
+
assert_equal pair, ["fancy.var2", "another string"]
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_multiple_unquoted
|
39
|
+
pair1, pair2 = ParseSet.new("this=345, that=678").parse
|
40
|
+
assert_equal pair1, %w[this 345]
|
41
|
+
assert_equal pair2, %w[that 678]
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_multiple_unquoted_quoted
|
45
|
+
pair1, pair2 = ParseSet.new('alpha = 567, beta = "oh well"').parse
|
46
|
+
assert_equal pair1, %w[alpha 567]
|
47
|
+
assert_equal pair2, ["beta", "oh well"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_quote_embedded_comma
|
51
|
+
set = ParseSet.new('gamma = "oh, well"').parse
|
52
|
+
pair = set.first
|
53
|
+
assert_equal pair, ["gamma", "oh, well"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_get_var
|
57
|
+
@parse = ParseSet.new("foo=345")
|
58
|
+
assert_equal @parse.get_var, "foo"
|
59
|
+
@parse = ParseSet.new("foo = 345")
|
60
|
+
assert_equal @parse.get_var, "foo"
|
61
|
+
@parse = ParseSet.new("foo123 = 345")
|
62
|
+
assert_equal @parse.get_var, "foo123"
|
63
|
+
@parse = ParseSet.new("foo_bar = 345")
|
64
|
+
assert_equal @parse.get_var, "foo_bar"
|
65
|
+
@parse = ParseSet.new("Foobar = 345")
|
66
|
+
assert_equal @parse.get_var, "Foobar"
|
67
|
+
@parse = ParseSet.new("_foobar = 345")
|
68
|
+
assert_equal @parse.get_var, "_foobar"
|
69
|
+
|
70
|
+
# will not notice missing equal sign till later parsing
|
71
|
+
@parse = ParseSet.new("foo bar")
|
72
|
+
assert_equal @parse.get_var, "foo"
|
73
|
+
|
74
|
+
# can detect missing equal sign if iteration ends
|
75
|
+
@parse = ParseSet.new("foo")
|
76
|
+
assert_raises(NoEqualSign) { @parse.get_var }
|
77
|
+
@parse = ParseSet.new("foo-bar = 345")
|
78
|
+
assert_raises(BadVariableName) { @parse.get_var }
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_skip_equal
|
82
|
+
@parse = ParseSet.new("=")
|
83
|
+
assert_nil @parse.skip_equal
|
84
|
+
@parse = ParseSet.new(" = ")
|
85
|
+
assert_nil @parse.skip_equal
|
86
|
+
@parse = ParseSet.new(" =")
|
87
|
+
assert_nil @parse.skip_equal
|
88
|
+
@parse = ParseSet.new(" = 345")
|
89
|
+
assert_equal @parse.skip_equal, "3"
|
90
|
+
@parse = ParseSet.new(" = 'meh'")
|
91
|
+
assert_equal @parse.skip_equal, "'"
|
92
|
+
|
93
|
+
@parse = ParseSet.new("no equal here")
|
94
|
+
assert_raises(NoEqualSign) { @parse.skip_equal }
|
95
|
+
@parse = ParseSet.new("")
|
96
|
+
assert_raises(NoEqualSign) { @parse.skip_equal }
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_quoted_value
|
100
|
+
@parse = ParseSet.new(%['this'])
|
101
|
+
assert_equal @parse.quoted_value, "this"
|
102
|
+
@parse = ParseSet.new(%["that"])
|
103
|
+
assert_equal @parse.quoted_value, "that"
|
104
|
+
@parse = ParseSet.new(%[""])
|
105
|
+
assert_equal @parse.quoted_value, ""
|
106
|
+
@parse = ParseSet.new(%[''])
|
107
|
+
assert_equal @parse.quoted_value, ""
|
108
|
+
|
109
|
+
@parse = ParseSet.new(%['foo"])
|
110
|
+
assert_raises(BadQuotedString) { @parse.quoted_value }
|
111
|
+
@parse = ParseSet.new(%["bar'])
|
112
|
+
assert_raises(BadQuotedString) { @parse.quoted_value }
|
113
|
+
@parse = ParseSet.new(%['baz])
|
114
|
+
assert_raises(BadQuotedString) { @parse.quoted_value }
|
115
|
+
@parse = ParseSet.new(%["bam])
|
116
|
+
assert_raises(BadQuotedString) { @parse.quoted_value }
|
117
|
+
# LATER:
|
118
|
+
# - allow (escaped?) comma in quoted string
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_unquoted_value
|
122
|
+
# Note: an unquoted value is still a string!
|
123
|
+
@parse = ParseSet.new(%[342 ])
|
124
|
+
assert_equal @parse.unquoted_value, "342"
|
125
|
+
@parse = ParseSet.new(%[343,])
|
126
|
+
assert_equal @parse.unquoted_value, "343"
|
127
|
+
@parse = ParseSet.new(%[344,678])
|
128
|
+
assert_equal @parse.unquoted_value, "344"
|
129
|
+
@parse = ParseSet.new(%[345.123])
|
130
|
+
assert_equal @parse.unquoted_value, "345.123"
|
131
|
+
@parse = ParseSet.new(%[whatever])
|
132
|
+
assert_equal @parse.unquoted_value, "whatever"
|
133
|
+
|
134
|
+
# LATER:
|
135
|
+
# - disallow comma in unquoted string
|
136
|
+
# - disallow quote trailing unquoted string
|
137
|
+
# - allow/disallow escaping??
|
138
|
+
end
|
139
|
+
|
140
|
+
# BUG: FormatLine doesn't know variables in this context!
|
141
|
+
|
142
|
+
def xtest_4
|
143
|
+
set = ParseSet.new("file = $File").parse
|
144
|
+
assert_equal set.first, "file"
|
145
|
+
assert set.last !~ /undefined/
|
146
|
+
end
|
147
|
+
|
148
|
+
# BUG: ...or functions.
|
149
|
+
# (Additional bug: Failing silently seems wrong.)
|
150
|
+
|
151
|
+
def xtest_5
|
152
|
+
set = ParseSet.new("date = $$date").parse
|
153
|
+
assert_equal set.first, "date"
|
154
|
+
assert set.last =~ /^\d\d.\d\d.\d\d/
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
require_relative '../../../lib/parser/general'
|
5
|
+
|
6
|
+
ParseMisc = ::Livetext::ParseMisc
|
7
|
+
|
8
|
+
class TestParseMisc < MiniTest::Test
|
9
|
+
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_strip_quotes
|
17
|
+
assert_raises(NilValue) { ParseMisc.new(nil).strip_quotes }
|
18
|
+
assert_raises(NullString) { ParseMisc.new("").strip_quotes }
|
19
|
+
assert_raises(MismatchedQuotes) { ParseMisc.new(%['test]).strip_quotes }
|
20
|
+
# assert_raises(MismatchedQuotes) { ParseMisc.new(%[test']).strip_quotes }
|
21
|
+
assert_raises(MismatchedQuotes) { ParseMisc.new(%["test]).strip_quotes }
|
22
|
+
# assert_raises(MismatchedQuotes) { ParseMisc.new(%[test"]).strip_quotes }
|
23
|
+
assert_raises(MismatchedQuotes) { ParseMisc.new(%["test']).strip_quotes }
|
24
|
+
assert_raises(MismatchedQuotes) { ParseMisc.new(%['test"]).strip_quotes }
|
25
|
+
|
26
|
+
assert ParseMisc.new(%[24601]).strip_quotes == "24601", "Failure 1"
|
27
|
+
assert ParseMisc.new(%[3.14]).strip_quotes == "3.14", "Failure 2"
|
28
|
+
assert ParseMisc.new(%[test]).strip_quotes == "test", "Failure 3"
|
29
|
+
assert ParseMisc.new(%['test']).strip_quotes == "test", "Failure 4"
|
30
|
+
assert ParseMisc.new(%["test"]).strip_quotes == "test", "Failure 5"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_variables
|
34
|
+
vars = ["foo 234\n", "bar 456\n"]
|
35
|
+
expect = [%w[foo 234], %w[bar 456]]
|
36
|
+
assert_equal ParseMisc.parse_vars(vars), expect
|
37
|
+
|
38
|
+
vars = ["foo2 234", "bar2 456"] # newline irrelevant
|
39
|
+
expect = [%w[foo2 234], %w[bar2 456]]
|
40
|
+
assert_equal ParseMisc.parse_vars(vars), expect
|
41
|
+
|
42
|
+
# quotes are not stripped... hmm
|
43
|
+
vars = ["alpha 'simple string'", 'beta "another string"']
|
44
|
+
expect = [["alpha", "'simple string'"], ["beta", '"another string"']]
|
45
|
+
assert_equal ParseMisc.parse_vars(vars), expect
|
46
|
+
|
47
|
+
# prefix (namespacing)
|
48
|
+
vars = ["alpha 'simple string'", 'beta "another string"']
|
49
|
+
expect = [["this.alpha", "'simple string'"], ["this.beta", '"another string"']]
|
50
|
+
assert_equal ParseMisc.parse_vars(vars, prefix: "this"), expect
|
51
|
+
|
52
|
+
# prefix (namespacing)
|
53
|
+
vars = ["alpha 'simple string'", 'beta "another string"']
|
54
|
+
expect = [["this.that.alpha", "'simple string'"], ["this.that.beta", '"another string"']]
|
55
|
+
assert_equal ParseMisc.parse_vars(vars, prefix: "this.that"), expect
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
require_relative '../../../lib/parser/set'
|
5
|
+
|
6
|
+
ParseSet = Livetext::ParseSet
|
7
|
+
|
8
|
+
class TestParseSet < MiniTest::Test
|
9
|
+
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
end
|
15
|
+
|
16
|
+
# FIXME no tests yet
|
17
|
+
# Bad syntax? File not found? not found searching upward?
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
require_relative 'set'
|
5
|
+
|
6
|
+
ParseSet = Livetext::ParseSet
|
7
|
+
|
8
|
+
class TestParseSet < MiniTest::Test
|
9
|
+
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
end
|
15
|
+
|
16
|
+
# FIXME no tests yet
|
17
|
+
# Bad syntax? File not found? not found searching upward?
|
18
|
+
|
19
|
+
end
|