livetext 0.9.02 → 0.9.03

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: d9e45d3b0ea8fb06374c84d7e830ca7537fc553decbdbe034171dd7f9395671a
4
- data.tar.gz: 1943173d9090705f70b447e4a283d73cb9bbd86c7458a6e744431c79e3ccea21
3
+ metadata.gz: 868972bd6d69160614982ec1673ffe4b1e6b52cc0c37b3f3665b4cd63a9465c4
4
+ data.tar.gz: bb03f156bed4713bfa30804c6bb4fb5057a22db84523774a90649e62e22ac8f6
5
5
  SHA512:
6
- metadata.gz: 78452f768fe1a334af4f7b2f5ac437bcda06d27a7e4ae3bf360ad92db61632a0bdb67c1a8e5fcf7ba8f18e4c3941181c084fb2a88b0ece4eae7b3eb31e4bddb6
7
- data.tar.gz: 4fca6756c94dcceb8a7f5224d71aca40e3a47cea1bfc1d660e62409ed532b1bed1123528615e32ca01715f0a6a8d2e7efb07b9a22ed2c7f2c0362829c7b2639f
6
+ metadata.gz: f44235d6cd9649515ae9b6fed910b233f90c37f92c54bec3183f718b83e918ef95192aa8e8c08ec8b2eca16edbcbcc519a002214efeff4d042d7056f8a3a3a78
7
+ data.tar.gz: 148fa1af92fa0320bbbe3db92fb89cd24d4ebc0620d65343c1c0120c1a61c5612df7fe27bf2d6b0cf805189e00a566487cda712a4e1e09be3ce1f4e9ea035999
@@ -1,5 +1,5 @@
1
1
  class Livetext
2
- VERSION = "0.9.02"
2
+ VERSION = "0.9.03"
3
3
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
4
4
  end
5
5
 
