livetext 0.9.09 → 0.9.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/bin/livetext +0 -1
  3. data/lib/errors.rb +15 -0
  4. data/lib/formatline.rb +3 -5
  5. data/lib/functions.rb +6 -2
  6. data/lib/helpers.rb +25 -0
  7. data/lib/html.rb +32 -0
  8. data/lib/livetext/importable.rb +2 -0
  9. data/lib/livetext.rb +60 -48
  10. data/lib/parser/general.rb +38 -0
  11. data/lib/parser/import.rb +17 -0
  12. data/lib/parser/mixin.rb +40 -0
  13. data/lib/parser/set.rb +136 -0
  14. data/lib/parser/string.rb +55 -0
  15. data/lib/parser.rb +5 -0
  16. data/lib/processor.rb +22 -23
  17. data/lib/standard.rb +145 -298
  18. data/lib/userapi.rb +2 -5
  19. data/livetext.gemspec +1 -2
  20. data/test/all.rb +4 -0
  21. data/test/formatting-tests.rb +35 -0
  22. data/test/formatting.rb +2 -9
  23. data/test/snapshots/OMIT.txt +10 -0
  24. data/test/{data → snapshots}/basic_formatting/expected-error.txt +0 -0
  25. data/test/{data → snapshots}/basic_formatting/expected-output.txt +0 -0
  26. data/test/{data → snapshots}/basic_formatting/source.lt3 +0 -0
  27. data/test/{data → snapshots}/block_comment/expected-error.txt +0 -0
  28. data/test/{data → snapshots}/block_comment/expected-output.txt +0 -0
  29. data/test/{data → snapshots}/block_comment/source.lt3 +0 -0
  30. data/test/{data → snapshots}/comments_ignored_1/expected-error.txt +0 -0
  31. data/test/{data → snapshots}/comments_ignored_1/expected-output.txt +0 -0
  32. data/test/{data → snapshots}/comments_ignored_1/source.lt3 +0 -0
  33. data/test/{data → snapshots}/copy_is_raw/expected-error.txt +0 -0
  34. data/test/{data → snapshots}/copy_is_raw/expected-output.txt +0 -0
  35. data/test/{data → snapshots}/copy_is_raw/rawtext.inc +0 -0
  36. data/test/{data → snapshots}/copy_is_raw/source.lt3 +0 -0
  37. data/test/{data → snapshots}/crap +0 -0
  38. data/test/{data → snapshots}/def_method/expected-error.txt +0 -0
  39. data/test/{data → snapshots}/def_method/expected-output.txt +0 -0
  40. data/test/{data → snapshots}/def_method/source.lt3 +0 -0
  41. data/test/{data → snapshots}/error_inc_line_num/expected-output.txt +6 -0
  42. data/test/{data → snapshots}/error_inc_line_num/file2.lt3 +0 -0
  43. data/test/snapshots/error_inc_line_num/match-error.txt +1 -0
  44. data/test/{data → snapshots}/error_inc_line_num/source.lt3 +0 -0
  45. data/test/{data → snapshots}/error_invalid_name/expected-output.txt +0 -0
  46. data/test/snapshots/error_invalid_name/match-error.txt +1 -0
  47. data/test/{data → snapshots}/error_invalid_name/source.lt3 +0 -0
  48. data/test/{data → snapshots}/error_line_num/expected-output.txt +0 -0
  49. data/test/snapshots/error_line_num/match-error.txt +1 -0
  50. data/test/{data → snapshots}/error_line_num/source.lt3 +0 -0
  51. data/test/{data → snapshots}/error_mismatched_end/expected-output.txt +0 -0
  52. data/test/snapshots/error_mismatched_end/match-error.txt +1 -0
  53. data/test/{data → snapshots}/error_mismatched_end/source.lt3 +0 -0
  54. data/test/{data → snapshots}/error_missing_end/expected-output.txt +1 -0
  55. data/test/snapshots/error_missing_end/match-error.txt +1 -0
  56. data/test/{data → snapshots}/error_missing_end/source.lt3 +0 -0
  57. data/test/{data/error_no_such_mixin → snapshots/error_name_not_permitted}/expected-output.txt +0 -0
  58. data/test/snapshots/error_name_not_permitted/match-error.txt +1 -0
  59. data/test/{data → snapshots}/error_name_not_permitted/source.lt3 +0 -0
  60. data/test/{data → snapshots}/error_no_such_copy/expected-output.txt +0 -1
  61. data/test/snapshots/error_no_such_copy/match-error.txt +1 -0
  62. data/test/{data → snapshots}/error_no_such_copy/source.lt3 +1 -0
  63. data/test/{data → snapshots}/error_no_such_inc/expected-output.txt +0 -0
  64. data/test/snapshots/error_no_such_inc/match-error.txt +1 -0
  65. data/test/{data → snapshots}/error_no_such_inc/source.lt3 +0 -0
  66. data/test/snapshots/error_no_such_mixin/expected-output.txt +5 -0
  67. data/test/snapshots/error_no_such_mixin/match-error.txt +1 -0
  68. data/test/{data → snapshots}/error_no_such_mixin/source.lt3 +0 -0
  69. data/test/{data → snapshots}/example_alpha/expected-error.txt +0 -0
  70. data/test/{data → snapshots}/example_alpha/expected-output.txt +0 -0
  71. data/test/{data → snapshots}/example_alpha/source.lt3 +0 -0
  72. data/test/{data → snapshots}/example_alpha2/expected-error.txt +0 -0
  73. data/test/{data → snapshots}/example_alpha2/expected-output.txt +0 -0
  74. data/test/{data → snapshots}/example_alpha2/source.lt3 +0 -0
  75. data/test/{data → snapshots}/fixit +0 -0
  76. data/test/{data/lines.txt → snapshots/formatting-tests.txt} +4 -0
  77. data/test/{data → snapshots}/functions/expected-error.txt +0 -0
  78. data/test/{data → snapshots}/functions/expected-output.txt +0 -0
  79. data/test/{data → snapshots}/functions/source.lt3 +0 -0
  80. data/test/{data → snapshots}/hello_world/expected-error.txt +0 -0
  81. data/test/{data → snapshots}/hello_world/expected-output.txt +0 -0
  82. data/test/{data → snapshots}/hello_world/source.lt3 +0 -0
  83. data/test/{data → snapshots}/more_complex_vars/expected-error.txt +0 -0
  84. data/test/{data → snapshots}/more_complex_vars/expected-output.txt +0 -0
  85. data/test/{data → snapshots}/more_complex_vars/source.lt3 +0 -0
  86. data/test/{data/raw_lines → snapshots/predef_vars}/expected-error.txt +0 -0
  87. data/test/snapshots/predef_vars/match-output.txt +6 -0
  88. data/test/snapshots/predef_vars/source.lt3 +6 -0
  89. data/test/{data/raw_text_block → snapshots/raw_lines}/expected-error.txt +0 -0
  90. data/test/{data → snapshots}/raw_lines/expected-output.txt +0 -0
  91. data/test/{data → snapshots}/raw_lines/source.lt3 +0 -0
  92. data/test/{data/simple_copy → snapshots/raw_text_block}/expected-error.txt +0 -0
  93. data/test/{data → snapshots}/raw_text_block/expected-output.txt +0 -0
  94. data/test/{data → snapshots}/raw_text_block/rawtext.inc +0 -0
  95. data/test/{data → snapshots}/raw_text_block/source.lt3 +0 -0
  96. data/test/{data/simple_include → snapshots/simple_copy}/expected-error.txt +0 -0
  97. data/test/{data → snapshots}/simple_copy/expected-output.txt +0 -0
  98. data/test/{data → snapshots}/simple_copy/simplefile.inc +0 -0
  99. data/test/{data → snapshots}/simple_copy/source.lt3 +0 -0
  100. data/test/{data/simple_mixin → snapshots/simple_include}/expected-error.txt +0 -0
  101. data/test/{data → snapshots}/simple_include/expected-output.txt +0 -0
  102. data/test/{data → snapshots}/simple_include/simplefile.inc +0 -0
  103. data/test/{data → snapshots}/simple_include/source.lt3 +0 -0
  104. data/test/{data/simple_vars → snapshots/simple_mixin}/expected-error.txt +0 -0
  105. data/test/{data → snapshots}/simple_mixin/expected-output.txt +0 -0
  106. data/test/{data → snapshots}/simple_mixin/simple_mixin.rb +0 -0
  107. data/test/{data → snapshots}/simple_mixin/source.lt3 +0 -0
  108. data/test/{data/single_raw_line → snapshots/simple_vars}/expected-error.txt +0 -0
  109. data/test/{data → snapshots}/simple_vars/expected-output.txt +0 -0
  110. data/test/{data → snapshots}/simple_vars/source.lt3 +0 -0
  111. data/test/{data/table_with_heredocs → snapshots/single_raw_line}/expected-error.txt +0 -0
  112. data/test/{data → snapshots}/single_raw_line/expected-output.txt +0 -0
  113. data/test/{data → snapshots}/single_raw_line/source.lt3 +0 -0
  114. data/test/{data → snapshots}/subset.txt +0 -0
  115. data/test/snapshots/table_with_heredocs/expected-error.txt +0 -0
  116. data/test/{data → snapshots}/table_with_heredocs/expected-output.txt +0 -0
  117. data/test/{data → snapshots}/table_with_heredocs/source.lt3 +0 -0
  118. data/test/snapshots.rb +168 -0
  119. data/test/testlines.rb +17 -7
  120. data/test/unit/all.rb +3 -0
  121. data/test/unit/html.rb +38 -0
  122. data/test/unit/parser/all.rb +3 -0
  123. data/test/unit/parser/general.rb +59 -0
  124. data/test/unit/parser/importable.rb +19 -0
  125. data/test/unit/parser/mixin.rb +19 -0
  126. data/test/unit/parser/set.rb +157 -0
  127. data/test/unit/parser/string.rb +130 -0
  128. data/test/unit/parser.rb +6 -0
  129. data/test/unit/standard.rb +23 -0
  130. data/test/unit/stringparser.rb +140 -0
  131. metadata +122 -96
  132. data/test/data/error_inc_line_num/expected-err-line1match.txt +0 -1
  133. data/test/data/error_invalid_name/expected-err-line1match.txt +0 -1
  134. data/test/data/error_line_num/expected-err-line1match.txt +0 -1
  135. data/test/data/error_mismatched_end/expected-err-line1match.txt +0 -1
  136. data/test/data/error_missing_end/expected-err-line1match.txt +0 -1
  137. data/test/data/error_name_not_permitted/expected-error.txt +0 -1
  138. data/test/data/error_name_not_permitted/expected-output.txt +0 -4
  139. data/test/data/error_no_such_copy/expected-err-line1match.txt +0 -1
  140. data/test/data/error_no_such_inc/expected-err-line1match.txt +0 -1
  141. data/test/data/error_no_such_mixin/expected-err-line1match.txt +0 -1
  142. data/test/extratests.txt +0 -20
  143. 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
