livetext 0.9.09 → 0.9.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/livetext +0 -1
- data/lib/errors.rb +15 -0
- data/lib/formatline.rb +3 -5
- data/lib/functions.rb +6 -2
- data/lib/helpers.rb +25 -0
- data/lib/html.rb +32 -0
- data/lib/livetext/importable.rb +2 -0
- data/lib/livetext.rb +60 -48
- data/lib/parser/general.rb +38 -0
- data/lib/parser/import.rb +17 -0
- data/lib/parser/mixin.rb +40 -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 -23
- data/lib/standard.rb +145 -298
- data/lib/userapi.rb +2 -5
- data/livetext.gemspec +1 -2
- data/test/all.rb +4 -0
- data/test/formatting-tests.rb +35 -0
- data/test/formatting.rb +2 -9
- data/test/snapshots/OMIT.txt +10 -0
- 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 → snapshots}/error_inc_line_num/expected-output.txt +6 -0
- data/test/{data → snapshots}/error_inc_line_num/file2.lt3 +0 -0
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
- data/test/{data → snapshots}/error_inc_line_num/source.lt3 +0 -0
- data/test/{data → snapshots}/error_invalid_name/expected-output.txt +0 -0
- data/test/snapshots/error_invalid_name/match-error.txt +1 -0
- data/test/{data → snapshots}/error_invalid_name/source.lt3 +0 -0
- data/test/{data → snapshots}/error_line_num/expected-output.txt +0 -0
- data/test/snapshots/error_line_num/match-error.txt +1 -0
- data/test/{data → snapshots}/error_line_num/source.lt3 +0 -0
- data/test/{data → snapshots}/error_mismatched_end/expected-output.txt +0 -0
- data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
- data/test/{data → snapshots}/error_mismatched_end/source.lt3 +0 -0
- data/test/{data → snapshots}/error_missing_end/expected-output.txt +1 -0
- data/test/snapshots/error_missing_end/match-error.txt +1 -0
- data/test/{data → snapshots}/error_missing_end/source.lt3 +0 -0
- data/test/{data/error_no_such_mixin → 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/{data → snapshots}/error_no_such_copy/expected-output.txt +0 -1
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_copy/source.lt3 +1 -0
- data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -0
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_inc/source.lt3 +0 -0
- data/test/snapshots/error_no_such_mixin/expected-output.txt +5 -0
- data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
- data/test/{data → snapshots}/error_no_such_mixin/source.lt3 +0 -0
- data/test/{data → 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 → 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/lines.txt → snapshots/formatting-tests.txt} +4 -0
- data/test/{data → 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 → 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}/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/raw_lines → snapshots/predef_vars}/expected-error.txt +0 -0
- data/test/snapshots/predef_vars/match-output.txt +6 -0
- data/test/snapshots/predef_vars/source.lt3 +6 -0
- data/test/{data/raw_text_block → 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_copy → 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/simple_include → 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/simple_mixin → 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/{data/simple_vars → snapshots/simple_mixin}/expected-error.txt +0 -0
- data/test/{data → snapshots}/simple_mixin/expected-output.txt +0 -0
- data/test/{data → snapshots}/simple_mixin/simple_mixin.rb +0 -0
- data/test/{data → snapshots}/simple_mixin/source.lt3 +0 -0
- data/test/{data/single_raw_line → 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/{data/table_with_heredocs → 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/{data → 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 +168 -0
- data/test/testlines.rb +17 -7
- data/test/unit/all.rb +3 -0
- data/test/unit/html.rb +38 -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 +6 -0
- data/test/unit/standard.rb +23 -0
- data/test/unit/stringparser.rb +140 -0
- metadata +122 -96
- data/test/data/error_inc_line_num/expected-err-line1match.txt +0 -1
- data/test/data/error_invalid_name/expected-err-line1match.txt +0 -1
- data/test/data/error_line_num/expected-err-line1match.txt +0 -1
- data/test/data/error_mismatched_end/expected-err-line1match.txt +0 -1
- data/test/data/error_missing_end/expected-err-line1match.txt +0 -1
- data/test/data/error_name_not_permitted/expected-error.txt +0 -1
- data/test/data/error_name_not_permitted/expected-output.txt +0 -4
- 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/data/error_no_such_mixin/expected-err-line1match.txt +0 -1
- data/test/extratests.txt +0 -20
- data/test/test.rb +0 -140
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
require_relative '../lib/livetext'
|
4
|
+
|
5
|
+
# Just another testing class. Chill.
|
6
|
+
|
7
|
+
class TestingLivetext < MiniTest::Test
|
8
|
+
|
9
|
+
TestLines = []
|
10
|
+
|
11
|
+
items = []
|
12
|
+
formatting_tests = File.open("formatting-tests.txt")
|
13
|
+
loop do
|
14
|
+
4.times { items << formatting_tests.gets.chomp }
|
15
|
+
# Blank line terminates each "stanza"
|
16
|
+
raise "Oops? #{items.inspect}" unless items.last.empty?
|
17
|
+
TestLines << items
|
18
|
+
break if formatting_tests.eof?
|
19
|
+
end
|
20
|
+
|
21
|
+
TestLines.each.with_index do |item, num|
|
22
|
+
msg, src, exp, blank = *item
|
23
|
+
define_method("test_formatting_#{num}") do
|
24
|
+
actual = FormatLine.parse!(src)
|
25
|
+
# FIXME could simplify assert logic?
|
26
|
+
if exp[0] == "/" # regex! FIXME doesn't honor %r[...]
|
27
|
+
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
28
|
+
assert_match(exp, actual, msg)
|
29
|
+
else
|
30
|
+
assert_equal(exp, actual, msg)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/test/formatting.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
|
2
|
-
require 'minitest/autorun'
|
3
|
-
end
|
4
|
-
|
5
|
-
abort "minitest gem is not installed" unless minitest?
|
6
|
-
|
7
|
-
|
8
|
-
$LOAD_PATH << "./lib"
|
1
|
+
require 'minitest/autorun'
|
9
2
|
|
10
|
-
|
3
|
+
require_relative '../lib/livetext'
|
11
4
|
|
12
5
|
class TestingLivetext < MiniTest::Test
|
13
6
|
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Comments are ignored.
|
2
|
+
# Other lines: name_of_snapshot and any comments here are ignored (no # needed)
|
3
|
+
# fake_test_name Use # to un-omit ;)
|
4
|
+
error_no_such_inc Output BEFORE error doesn't get passed through
|
5
|
+
error_no_such_copy ^ Same behavior as error_no_such_inc
|
6
|
+
simple_mixin Mixin doesn't work?? But no error... maybe _def isn't working.
|
7
|
+
error_missing_end Output is duplicated somehow. Look for: puts @body or puts @main.body
|
8
|
+
error_no_such_mixin ^ Same behavior as error_missing_end
|
9
|
+
error_line_num Same behavior as error_missing_end
|
10
|
+
error_invalid_name ^ Same behavior as error_no_such_inc
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: Name 'foobar' is unknown/
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: Illegal name 'to_s'/
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: Name 'foobar' is unknown/
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: found .end with no opening command/
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: Expected .end, found end of file/
|
File without changes
|
data/test/{data/error_no_such_mixin → snapshots/error_name_not_permitted}/expected-output.txt
RENAMED
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Disallowed/
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: file nosuchfile.txt not found/
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /Error: file nosuchinc.lt3 not found/
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /No such mixin 'nosuchthing'/
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/snapshots.rb
ADDED
@@ -0,0 +1,168 @@
|
|
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 Snapshot.new
|
12
|
+
|
13
|
+
It 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
|
17
|
+
- ...and also either expected-output.txt OR match-output.txt (not both)
|
18
|
+
- ...and also either expected-error.txt OR match-error.txt (not both)
|
19
|
+
- Technically, any existing file can be empty
|
20
|
+
- The expected-* files are "literal" data
|
21
|
+
* compared byte-for-byte
|
22
|
+
* watch spaces and bad regexes, etc. #duh
|
23
|
+
* each of these files corresponds to a single assertion
|
24
|
+
- A match-* file has two entries per line:
|
25
|
+
* a ONE-BASED line number (in actual-* file)
|
26
|
+
* a String OR a Regexp (to match against that line)
|
27
|
+
* If there is nonsense here, it currently isn't caught
|
28
|
+
* each of these files MAY correspond to many assertions
|
29
|
+
- We run livetext on the source and compare actual vs expected (stdout, stderr)
|
30
|
+
- The error output gets checked first (expected or match), THEN standard output
|
31
|
+
- Of course, both must compare correctly for the test to pass
|
32
|
+
=end
|
33
|
+
|
34
|
+
|
35
|
+
# Just a testing class. Chill.
|
36
|
+
|
37
|
+
class TestingLivetext < MiniTest::Test
|
38
|
+
|
39
|
+
class Snapshot
|
40
|
+
SOURCE = "source.lt3"
|
41
|
+
# Will now keep "actual" output in same dir?
|
42
|
+
ACTUAL_OUT, ACTUAL_ERR = "actual-output.txt", "actual-error.txt"
|
43
|
+
EXP_OUT, EXP_ERR = "expected-output.txt", "expected-error.txt"
|
44
|
+
MATCH_OUT, MATCH_ERR = "match-output.txt", "match-error.txt"
|
45
|
+
|
46
|
+
def initialize(base, assertion = nil)
|
47
|
+
@assertion = assertion
|
48
|
+
@base = base
|
49
|
+
@errors = false
|
50
|
+
Dir.chdir(base) do
|
51
|
+
@literal_out = File.exist?(EXP_OUT)
|
52
|
+
@literal_err = File.exist?(EXP_ERR)
|
53
|
+
@match_out = File.exist?(MATCH_OUT)
|
54
|
+
@match_err = File.exist?(MATCH_ERR)
|
55
|
+
end
|
56
|
+
bad_files = (@literal_out && @match_out) || (@literal_err && @match_err)
|
57
|
+
raise "Inconsistent structure for #@base" if bad_files
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_matches(actual, control)
|
61
|
+
controls = File.readlines(control).map(&:chomp)
|
62
|
+
lines = File.readlines(actual).map(&:chomp)
|
63
|
+
lines.unshift("DUMMY LINE") # 1-based index! (for when I'm editing)
|
64
|
+
controls.each do |line|
|
65
|
+
line_num, item = line.split(" ", 2)
|
66
|
+
item = Regexp.new(item[1..-2]) if item[0] == "/" # Hmm, string can't start with /...
|
67
|
+
line_num = line_num.to_i
|
68
|
+
info = "Expected line #{line_num} of #{actual.inspect} to match #{item.inspect} (was: #{lines[line_num].inspect})"
|
69
|
+
good = item === lines[line_num]
|
70
|
+
@errors = true unless good
|
71
|
+
@assertion.call item === lines[line_num], info # string or regex
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def sdiff(f1, f2, out)
|
76
|
+
File.open(out, "w") {|file| file.puts "#{'%-60s'% 'ACTUAL'}| #{'%-60s'% 'EXPECTED'}" }
|
77
|
+
system("/usr/bin/sdiff -t -w 121 #{f1} #{f2} >>#{out}")
|
78
|
+
end
|
79
|
+
|
80
|
+
def check_stdout
|
81
|
+
if @literal_out
|
82
|
+
actual, expected = File.read(ACTUAL_OUT), File.read(EXP_OUT)
|
83
|
+
same = actual == expected
|
84
|
+
@errors = true if not same
|
85
|
+
file = "out-sdiff.txt"
|
86
|
+
sdiff(ACTUAL_OUT, EXP_OUT, file)
|
87
|
+
@assertion.call same, "Discrepancy in STDOUT - see #{file} in test/snapshots/#@base"
|
88
|
+
else
|
89
|
+
check_matches(ACTUAL_OUT, MATCH_OUT)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def check_stderr
|
94
|
+
if @literal_err
|
95
|
+
actual, expected = File.read(ACTUAL_ERR), File.read(EXP_ERR)
|
96
|
+
same = actual == expected
|
97
|
+
@errors = true if not same
|
98
|
+
file = "err-sdiff.txt"
|
99
|
+
sdiff(ACTUAL_ERR, EXP_ERR, file)
|
100
|
+
@assertion.call same, "Discrepancy in STDERR - see #{file} in test/snapshots/#@base"
|
101
|
+
else
|
102
|
+
check_matches(ACTUAL_ERR, MATCH_ERR)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def cleanup
|
107
|
+
return if @errors
|
108
|
+
system("rm -f #{ACTUAL_OUT} #{ACTUAL_ERR} *sdiff.txt")
|
109
|
+
end
|
110
|
+
|
111
|
+
def filter # TODO move subset/omit logic here??
|
112
|
+
end
|
113
|
+
|
114
|
+
def run
|
115
|
+
@errors = false # oops, need to reset
|
116
|
+
Dir.chdir(@base) do
|
117
|
+
cmd = "../../../bin/livetext #{SOURCE} >#{ACTUAL_OUT} 2>#{ACTUAL_ERR}"
|
118
|
+
system(cmd)
|
119
|
+
check_stdout
|
120
|
+
check_stderr
|
121
|
+
cleanup
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
TTY = File.open("/dev/tty","w")
|
127
|
+
|
128
|
+
cmdline = ARGV.first == "cmdline" # FIXME remove??
|
129
|
+
if cmdline
|
130
|
+
dir = "../"
|
131
|
+
Dir.chdir `livetext --path`.chomp.chomp
|
132
|
+
else
|
133
|
+
dir = ""
|
134
|
+
end
|
135
|
+
|
136
|
+
Data = "#{dir}test/snapshots"
|
137
|
+
Dir.chdir(Data)
|
138
|
+
|
139
|
+
TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
|
140
|
+
|
141
|
+
selected = File.readlines("subset.txt").map(&:chomp)
|
142
|
+
|
143
|
+
omitfile = "OMIT.txt"
|
144
|
+
omitted = File.readlines(omitfile).map(&:chomp)
|
145
|
+
omitted.reject! {|line| line.start_with?("#") }
|
146
|
+
omit_names = omitted.map {|line| line.split.first }
|
147
|
+
STDERR.puts
|
148
|
+
STDERR.puts " >>> Warning: Omitting #{omitted.size} snapshot tests:\n "
|
149
|
+
indented = " "*7
|
150
|
+
omitted.each do |line|
|
151
|
+
STDERR.print indented
|
152
|
+
name, info = line.split(" ", 2)
|
153
|
+
STDERR.printf "%-20s %s\n", name, info
|
154
|
+
end
|
155
|
+
STDERR.puts
|
156
|
+
|
157
|
+
wanted = selected.empty? ? TestDirs : selected
|
158
|
+
|
159
|
+
Subset = wanted - omit_names
|
160
|
+
|
161
|
+
Subset.each do |tdir|
|
162
|
+
define_method("test_#{tdir}") do
|
163
|
+
myproc = Proc.new {|bool, info| assert bool, info }
|
164
|
+
this = Snapshot.new(tdir, myproc)
|
165
|
+
this.run
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/test/testlines.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'livetext'
|
2
|
-
require 'formatline'
|
1
|
+
require '../lib/livetext'
|
2
|
+
require '../lib/formatline'
|
3
3
|
|
4
4
|
def red(str)
|
5
5
|
"[31m" + str + "[0m"
|
@@ -8,20 +8,30 @@ require 'formatline'
|
|
8
8
|
input = ARGV.first || "test/data/lines.txt"
|
9
9
|
data = File.readlines(input)
|
10
10
|
|
11
|
-
|
11
|
+
pass = fail = 0
|
12
|
+
data.each_slice(4).with_index do |lines, i|
|
12
13
|
title, input, expected, blank = *lines
|
14
|
+
lnum = i*4 + 1
|
13
15
|
input.chomp!
|
14
16
|
expected.chomp!
|
15
17
|
expected = eval(expected) if expected[0] == "/"
|
16
18
|
|
17
|
-
puts "-----------------------------"
|
18
|
-
print "Test: #{title}"
|
19
19
|
|
20
20
|
actual = FormatLine.parse!(input)
|
21
|
-
|
21
|
+
if expected === actual
|
22
|
+
pass += 1
|
23
|
+
# puts "PASS: #{title}"
|
24
|
+
next
|
25
|
+
end
|
22
26
|
|
23
|
-
|
27
|
+
fail += 1
|
28
|
+
puts "----------------------------- (line #{lnum})"
|
29
|
+
puts "Test: #{title}"
|
30
|
+
puts "Input: #{input}"
|
24
31
|
puts " #{red('FAIL Expected: ')} #{expected.inspect}"
|
25
32
|
puts " #{red(' Actual : ')} #{actual.inspect}"
|
26
33
|
puts
|
27
34
|
end
|
35
|
+
|
36
|
+
puts
|
37
|
+
puts "#{pass} passes #{fail} fails"
|
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
|