livetext 0.9.01 → 0.9.06

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b5dbf29a35e17c163982a4c2d5355949a72be58c662e75cf1f1d59bef1894dd
4
- data.tar.gz: 882f20c410919dc4aa5f5d4e4277cdff88dca8efce5b1d0d96d1228767dd80c3
3
+ metadata.gz: 4070b2fad292adbaaf7e01d3436d352e91c4af4d51a9cdf4217af97ab9650d2f
4
+ data.tar.gz: 483229184f006895624ab5bb9abecf3c64e131d813ad7ec5f7dca761d148890b
5
5
  SHA512:
6
- metadata.gz: 58671323ec46267e898c2999e86fc3f5e1379eae4adca5df0adf7be90d0d8b35a9aefaa9f4bf778f67963624fa764ba8087349500e5c4c280c90297c9fc07789
7
- data.tar.gz: 3ddfa97b6ef5a86c311baf9df53851bf39f01780fbec54a34de64bd9b4970aa8e055b77147891927e1ed378b87a050a414d11a51d942010ba0d774a99714e3bb
6
+ metadata.gz: 8fa6323f64814746b0181b7440b3f85638c1a42275816aa541d41dccbfccf20d2730f6a4d151981a7232f7c89fb3f165d6f35ec1d2df1b8bfcf81b9ccaeec854
7
+ data.tar.gz: 89f65b89dd48f01ea6afa008fbd5db90ff68349cdc5fc2a45e7653830d631d230962b0c04b5a0b3406ad3fccd95b8c0eff21afdf84016a3186721257cc081dc6
@@ -195,6 +195,7 @@ class FormatLine
195
195
  end
196
196
 
197
197
  def add_token(kind, token = @token)
198
+ return if token.nil?
198
199
  @tokenlist << [kind, token] unless token.empty?
199
200
  @token = Null.dup
200
201
  end
@@ -352,6 +353,8 @@ class FormatLine
352
353
  grab # ZZZ
353
354
  loop do
354
355
  case
356
+ when curr.nil?
357
+ return str
355
358
  when curr == Escape
356
359
  str << escaped
357
360
  next
@@ -1,5 +1,5 @@
1
1
  class Livetext
2
- VERSION = "0.9.01"
2
+ VERSION = "0.9.06"
3
3
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
4
4
  end
5
5
 
@@ -31,6 +31,10 @@ class Livetext
31
31
  attr_accessor :output # both bad solutions?
32
32
  end
33
33
 
34
+ def vars
35
+ Livetext::Vars.dup
36
+ end
37
+
34
38
  def self.customize(mix: [], call: [], vars: {})
35
39
  obj = self.new
36
40
  mix = Array(mix)
@@ -50,10 +54,6 @@ class Livetext
50
54
  self
51
55
  end
52
56
 
53
- def vars
54
- Livetext::Vars.dup
55
- end
56
-
57
57
  Space = " "
58
58
  Sigil = "." # Can't change yet
59
59
 
@@ -73,29 +73,30 @@ class Livetext
73
73
  @body = ""
74
74
  @main = Processor.new(self, output)
75
75
  @indentation = [0]
76
+ @_vars = Livetext::Vars
76
77
  end
77
78
 
78
- def _parse_colon_args(args, hash) # really belongs in livetext
79
- h2 = hash.dup
80
- e = args.each
81
- loop do
82
- arg = e.next.chop.to_sym
83
- raise "_parse_args: #{arg} is unknown" unless hash.keys.include?(arg)
84
- h2[arg] = e.next
79
+ def _parse_colon_args(args, hash) # really belongs in livetext
80
+ h2 = hash.dup
81
+ e = args.each
82
+ loop do
83
+ arg = e.next.chop.to_sym
84
+ raise "_parse_args: #{arg} is unknown" unless hash.keys.include?(arg)
85
+ h2[arg] = e.next
86
+ end
87
+ h2 = h2.reject {|k,v| v.nil? }
88
+ h2.each_pair {|k, v| raise "#{k} has no value" if v.empty? }
89
+ h2
85
90
  end