- def minitest?
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
- require 'livetext'
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
@@ -5,3 +5,9 @@ which includes file2 here:
5
5
  which has an error
6
6
  about an unknown command
7
7
  in line 5
8
+ <p>
9
+
10
+ And this is file2 line 7.
11
+ And here we are
12
+ back in the
13
+ original file.
@@ -0,0 +1 @@
1
+ 1 /Error: Name 'foobar' is unknown/
@@ -0,0 +1 @@
1
+ 1 /Error: Illegal name 'to_s'/
@@ -0,0 +1 @@
1
+ 1 /Error: Name 'foobar' is unknown/
File without changes
@@ -0,0 +1 @@
1
+ 1 /Error: found .end with no opening command/
@@ -0,0 +1 @@
1
+ 1 /Error: Expected .end, found end of file/
@@ -0,0 +1 @@
1
+ 1 /Disallowed/
@@ -2,4 +2,3 @@ Make sure a
2
2
  nonexistent file with .copy
3
3
  gives an error.
4
4
  <p>
5
-
@@ -0,0 +1 @@
1
+ 1 /Error: file nosuchfile.txt not found/
@@ -1,3 +1,4 @@
1
+ .debug
1
2
  Make sure a
2
3
  nonexistent file with .copy
3
4
  gives an error.