@@ -271,7 +271,7 @@ line = line.sub(/# .*$/, "")
271
271
  if @main.respond_to?(name)
272
272
  result = @main.send(name)
273
273
  else
274
- @main._error! "Name '#{name}' is unknown; version = #{Livetext::VERSION}"
274
+ @main._error! "Name '#{name}' is unknown"
275
275
  return
276
276
  end
277
277
  result
@@ -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
@@ -50,22 +50,22 @@ EOS
50
50
  end
51
51
 
52
52
  def shell!
53
- cmd = @_data
53
+ cmd = @_data.chomp
54
54
  system(cmd)
55
55
  end
56
56
 
57
57
  def errout
58
- TTY.puts @_data
58
+ TTY.puts @_data.chomp
59
59
  end
60
60
 
61
61
  def say
62
- str = _format(@_data)
62
+ str = _format(@_data.chomp)
63
63
  TTY.puts str
64
64
  _optional_blank_line
65
65
  end
66
66
 
67
67
  def banner
68
- str = _format(@_data)
68
+ str = _format(@_data.chomp)
69
69
  n = str.length - 1
70
70
  puts "-"*n
71
71
  puts str
@@ -94,7 +94,7 @@ EOS
94
94
  name = @_args[0]
95
95
  str = "def #{name}\n"
96
96
  raise "Illegal name '#{name}'" if _disallowed?(name)
97
- str += _body_text(true)
97
+ str += _body(true).join("\n")
98
98
  str += "\nend\n"
99
99
  eval str
100
100
  rescue => err
@@ -179,7 +179,7 @@ EOS
179
179
  end
180
180
 
181
181
  def set_NEW
182
- line = _data.dup # dup needed?
182
+ line = _data.chomp
183
183
  e = line.each_char # enum
184
184
  loop do
185
185
  c = e.next
@@ -216,12 +216,12 @@ EOS
216
216
  end
217
217
 
218
218
  def reval
219
- eval _data
219
+ eval _data.chomp
220
220
  end
221
221
 
222
222
  def heredoc
223
223
  var = @_args[0]
224
- str = _body_text
224
+ str = _body.join("\n")
225
225
  s2 = ""
226
226
  str.each_line do |s|
227
227
  str = FormatLine.var_func_parse(s.chomp)
@@ -347,7 +347,7 @@ EOS
347
347
  end
348
348
 
349
349
  def r
350
- _out @_data # No processing at all
350
+ _out @_data.chomp # No processing at all
351
351
  end
352
352
 
353
353
  def raw
@@ -393,7 +393,7 @@ EOS
393
393
 
394
394
  def heading
395
395
  _print "<center><font size=+1><b>"
396
- _print @_data
396
+ _print @_data.chomp
397
397
  _print "</b></font></center>"
398
398
  end
399
399
 
@@ -444,7 +444,7 @@ EOS
444
444
  end
445
445
 
446
446
  def xtable # Borrowed from bookish - FIXME
447
- title = @_data
447
+ title = @_data.chomp
448
448
  delim = " :: "
449
449
  _out "<br><center><table width=90% cellpadding=5>"
450
450
  lines = _body(true)
@@ -19,6 +19,7 @@ module Livetext::UserAPI
19
19
  end
20
20
 
21
21
  def _args
22
+ @_args = @_data.chomp.split
22
23
  if block_given?
23
24
  @_args.each {|arg| yield arg }
24
25
  else
@@ -80,6 +81,8 @@ module Livetext::UserAPI
80
81
  lines << @line
81
82
  end
82
83
 
84
+ raise "Expected .end, found end of file" unless _end?(@line)
85
+
83
86
  _optional_blank_line
84
87
  if block_given?
85
88
  lines.each {|line| yield line } # FIXME what about $. ?
@@ -87,14 +90,13 @@ module Livetext::UserAPI
87
90
  lines
88
91
  end
89
92
  rescue => err
90
- str = "Fake error? 'Expecting .end, found end of file'\n"
91
93
  str << err.inspect + "\n"
92
94
  str << err.backtrace.map {|x| " " + x }.join("\n")
93
95
  _error!(str)
94
96
  end
95
97
 
96
98
  def _body_text(raw=false)
97
- _body.join("\n")
99
+ _raw_body.join("\n")
98
100
  end
99
101
 
100
102
  def _raw_body!
@@ -88,7 +88,8 @@ def chapter
88
88
  @sec = @sec2 = 0
89
89
  title = @_data.split(" ",2)[1]
90
90
  @toc << "<br><b>#@chapter</b> #{title}<br>"
91
- _next_output(_slug(title))
91
+ @_data = _slug(title)
92
+ next_output
92
93
  _out "<title>#{@chapter}. #{title}</title>"
93
94
  _out <<-HTML
94
95
  <h2>Chapter #{@chapter}</h1>
@@ -103,7 +104,8 @@ def chapterN
103
104
  title = @_data # .split(" ",2)[1]
104
105
  _errout("Chapter #@chapter: #{title}")
105
106
  @toc << "<br><b>#@chapter</b> #{title}<br>"
106
- _next_output(_slug(title))
107
+ @_data = _slug(title)
108
+ next_output
107
109
  _out "<title>#{@chapter}. #{title}</title>"
108
110
  _out <<-HTML
109
111
  <h2>Chapter #{@chapter}</h1>
@@ -118,7 +120,8 @@ def sec
118
120
  @section = "#@chapter.#@sec"
119
121
  # _errout("section #@section")
120
122
  @toc << "#{_nbsp(3)}<b>#@section</b> #@_data<br>"
121
- _next_output(_slug(@_data))
123
+ @_data = _slug(@_data)
124
+ next_output
122
125
  _out "<h3>#@section #{@_data}</h3>\n"
123
126
  rescue => err
124
127
  STDERR.puts "#{err}\n#{err.backtrace}"
@@ -130,7 +133,8 @@ def subsec
130
133
  @subsec = "#@chapter.#@sec.#@sec2"
131
134
  @toc << "#{_nbsp(6)}<b>#@subsec</b> #@_data<br>"
132
135
  # _errout("section #@subsec")
133
- _next_output(_slug(@_data))
136
+ @_data = _slug(@_data)
137
+ next_output
134
138
  _out "<h3>#@subsec #{@_data}</h3>\n"
135
139
  end
136
140
 
@@ -246,12 +250,12 @@ end
246
250
  def missing
247
251
  @toc << "#{_nbsp(8)}<font color=red>TBD: #@_data</font><br>"
248
252
  stuff = @_data.empty? ? "" : ": #@_data"
249
- _print "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
253
+ _out "<br><font color=red><i>[Material missing#{stuff}]</i></font><br>\n "
250
254
  end
251
255
 
252
256
  def TBC
253
257
  @toc << "#{_nbsp(8)}<font color=red>To be continued...</font><br>"
254
- _print "<br><font color=red><i>To be continued...</i></font><br>"
258
+ _out "<br><font color=red><i>To be continued...</i></font><br>"
255
259
  end
256
260
 
257
261
  def note
@@ -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.02
4
+ version: 0.9.03
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2020-01-28 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