livetext 0.8.99 → 0.9.01
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/formatline.rb +54 -12
- data/lib/livetext.rb +3 -2
- data/lib/standard.rb +9 -1
- data/test/data/lines.txt +20 -0
- data/test/extratests.txt +20 -0
- data/test/formatting.rb +110 -0
- data/test/testlines.rb +27 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b5dbf29a35e17c163982a4c2d5355949a72be58c662e75cf1f1d59bef1894dd
|
4
|
+
data.tar.gz: 882f20c410919dc4aa5f5d4e4277cdff88dca8efce5b1d0d96d1228767dd80c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58671323ec46267e898c2999e86fc3f5e1379eae4adca5df0adf7be90d0d8b35a9aefaa9f4bf778f67963624fa764ba8087349500e5c4c280c90297c9fc07789
|
7
|
+
data.tar.gz: 3ddfa97b6ef5a86c311baf9df53851bf39f01780fbec54a34de64bd9b4970aa8e055b77147891927e1ed378b87a050a414d11a51d942010ba0d774a99714e3bb
|
data/lib/formatline.rb
CHANGED
@@ -106,7 +106,6 @@ class FormatLine
|
|
106
106
|
when :str
|
107
107
|
@out << val unless val == "\n" # BUG
|
108
108
|
when :var
|
109
|
-
# STDERR.puts "=== lt: sym = #{sym} val = #{val} sub = #{varsub(val).inspect} #{Livetext::Vars[sym].inspect}"
|
110
109
|
@out << varsub(val)
|
111
110
|
when :func
|
112
111
|
param = nil
|
@@ -133,6 +132,7 @@ class FormatLine
|
|
133
132
|
end
|
134
133
|
|
135
134
|
def prev
|
135
|
+
return nil if @i <= 0
|
136
136
|
@line[@i-1]
|
137
137
|
end
|
138
138
|
|
@@ -144,6 +144,10 @@ class FormatLine
|
|
144
144
|
@line[@i+=1]
|
145
145
|
end
|
146
146
|
|
147
|
+
def ungrab
|
148
|
+
@line[@i-=1]
|
149
|
+
end
|
150
|
+
|
147
151
|
def grab_colon_param
|
148
152
|
grab # grab :
|
149
153
|
param = ""
|
@@ -248,7 +252,6 @@ class FormatLine
|
|
248
252
|
case next!
|
249
253
|
when ":"; param = grab_colon_param; add_token(:colon, param)
|
250
254
|
when "["; param = grab_func_param; add_token(:brackets, param)
|
251
|
-
else # do nothing
|
252
255
|
end
|
253
256
|
else
|
254
257
|
grab; add_token :str, "$$" + curr; return
|
@@ -266,6 +269,7 @@ class FormatLine
|
|
266
269
|
# add char # ??? add_token "*", :string
|
267
270
|
return
|
268
271
|
end
|
272
|
+
|
269
273
|
grab
|
270
274
|
case curr
|
271
275
|
when Space
|
@@ -278,25 +282,24 @@ class FormatLine
|
|
278
282
|
when char; double_marker(char)
|
279
283
|
when LBrack; long_marker(char)
|
280
284
|
else
|
281
|
-
|
282
|
-
str
|
285
|
+
str = curr + collect!(sym, Blank)
|
286
|
+
add str
|
283
287
|
add_token sym, str
|
284
|
-
|
288
|
+
grab
|
285
289
|
end
|
286
290
|
end
|
287
291
|
|
288
292
|
def double_marker(char)
|
289
293
|
sym = Syms[char]
|
290
|
-
|
291
|
-
kind = sym # "string_#{char}".to_sym
|
294
|
+
kind = sym
|
292
295
|
case next! # first char after **
|
293
296
|
when Space, LF, nil
|
294
297
|
pre, post = SimpleFormats[sym]
|
295
298
|
add_token kind
|
296
299
|
else
|
297
300
|
str = collect!(sym, Punc)
|
298
|
-
grab unless next!.nil?
|
299
301
|
add_token kind, str
|
302
|
+
grab
|
300
303
|
end
|
301
304
|
end
|
302
305
|
|
@@ -308,21 +311,60 @@ class FormatLine
|
|
308
311
|
add_token kind, arg
|
309
312
|
end
|
310
313
|
|
311
|
-
def
|
314
|
+
def collect_bracketed(sym, terminators)
|
312
315
|
str = Null.dup # next is not " ","*","["
|
313
|
-
grab
|
316
|
+
grab # ZZZ
|
314
317
|
loop do
|
315
318
|
if curr == Escape
|
316
319
|
str << grab # ch = escaped char
|
317
320
|
grab
|
318
321
|
next
|
319
322
|
end
|
320
|
-
|
323
|
+
if terminate?(terminators, curr)
|
324
|
+
break
|
325
|
+
end
|
326
|
+
# STDERR.puts "#{curr.inspect} is not a terminator"
|
321
327
|
str << curr # not a terminator
|
322
328
|
grab
|
329
|
+
# STDERR.puts "After grab, curr is #{curr.inspect}"
|
330
|
+
end
|
331
|
+
|
332
|
+
if curr == "]" # skip right bracket
|
333
|
+
grab
|
323
334
|
end
|
324
|
-
grab if param && curr == "]" # skip right bracket
|
325
335
|
add str
|
336
|
+
str
|
337
|
+
rescue => err
|
338
|
+
STDERR.puts "ERR = #{err}\n#{err.backtrace}"
|
339
|
+
STDERR.puts "=== str = #{str.inspect}"
|
340
|
+
end
|
341
|
+
|
342
|
+
def escaped
|
343
|
+
ch = grab
|
344
|
+
grab
|
345
|
+
ch
|
346
|
+
end
|
347
|
+
|
348
|
+
def collect!(sym, terminators, bracketed=nil)
|
349
|
+
return collect_bracketed(sym, terminators) if bracketed
|
350
|
+
|
351
|
+
str = Null.dup # next is not " ","*","["
|
352
|
+
grab # ZZZ
|
353
|
+
loop do
|
354
|
+
case
|
355
|
+
when curr == Escape
|
356
|
+
str << escaped
|
357
|
+
next
|
358
|
+
when terminate?(terminators, curr)
|
359
|
+
break
|
360
|
+
else
|
361
|
+
str << curr # not a terminator
|
362
|
+
end
|
363
|
+
grab
|
364
|
+
end
|
365
|
+
ungrab
|
366
|
+
add str
|
367
|
+
str
|
326
368
|
rescue => err
|
327
369
|
STDERR.puts "ERR = #{err}\n#{err.backtrace}"
|
328
370
|
STDERR.puts "=== str = #{str.inspect}"
|
data/lib/livetext.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Livetext
|
2
|
-
VERSION = "0.
|
2
|
+
VERSION = "0.9.01"
|
3
3
|
Path = File.expand_path(File.join(File.dirname(__FILE__)))
|
4
4
|
end
|
5
5
|
|
@@ -109,7 +109,8 @@ end
|
|
109
109
|
|
110
110
|
def _setfile(file)
|
111
111
|
_setvar(:File, file)
|
112
|
-
|
112
|
+
dir = File.dirname(File.expand_path(file))
|
113
|
+
_setvar(:FileDir, dir)
|
113
114
|
end
|
114
115
|
|
115
116
|
def _setfile!(file)
|
data/lib/standard.rb
CHANGED
@@ -197,7 +197,15 @@ EOS
|
|
197
197
|
|
198
198
|
def variables
|
199
199
|
prefix = _args[0]
|
200
|
-
|
200
|
+
file = _args[1]
|
201
|
+
prefix = nil if prefix == "-" # FIXME dumb hack
|
202
|
+
if file
|
203
|
+
here = ::Livetext::Vars[:FileDir] + "/"
|
204
|
+
lines = File.readlines(here + file)
|
205
|
+
else
|
206
|
+
lines = _body
|
207
|
+
end
|
208
|
+
lines.each do |line|
|
201
209
|
next if line.strip.empty?
|
202
210
|
var, val = line.split(" ", 2)
|
203
211
|
val = FormatLine.var_func_parse(val)
|
data/test/data/lines.txt
CHANGED
@@ -98,3 +98,23 @@ Escape brackets inside ~
|
|
98
98
|
There are brackets ~[\[\]] here
|
99
99
|
There are brackets <strike>[]</strike> here
|
100
100
|
|
101
|
+
Line starts with underscore
|
102
|
+
_This for example
|
103
|
+
<i>This</i> for example
|
104
|
+
|
105
|
+
Line starts with double underscore
|
106
|
+
__This, for example
|
107
|
+
<i>This,</i> for example
|
108
|
+
|
109
|
+
Line has embedded underscores
|
110
|
+
This has some_embedded_underscores
|
111
|
+
This has some_embedded_underscores
|
112
|
+
|
113
|
+
Line has escaped underscores
|
114
|
+
This has some\_escaped\_underscores
|
115
|
+
This has some_escaped_underscores
|
116
|
+
|
117
|
+
Doubled underscore, midline
|
118
|
+
This is __doubled, it seems
|
119
|
+
This is <i>doubled,</i> it seems
|
120
|
+
|
data/test/extratests.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Line starts with underscore
|
2
|
+
_This for example
|
3
|
+
<i>This</i> for example
|
4
|
+
|
5
|
+
Line starts with double underscore
|
6
|
+
__This, for example
|
7
|
+
<i>This,</i> for example
|
8
|
+
|
9
|
+
Line has embedded underscores
|
10
|
+
This has some_embedded_underscores
|
11
|
+
This has some_embedded_underscores
|
12
|
+
|
13
|
+
Doubled underscore, midline
|
14
|
+
This is __doubled, it seems
|
15
|
+
This is <i>doubled,</i> it seems
|
16
|
+
|
17
|
+
Line has escaped underscores
|
18
|
+
This has some\_escaped\_underscores
|
19
|
+
This has some_escaped_underscores
|
20
|
+
|
data/test/formatting.rb
ADDED
@@ -0,0 +1,110 @@
|
|
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"
|
9
|
+
|
10
|
+
require 'livetext'
|
11
|
+
|
12
|
+
class TestingLivetext < MiniTest::Test
|
13
|
+
|
14
|
+
TTY = File.open("/dev/tty","w")
|
15
|
+
|
16
|
+
dir = ARGV.first == "cmdline" ? "../" : ""
|
17
|
+
Data = "#{dir}test/data"
|
18
|
+
|
19
|
+
TestLines = []
|
20
|
+
|
21
|
+
Dir.chdir `livetext --path`.chomp if ARGV.first == "cmdline"
|
22
|
+
|
23
|
+
Dir.chdir(Data)
|
24
|
+
|
25
|
+
f = File.open("lines.txt")
|
26
|
+
loop do
|
27
|
+
item = []
|
28
|
+
4.times { item << f.gets.chomp }
|
29
|
+
raise "Oops? #{item.inspect}" unless item.last == ""
|
30
|
+
TestLines << item
|
31
|
+
break if f.eof?
|
32
|
+
end
|
33
|
+
|
34
|
+
if File.size("subset.txt") # == 0
|
35
|
+
puts "Defining via TestLines"
|
36
|
+
TestLines.each.with_index do |item, i|
|
37
|
+
msg, src, exp, blank = *item
|
38
|
+
define_method("test_formatting_#{i}") do
|
39
|
+
actual = FormatLine.parse!(src)
|
40
|
+
if exp[0] == "/" # regex!
|
41
|
+
exp = Regexp.compile(exp[1..-2]) # skip slashes
|
42
|
+
assert_match(exp, actual, msg)
|
43
|
+
else
|
44
|
+
assert_equal(exp, actual, msg)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
TestDirs = Dir.entries(".").reject {|f| ! File.directory?(f) } - %w[. ..]
|
51
|
+
selected = File.readlines("subset.txt").map(&:chomp)
|
52
|
+
Subset = selected.empty? ? TestDirs : selected
|
53
|
+
|
54
|
+
# puts "Subset = #{Subset.inspect}"
|
55
|
+
|
56
|
+
Subset.each do |tdir|
|
57
|
+
define_method("test_#{tdir}") do
|
58
|
+
external_files(tdir)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def green(str)
|
63
|
+
"[32m" + str + "[0m"
|
64
|
+
end
|
65
|
+
|
66
|
+
def red(str)
|
67
|
+
"[31m" + str + "[0m"
|
68
|
+
end
|
69
|
+
|
70
|
+
def external_files(base)
|
71
|
+
Dir.chdir(base) do
|
72
|
+
src, out, exp = "source.lt3", "/tmp/#{base}--actual-output.txt", "expected-output.txt"
|
73
|
+
err, erx = "/tmp/#{base}--actual-error.txt", "expected-error.txt"
|
74
|
+
cmd = "livetext #{src} >#{out} 2>#{err}"
|
75
|
+
system(cmd)
|
76
|
+
output, expected, errors, errexp = File.read(out), File.read(exp), File.read(err), File.read(erx)
|
77
|
+
|
78
|
+
out_ok = output == expected
|
79
|
+
err_ok = errors == errexp
|
80
|
+
nout = output.split("\n").size
|
81
|
+
nexp = expected.split("\n").size
|
82
|
+
bad_out = "--- Expected (#{nexp} lines): \n#{green(expected)}\n--- Output (#{nout} lines): \n#{red(output)}\n"
|
83
|
+
bad_err = "--- Error Expected: \n#{green(errexp)}\n--- Error Output: \n#{red(errors)}\n"
|
84
|
+
|
85
|
+
assert(out_ok, bad_out)
|
86
|
+
assert(err_ok, bad_err)
|
87
|
+
# only on success
|
88
|
+
system("rm -f #{out} #{err}") if out_ok && err_ok
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
=begin
|
96
|
+
|
97
|
+
You can add any ordinary test method above. But so far, all these tests simply
|
98
|
+
call external_files.
|
99
|
+
|
100
|
+
The external_files method works this way:
|
101
|
+
- If the test (caller) method is test_my_silly_feature, then we will
|
102
|
+
look for a directory called data/my_silly_feature
|
103
|
+
- In here, there must be a source.lt3, expected-output.txt, and expected-error.txt
|
104
|
+
- Technically, any of these can be empty
|
105
|
+
- We run livetext on the source and compare actual vs expected (stdout, stderr)
|
106
|
+
- The "real" output gets checked first
|
107
|
+
- Of course, both must compare correctly for the test to pass
|
108
|
+
|
109
|
+
=end
|
110
|
+
|
data/test/testlines.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'livetext'
|
2
|
+
require 'formatline'
|
3
|
+
|
4
|
+
def red(str)
|
5
|
+
"[31m" + str + "[0m"
|
6
|
+
end
|
7
|
+
|
8
|
+
input = ARGV.first || "test/data/lines.txt"
|
9
|
+
data = File.readlines(input)
|
10
|
+
|
11
|
+
data.each_slice(4) do |lines|
|
12
|
+
title, input, expected, blank = *lines
|
13
|
+
input.chomp!
|
14
|
+
expected.chomp!
|
15
|
+
expected = eval(expected) if expected[0] == "/"
|
16
|
+
|
17
|
+
puts "-----------------------------"
|
18
|
+
print "Test: #{title}"
|
19
|
+
|
20
|
+
actual = FormatLine.parse!(input)
|
21
|
+
next if expected === actual
|
22
|
+
|
23
|
+
puts "Input: #{input}"
|
24
|
+
puts " #{red('FAIL Expected: ')} #{expected.inspect}"
|
25
|
+
puts " #{red(' Actual : ')} #{actual.inspect}"
|
26
|
+
puts
|
27
|
+
end
|
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.
|
4
|
+
version: 0.9.01
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A smart text processor extensible in Ruby
|
14
14
|
email: rubyhacker@gmail.com
|
@@ -127,9 +127,12 @@ files:
|
|
127
127
|
- test/data/table_with_heredocs/expected-error.txt
|
128
128
|
- test/data/table_with_heredocs/expected-output.txt
|
129
129
|
- test/data/table_with_heredocs/source.lt3
|
130
|
+
- test/extratests.txt
|
131
|
+
- test/formatting.rb
|
130
132
|
- test/newtest
|
131
133
|
- test/sdtest
|
132
134
|
- test/test.rb
|
135
|
+
- test/testlines.rb
|
133
136
|
homepage: https://github.com/Hal9000/livetext
|
134
137
|
licenses:
|
135
138
|
- Ruby
|