@@ -0,0 +1 @@
1
+ 1 /Error: file nosuchinc.lt3 not found/
@@ -0,0 +1,5 @@
1
+ Test that
2
+ we give an error
3
+ when a mixin does not
4
+ exist:
5
+ <p>
@@ -0,0 +1 @@
1
+ 1 /No such mixin 'nosuchthing'/
File without changes
File without changes
File without changes
@@ -118,3 +118,7 @@ Doubled underscore, midline
118
118
  This is __doubled, it seems
119
119
  This is <i>doubled</i>, it seems
120
120
 
121
+ Underscore inside parens
122
+ This is (_italicized and parenthesized)
123
+ This is (<i>italicized</i> and parenthesized)
124
+
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ 1 Here we go...
2
+ 2 File = source.lt3
3
+ 3 /FileDir = .*.test.snapshots.predef_vars/
4
+ 4 /User = [A-Za-z][A-Za-z0-9]*/
5
+ 5 /Version = 0\.\d{1,2}\.\d{1,2}/
6
+ 6 NoSuchVar = [NoSuchVar is undefined]
@@ -0,0 +1,6 @@
1
+ Here we go...
2
+ File = $File
3
+ FileDir = $FileDir
4
+ User = $User
5
+ Version = $Version
6
+ NoSuchVar = $NoSuchVar
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
  "" + str + ""
@@ -8,20 +8,30 @@ require 'formatline'
8
8
  input = ARGV.first || "test/data/lines.txt"
9
9
  data = File.readlines(input)
10
10
 
11
- data.each_slice(4) do |lines|
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
- next if expected === actual
21
+ if expected === actual
22
+ pass += 1
23
+ # puts "PASS: #{title}"
24
+ next
25
+ end
22
26
 
23
- puts "Input: #{input}"
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
@@ -0,0 +1,3 @@
1
+
2
+ require_relative 'standard'
3
+ require_relative 'parser' # nested
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