86
- h2 = h2.reject {|k,v| v.nil? }
87
- h2.each_pair {|k, v| raise "#{k} has no value" if v.empty? }
88
- h2
89
- end
90
91
 
91
- def _get_arg(name, args) # really belongs in livetext
92
- raise "(#{name}) Expected an array" unless args.is_a? Array
93
- raise "(#{name}) Expected an arg" if args.empty?
94
- raise "(#{name}) Too many args: #{args.inspect}" if args.size > 1
95
- val = args[0]
96
- raise "Expected an argument '#{name}'" if val.nil?
97
- val
98
- end
92
+ def _get_arg(name, args) # really belongs in livetext
93
+ raise "(#{name}) Expected an array" unless args.is_a? Array
94
+ raise "(#{name}) Expected an arg" if args.empty?
95
+ raise "(#{name}) Too many args: #{args.inspect}" if args.size > 1
96
+ val = args[0]
97
+ raise "Expected an argument '#{name}'" if val.nil?
98
+ val
99
+ end
99
100
 
100
101
  def mixin(mod)
101
102
  @main._mixin(mod)
@@ -105,6 +106,8 @@ end
105
106
  str, sym = var.to_s, var.to_sym
106
107
  Livetext::Vars[str] = val
107
108
  Livetext::Vars[sym] = val
109
+ @_vars[str] = val
110
+ @_vars[sym] = val
108
111
  end
109
112
 
110
113
  def _setfile(file)
@@ -166,50 +169,13 @@ end
166
169
  self.body
167
170
  end
168
171
 
169
- def xform_file(file, vars: {})
172
+ def xform_file(file) # , vars: {})
170
173
  Livetext::Vars.replace(vars) unless vars.nil?
174
+ @_vars.replace(vars) unless vars.nil?
171
175
  self.process_file(file)
172
176
  self.body
173
177
  end
174
178
 
175
- # def transform(text)
176
- # _setfile!("(string)")
177
- # @output = ::Livetext.output
178
- # enum = text.each_line
179
- # front = text.match(/.*?\n/).to_a.first.chomp rescue "..."
180
- # @main.source(enum, "STDIN: '#{front}...'", 0)
181
- # loop do
182
- # line = @main.nextline
183
- # break if line.nil?
184
- # process_line(line) # transform_line ???
185
- # end
186
- # @body
187
- # end
188
-
189
- ## FIXME don't need process *and* process_text
190
-
191
- # def process_text(text)
192
- # _setfile!("(string)")
193
- # text = text.split("\n") if text.is_a? String
194
- # enum = text.each
195
- # @backtrace = false
196
- # front = text[0].chomp
197
- # @main.source(enum, "(text): '#{front}...'", 0)
198
- # loop do
199
- # line = @main.nextline
200
- # break if line.nil?
201
- # process_line(line)
202
- # end
203
- # val = @main.finalize if @main.respond_to? :finalize
204
- # val
205
- # rescue => err
206
- # puts "process_text: err = #{err}"
207
- ## puts err.backtrace.join("\n")
208
- # puts @body
209
- # @body = ""
210
- # return @body
211
- # end
212
-
213
179
  ## FIXME process_file[!] should call process[_text]
214
180
 
215
181
  def process_file(fname, btrace=false)
@@ -231,21 +197,6 @@ end
231
197
  @body = ""
232
198
  end
233
199
 
234
- # def process_file!(fname, backtrace=false)
235
- # _setfile(fname)
236
- # raise "No such file '#{fname}' to process" unless File.exist?(fname)
237
- # @main.output = StringIO.new
238
- # enum = File.readlines(fname).each
239
- # @backtrace = backtrace
240
- # @main.source(enum, fname, 0)
241
- # loop do
242
- # line = @main.nextline
243
- # break if line.nil?
244
- # process_line(line)
245
- # end
246
- # @main.finalize if @main.respond_to? :finalize
247
- # end
248
-
249
200
  def handle_scomment(line)
250
201
  end
251
202
 
@@ -265,13 +216,13 @@ end
265
216
 
266
217
  def handle_dotcmd(line, indent = 0)
267
218
  indent = @indentation.last # top of stack
268
- line = line.sub(/# .*$/, "")
219
+ line = line.sub(/# .*$/, "")
269
220
  name = _get_name(line).to_sym
270
221
  result = nil
271
222
  if @main.respond_to?(name)
272
223
  result = @main.send(name)
273
224
  else
274
- @main._error! "Name '#{name}' is unknown; version = #{Livetext::VERSION}"
225
+ @main._error! "Name '#{name}' is unknown"
275
226
  return
276
227
  end
277
228
  result
@@ -35,7 +35,7 @@ class Livetext
35
35
  def _error!(err, abort=true, trace=false)
36
36
  where = @sources.last || @save_location
37
37
  puts @parent.body
38
- STDERR.puts "Error: #{err} (at #{where[1]} line #{where[2]})"
38
+ STDERR.puts "Error: #{err} " # (at #{where[1]} line #{where[2]})"
39
39
  STDERR.puts err.backtrace if err.respond_to?(:backtrace) # && trace
40
40
  exit if abort
41
41
  end
@@ -9,7 +9,7 @@ module Livetext::Standard
9
9
  attr_reader :_data
10
10
 
11
11
  def data=(val)
12
- @_data = val
12
+ @_data = val.chomp
13
13
  @_args = val.split rescue []
14
14
  @_mixins = []
15
15
  end
@@ -33,7 +33,7 @@ module Livetext::Standard
33
33
  end
34
34
 
35
35
  def shell
36
- cmd = @_data
36
+ cmd = @_data.chomp
37
37
  # _errout("Running: #{cmd}")
38
38
  system(cmd)
39
39
  end
@@ -49,23 +49,30 @@ EOS
49
49
  Livetext::Functions.class_eval func_def
50
50
  end
51
51
 
52
+ def h1; _out "<h1>#{@_data}</h1>"; end
53
+ def h2; _out "<h2>#{@_data}</h2>"; end
54
+ def h3; _out "<h3>#{@_data}</h3>"; end
55
+ def h4; _out "<h4>#{@_data}</h4>"; end
56
+ def h5; _out "<h5>#{@_data}</h5>"; end
57
+ def h6; _out "<h6>#{@_data}</h6>"; end
58
+
52
59
  def shell!
53
- cmd = @_data
60
+ cmd = @_data.chomp
54
61
  system(cmd)
55
62
  end
56
63
 
57
64
  def errout
58
- TTY.puts @_data
65
+ TTY.puts @_data.chomp
59
66
  end
60
67
 
61
68
  def say
62
- str = _format(@_data)
69
+ str = _format(@_data.chomp)
63
70
  TTY.puts str
64
71
  _optional_blank_line
65
72
  end
66
73
 
67
74
  def banner
68
- str = _format(@_data)
75
+ str = _format(@_data.chomp)
69
76
  n = str.length - 1
70
77
  puts "-"*n
71
78
  puts str
@@ -94,7 +101,7 @@ EOS
94
101
  name = @_args[0]
95
102
  str = "def #{name}\n"
96
103
  raise "Illegal name '#{name}'" if _disallowed?(name)
97
- str += _body_text(true)
104
+ str += _body(true).join("\n")
98
105
  str += "\nend\n"
99
106
  eval str
100
107
  rescue => err
@@ -179,7 +186,7 @@ EOS
179
186
  end
180
187
 
181
188
  def set_NEW
182
- line = _data.dup # dup needed?
189
+ line = _data.chomp
183
190
  e = line.each_char # enum
184
191
  loop do
185
192
  c = e.next
@@ -205,6 +212,7 @@ EOS
205
212
  else
206
213
  lines = _body
207
214
  end
215
+ lines.map! {|x| x.sub(/# .*/, "").strip } # strip comments
208
216
  lines.each do |line|
209
217
  next if line.strip.empty?
210
218
  var, val = line.split(" ", 2)
@@ -215,12 +223,12 @@ EOS
215
223
  end
216
224
 
217
225
  def reval
218
- eval _data
226
+ eval _data.chomp
219
227
  end
220
228
 
221
229
  def heredoc
222
230
  var = @_args[0]
223
- str = _body_text
231
+ str = _body.join("\n")
224
232
  s2 = ""
225
233
  str.each_line do |s|
226
234
  str = FormatLine.var_func_parse(s.chomp)
@@ -346,7 +354,7 @@ EOS
346
354
  end
347
355
 
348
356
  def r
349
- _out @_data # No processing at all
357
+ _out @_data.chomp # No processing at all
350
358
  end
351
359
 
352
360
  def raw
@@ -392,7 +400,7 @@ EOS
392
400
 
393
401
  def heading
394
402
  _print "<center><font size=+1><b>"
395
- _print @_data
403
+ _print @_data.chomp
396
404
  _print "</b></font></center>"
397
405
  end
398
406
 
@@ -443,7 +451,7 @@ EOS
443
451
  end
444
452
 
445
453
  def xtable # Borrowed from bookish - FIXME
446
- title = @_data
454
+ title = @_data.chomp
447
455
  delim = " :: "
448
456
  _out "<br><center><table width=90% cellpadding=5>"
449
457
  lines = _body(true)
@@ -471,6 +479,11 @@ EOS
471
479
  _out "</table></center>"
472
480
  end
473
481
 
482
+ def image
483
+ name = @_args[0]
484
+ _out "<img src='#{name}'></img>"
485
+ end
486
+
474
487
  def br
475
488
  n = _args.first || "1"
476
489
  out = ""
@@ -19,6 +19,7 @@ module Livetext::UserAPI
19
19
  end
20
20
 
21
21
  def _args
22
+ @_args = _format(@_data).chomp.split
22
23
  if block_given?
23
24
  @_args.each {|arg| yield arg }
24
25
  else
@@ -26,6 +27,10 @@ module Livetext::UserAPI
26
27
  end
27
28
  end
28
29
 
30
+ def _vars
31
+ @_vars.dup
32
+ end
33
+
29
34
  def _optional_blank_line
30
35
  peek = peek_nextline
31
36
  return if peek.nil?
@@ -68,19 +73,20 @@ module Livetext::UserAPI
68
73
  end
69
74
 
70
75
  def _body(raw=false)
71
- lines = [] # @save_location = @sources.last
76
+ lines = []
72
77
  end_found = false
73
78
  loop do
74
79
  @line = nextline
75
80
  break if @line.nil?
76
81
  @line.chomp!
77
- end_found = _end?(@line)
78
- break if end_found
79
- next if _comment?(@line) # FIXME Will cause problem with $. ?
82
+ break if _end?(@line)
83
+ next if _comment?(@line)
80
84
  @line = _format(@line) unless raw
81
85
  lines << @line
82
86
  end
83
87
 
88
+ raise "Expected .end, found end of file" unless _end?(@line)
89
+
84
90
  _optional_blank_line
85
91
  if block_given?
86
92
  lines.each {|line| yield line } # FIXME what about $. ?
@@ -88,16 +94,13 @@ module Livetext::UserAPI
88
94
  lines
89
95
  end
90
96
  rescue => err
91
- str = "Fake error? 'Expecting .end, found end of file'\n"
92
- str << err.inspect + "\n"
97
+ str = err.inspect + "\n"
93
98
  str << err.backtrace.map {|x| " " + x }.join("\n")
94
- STDERR.puts str
95
- exit
96
- # _error!(str)
99
+ _error!(str)
97
100
  end
98
101
 
99
102
  def _body_text(raw=false)
100
- _body(Livetext::Sigil).join("\n")
103
+ _raw_body.join("\n")
101
104
  end
102
105
 
103
106
  def _raw_body!
@@ -12,6 +12,7 @@ def credit
12
12
  end
13
13
 
14
14
  def h1; _out "<h1>#{@_data}</h1>"; end
15
+ def h2; _out "<h2>#{@_data}</h2>"; end
15
16
  def h3; _out "<h3>#{@_data}</h3>"; end
16
17
 
17
18
  def list
@@ -42,7 +43,7 @@ def alpha_columns
42
43
  words << line.chomp
43
44
  end
44
45
  words.sort!
45
- _out "<table cellpadding=10>"
46
+ _out "<table cellpadding=2>"
46
47
  words.each_slice(n) do |w|
47
48
  items = w.map {|x| "<tt>#{x}</tt>" }
48
49
  _out "<tr><td width=5% valign=top></td><td>" + items.join("</td><td>") + "</td></tr>"
@@ -88,10 +89,11 @@ def chapter
88
89
  @sec = @sec2 = 0
89
90
  title = @_data.split(" ",2)[1]
90
91
  @toc << "<br><b>#@chapter</b> #{title}<br>"
91
- _next_output(_slug(title))
92
+ @_data = _slug(title)
93
+ next_output
92
94
  _out "<title>#{@chapter}. #{title}</title>"
93
95
  _out <<-HTML
94
- <h2>Chapter #{@chapter}</h1>
96
+ <h2>Chapter #{@chapter}</h2>
95
97
  <h1>#{title}</h1>
96
98
 
97
99
  HTML
@@ -103,10 +105,11 @@ def chapterN
103
105
  title = @_data # .split(" ",2)[1]
104
106
  _errout("Chapter #@chapter: #{title}")
105
107
  @toc << "<br><b>#@chapter</b> #{title}<br>"
106
- _next_output(_slug(title))
108
+ @_data = _slug(title)
109
+ next_output
107
110
  _out "<title>#{@chapter}. #{title}</title>"
108
111
  _out <<-HTML
109
- <h2>Chapter #{@chapter}</h1>
112
+ <h2>Chapter #{@chapter}</h2>
110
113
  <h1>#{title}</h1>
111
114
 
112
115
  HTML
@@ -116,10 +119,11 @@ def sec
116
119
  @sec += 1
117
120
  @sec2 = 0
118
121
  @section = "#@chapter.#@sec"
119
- # _errout("section #@section")
120
- @toc << "#{_nbsp(3)}<b>#@section</b> #@_data<br>"
121
- _next_output(_slug(@_data))
122
- _out "<h3>#@section #{@_data}</h3>\n"
122
+ title = @_data.dup
123
+ @toc << "#{_nbsp(3)}<b>#@section</b> #{title}<br>"
124
+ @_data = _slug(@_data)
125
+ next_output
126
+ _out "<h3>#@section #{title}</h3>\n"
123
127
  rescue => err
124
128
  STDERR.puts "#{err}\n#{err.backtrace}"
125
129
  exit
@@ -128,10 +132,33 @@ end
128
132
  def subsec
129
133
  @sec2 += 1
130
134
  @subsec = "#@chapter.#@sec.#@sec2"
131
- @toc << "#{_nbsp(6)}<b>#@subsec</b> #@_data<br>"
132
- # _errout("section #@subsec")
133
- _next_output(_slug(@_data))
134
- _out "<h3>#@subsec #{@_data}</h3>\n"
135
+ title = @_data.dup
136
+ @toc << "#{_nbsp(6)}<b>#@subsec</b> #{title}<br>"
137
+ @_data = _slug(@_data)
138
+ next_output
139
+ _out "<h3>#@subsec #{title}</h3>\n"
140
+ end
141
+
142
+ def definition_table
143
+ title = @_data
144
+ wide = "95"
145
+ delim = " :: "
146
+ _out "<br><center><table width=#{wide}% cellpadding=5>"
147
+ lines = _body(true)
148
+ lines.map! {|line| _format(line) }
149
+
150
+ lines.each do |line|
151
+ cells = line.split(delim)
152
+ _out "<tr>"
153
+ cells.each.with_index do |cell, i|
154
+ width = (i == 0) ? "width=15%" : ""
155
+ _out " <td #{width} valign=top>#{cell}</td>"
156
+ end
157
+ _out "</tr>"
158
+ end
159
+ _out "</table></center><br><br>"
160
+
161
+ _optional_blank_line
135
162
  end
136
163
 
137
164
  def table2
@@ -139,7 +166,7 @@ def table2
139
166
  wide = "90"
140
167
  extra = _args[2]
141
168
  delim = " :: "
142
- _out "<br><center><table border=1 width=#{wide}% cellpadding=5>"
169
+ _out "<br><center><table width=#{wide}% cellpadding=5>"
143
170
  lines = _body(true)
144
171
  lines.map! {|line| _format(line) }
145
172
 
@@ -192,7 +219,7 @@ def table
192
219
  @table_num += 1
193
220
  title = @_data
194
221
  delim = " :: "
195
- _out "<br><center><table border=1 width=90% cellpadding=5>"
222
+ _out "<br><center><table width=90% cellpadding=5>"
196
223
  lines = _body(true)
197
224
  maxw = nil
198
225
  lines.each do |line|
@@ -200,7 +227,7 @@ def table
200
227
  cells = line.split(delim)
201
228
  wide = cells.map {|x| x.length }
202
229
  maxw = [0] * cells.size
203
- maxw = maxw.map.with_index {|x, i| [x, wide[i]].max }
230
+ maxw = maxw.map.with_index {|x, i| [x, wide[i]+2].max }
204
231
  end
205
232
 
206
233
  sum = maxw.inject(0, :+)
@@ -246,12 +273,12 @@ end
246
273
  def missing
247
274
  @toc << "#{_nbsp(8)}<font color=red>TBD: #@_data</font><br>"
248
275
  stuff = @_data.empty? ? "" : ": #@_data"
249
- _print "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
276
+ _out "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
250
277
  end
251
278
 
252
279
  def TBC
253
280
  @toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
254
- _print "<br><font color=red><i>To be continued...</i></font><br>"
281
+ _out "<br><font color=red><i>To be continued...</i></font><br>"
255
282
  end
256
283
 
257
284
  def note
@@ -6,6 +6,7 @@ def epub!
6
6
  @cover = @_args[2]
7
7
  if ::File.directory?(src)
8
8
  files = ::Dir["#{src}/*"].grep /\.html$/
9
+ files = files.sort # why is this necessary now?
9
10
  cmd = "cat #{files.join(' ')} >TEMP.html"
10
11
  system(cmd)
11
12
  else
@@ -17,8 +18,9 @@ def epub!
17
18
  cmd << "--cover #@cover " if @cover
18
19
  system(cmd)
19
20
 
20
- str = `links -dump TEMP.html | wc -w`
21
+ system("links -dump TEMP.html >/tmp/links.out")
22
+ str = `wc -w /tmp/links.out`
21
23
  nw = str.split[0]
22
24
  puts "Approx words: #{nw}"
23
- ::FileUtils.rm("TEMP.html")
25
+ # ::FileUtils.rm("TEMP.html")
24
26
  end
@@ -1,4 +1,4 @@
1
- Here are examples of <b>boldface</b>
1
+ Here are examples of <b>boldface</b>
2
2
  and <i>italics</i>
3
3
  and <font size=+1><tt>code</tt></font>
4
4
  as well as <b>more complex</b> examples
@@ -0,0 +1 @@
1
+ Error: Illegal name 'to_s' (at source.lt3 line 5)
@@ -0,0 +1 @@
1
+ Error: Name 'foobar' is unknown
@@ -3,7 +3,7 @@
3
3
  cols = "1" if cols == ""
4
4
  cols = cols.to_i
5
5
  raise "Columns must be 1-5" unless cols.between?(1,5)
6
- text = _body_text
6
+ text = _body.join("\n")
7
7
  text.gsub!(/\n/, " ")
8
8
  words = text.split.sort
9
9
  words.each_slice(cols) do |row|
@@ -104,7 +104,7 @@ _This for example
104
104
 
105
105
  Line starts with double underscore
106
106
  __This, for example
107
- <i>This,</i> for example
107
+ <i>This</i>, for example
108
108
 
109
109
  Line has embedded underscores
110
110
  This has some_embedded_underscores
@@ -116,5 +116,5 @@ This has some_escaped_underscores
116
116
 
117
117
  Doubled underscore, midline
118
118
  This is __doubled, it seems
119
- This is <i>doubled,</i> it seems
119
+ This is <i>doubled</i>, it seems
120
120
 
@@ -71,12 +71,44 @@ class TestingLivetext < MiniTest::Test
71
71
  Dir.chdir(base) do
72
72
  src, out, exp = "source.lt3", "/tmp/#{base}--actual-output.txt", "expected-output.txt"
73
73
  err, erx = "/tmp/#{base}--actual-error.txt", "expected-error.txt"
74
+
75
+ # New features - match out/err by regex
76
+ expout_regex = "expected-out-line1match.txt"
77
+ experr_regex = "expected-err-line1match.txt"
78
+
74
79
  cmd = "livetext #{src} >#{out} 2>#{err}"
75
80
  system(cmd)
76
- output, expected, errors, errexp = File.read(out), File.read(exp), File.read(err), File.read(erx)
77
81
 
78
- out_ok = output == expected
79
- err_ok = errors == errexp
82
+ output = File.read(out)
83
+ errors = File.read(err)
84
+ rx_out = rx_err = nil
85
+
86
+ if File.exist?(expout_regex)
87
+ rx_out = /#{Regexp.escape(File.read(expout_regex).chomp)}/
88
+ expected = "(match test)"
89
+ else
90
+ expected = File.read(exp)
91
+ end
92
+
93
+ if File.exist?(experr_regex)
94
+ rx_err = /#{Regexp.escape(File.read(experr_regex).chomp)}/
95
+ errexp = "(match test)"
96
+ else
97
+ errexp = File.read(erx)
98
+ end
99
+
100
+ if rx_out
101
+ out_ok = output =~ rx_out
102
+ else
103
+ out_ok = output == expected
104
+ end
105
+
106
+ if rx_err
107
+ err_ok = errors =~ rx_err
108
+ else
109
+ err_ok = errors == errexp
110
+ end
111
+
80
112
  nout = output.split("\n").size
81
113
  nexp = expected.split("\n").size
82
114
  bad_out = "--- Expected (#{nexp} lines): \n#{green(expected)}\n--- Output (#{nout} lines): \n#{red(output)}\n"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livetext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.01
4
+ version: 0.9.06
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-31 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -57,9 +57,11 @@ files:
57
57
  - test/data/error_inc_line_num/expected-output.txt
58
58
  - test/data/error_inc_line_num/file2.lt3
59
59
  - test/data/error_inc_line_num/source.lt3
60
+ - test/data/error_invalid_name/expected-err-line1match.txt
60
61
  - test/data/error_invalid_name/expected-error.txt
61
62
  - test/data/error_invalid_name/expected-output.txt
62
63
  - test/data/error_invalid_name/source.lt3
64
+ - test/data/error_line_num/expected-err-line1match.txt
63
65
  - test/data/error_line_num/expected-error.txt
64
66
  - test/data/error_line_num/expected-output.txt
65
67
  - test/data/error_line_num/source.lt3
@@ -137,7 +139,7 @@ homepage: https://github.com/Hal9000/livetext
137
139
  licenses:
138
140
  - Ruby
139
141
  metadata: {}
140
- post_install_message:
142
+ post_install_message:
141
143
  rdoc_options: []
142
144
  require_paths:
143
145
  - lib
@@ -152,8 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
154
  - !ruby/object:Gem::Version
153
155
  version: '0'
154
156
  requirements: []
155
- rubygems_version: 3.0.4
156
- signing_key:
157
+ rubygems_version: 3.1.2
158
+ signing_key:
157
159
  specification_version: 4
158
160
  summary: A smart processor for text
159
161
  test_files: []