livetext 0.9.14 → 0.9.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.lt3 +2 -2
- data/imports/bookish.rb +288 -0
- data/imports/calibre.rb +28 -0
- data/imports/livemagick.rb +133 -0
- data/imports/markdown.rb +44 -0
- data/imports/markdown_importable.rb +46 -0
- data/imports/pyggish.rb +204 -0
- data/imports/tutorial.rb +95 -0
- data/lib/cmdargs.rb +93 -0
- data/lib/formatline.rb +56 -83
- data/lib/handler/icanhaz.rb +35 -0
- data/lib/handler.rb +1 -0
- data/lib/helpers.rb +173 -4
- data/lib/livetext.rb +16 -141
- data/lib/parser/file.rb +8 -0
- data/lib/parser/import.rb +1 -3
- data/lib/parser/mixin.rb +22 -24
- data/lib/parser/set.rb +35 -26
- data/lib/parser/string.rb +19 -4
- data/lib/processor.rb +1 -4
- data/lib/standard.rb +68 -97
- data/lib/userapi.rb +1 -0
- data/livetext.gemspec +2 -1
- data/plugin/bookish.rb +26 -22
- data/plugin/calibre.rb +1 -1
- data/plugin/livemagick.rb +10 -10
- data/plugin/markdown.rb +13 -11
- data/plugin/pyggish.rb +94 -84
- data/plugin/tutorial.rb +10 -5
- data/test/all.rb +0 -1
- data/test/snapshots/OMIT.txt +9 -8
- data/test/snapshots/clusion.txt +84 -0
- data/test/snapshots/error_inc_line_num/match-error.txt +1 -1
- data/test/snapshots/error_invalid_name/match-error.txt +1 -1
- data/test/snapshots/error_line_num/match-error.txt +1 -1
- data/test/snapshots/error_mismatched_end/match-error.txt +1 -1
- data/test/snapshots/error_missing_end/match-error.txt +1 -1
- data/test/snapshots/error_no_such_copy/match-error.txt +1 -1
- data/test/snapshots/error_no_such_copy/source.lt3 +0 -1
- data/test/snapshots/error_no_such_inc/match-error.txt +1 -1
- data/test/snapshots/icanhaz/expected-output.txt +5 -0
- data/test/snapshots/icanhaz/match-error.txt +1 -0
- data/test/snapshots/icanhaz/simple_import.rb +5 -0
- data/test/snapshots/icanhaz/source.lt3 +10 -0
- data/test/snapshots/icanhaz2/expected-error.txt +0 -0
- data/test/snapshots/icanhaz2/expected-output.txt +6 -0
- data/test/snapshots/icanhaz2/simple_canhaz.rb +5 -0
- data/test/snapshots/icanhaz2/source.lt3 +6 -0
- data/test/snapshots/simple_import/expected-error.txt +0 -0
- data/test/snapshots/simple_import/expected-output.txt +7 -0
- data/test/snapshots/simple_import/simple_import.rb +5 -0
- data/test/snapshots/simple_import/source.lt3 +7 -0
- data/test/snapshots/simple_include/source.lt3 +0 -1
- data/test/snapshots.rb +85 -37
- data/test/unit/all.rb +1 -0
- data/test/unit/formatline.rb +650 -0
- data/test/unit/parser/importable.rb +1 -1
- data/test/unit/parser/mixin.rb +1 -1
- data/test/unit/parser/set.rb +19 -12
- data/test/unit/parser/string.rb +14 -14
- metadata +27 -5
- data/test/formatting-tests.rb +0 -35
- data/test/formatting.rb +0 -103
- data/test/snapshots/formatting-tests.txt +0 -124
data/plugin/livemagick.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'rmagick'
|
2
2
|
include ::Magick
|
3
3
|
|
4
|
-
def image
|
4
|
+
def image(args = nil, body = nil)
|
5
5
|
xx, yy, bg = _args
|
6
6
|
xx, yy = xx.to_i, yy.to_i
|
7
7
|
@image = Image.new(xx,yy) { self.background_color = bg }
|
8
8
|
_optional_blank_line
|
9
9
|
end
|
10
10
|
|
11
|
-
def canvas
|
11
|
+
def canvas(args = nil, body = nil)
|
12
12
|
color, width, opacity = _args
|
13
13
|
opacity, width = opacity.to_i, width.to_i
|
14
14
|
@canvas = Draw.new
|
@@ -18,7 +18,7 @@ def canvas
|
|
18
18
|
_optional_blank_line
|
19
19
|
end
|
20
20
|
|
21
|
-
def rectangle
|
21
|
+
def rectangle(args = nil, body = nil)
|
22
22
|
xy, wxh, stroke_color, stroke_width = _args
|
23
23
|
x, y = xy.split(",").map(&:to_i)
|
24
24
|
width, height = wxh.split("x").map(&:to_i)
|
@@ -29,14 +29,14 @@ def rectangle
|
|
29
29
|
@canvas.rectangle(x, y, x+width, y+height)
|
30
30
|
end
|
31
31
|
|
32
|
-
def pen
|
32
|
+
def pen(args = nil, body = nil)
|
33
33
|
@fill, @stroke = _args
|
34
34
|
@stroke = "black" if @stroke.nil? || @stroke.empty?
|
35
35
|
_debug "pen: fill=#@fill stroke=#@stroke"
|
36
36
|
_optional_blank_line
|
37
37
|
end
|
38
38
|
|
39
|
-
def font
|
39
|
+
def font(args = nil, body = nil)
|
40
40
|
size, font = _args
|
41
41
|
font = "Helvetica" if font.nil? || font.empty?
|
42
42
|
size = "32" if size.nil? || size.empty?
|
@@ -59,14 +59,14 @@ def _text(xy, wxh, str, weight, gravity)
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def text
|
62
|
+
def text(args = nil, body = nil)
|
63
63
|
xy, wxh, str = _data.split
|
64
64
|
weight, gravity = BoldWeight, CenterGravity
|
65
65
|
_text(xy, wxh, str, weight, gravity)
|
66
66
|
_optional_blank_line
|
67
67
|
end
|
68
68
|
|
69
|
-
def text!
|
69
|
+
def text!(args = nil, body = nil)
|
70
70
|
xy, wxh = _data.split
|
71
71
|
str = _body_text # .join
|
72
72
|
weight, gravity = BoldWeight, CenterGravity
|
@@ -74,17 +74,17 @@ def text!
|
|
74
74
|
_optional_blank_line
|
75
75
|
end
|
76
76
|
|
77
|
-
def draw
|
77
|
+
def draw(args = nil, body = nil)
|
78
78
|
@canvas.draw(@image)
|
79
79
|
_optional_blank_line
|
80
80
|
end
|
81
81
|
|
82
|
-
def save
|
82
|
+
def save(args = nil, body = nil)
|
83
83
|
@image.write(_args.first)
|
84
84
|
_optional_blank_line
|
85
85
|
end
|
86
86
|
|
87
|
-
def save!
|
87
|
+
def save!(args = nil, body = nil)
|
88
88
|
save
|
89
89
|
system("open #{_args.first}")
|
90
90
|
_optional_blank_line
|
data/plugin/markdown.rb
CHANGED
@@ -1,35 +1,37 @@
|
|
1
1
|
# This file is intended to be used via a Livetext .mixin
|
2
2
|
# or the equivalent.
|
3
3
|
|
4
|
+
SimpleFormats = {}
|
4
5
|
SimpleFormats[:b] = %w[* *]
|
5
6
|
SimpleFormats[:i] = %w[_ _]
|
6
7
|
SimpleFormats[:t] = %w[` `]
|
7
8
|
SimpleFormats[:s] = %w[<strike> </strike>]
|
8
9
|
|
9
|
-
def h1; _out "# #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end # atx style for now
|
10
|
-
def h2; _out "## #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
11
|
-
def h3; _out "### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
12
|
-
def h4; _out "#### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
13
|
-
def h5; _out "##### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
14
|
-
def h6; _out "###### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
15
10
|
|
16
|
-
def
|
11
|
+
def h1(args = nil, body = nil); _out "# #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end # atx style for now
|
12
|
+
def h2(args = nil, body = nil); _out "## #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
13
|
+
def h3(args = nil, body = nil); _out "### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
14
|
+
def h4(args = nil, body = nil); _out "#### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
15
|
+
def h5(args = nil, body = nil); _out "##### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
16
|
+
def h6(args = nil, body = nil); _out "###### #{FormatLine.var_func_parse(@_data)}"; _optional_blank_line end
|
17
|
+
|
18
|
+
def title(args = nil, body = nil)
|
17
19
|
h1
|
18
20
|
end
|
19
21
|
|
20
|
-
def section
|
22
|
+
def section(args = nil, body = nil)
|
21
23
|
h3
|
22
24
|
end
|
23
25
|
|
24
|
-
def bq # block quote
|
26
|
+
def bq(args = nil, body = nil) # block quote
|
25
27
|
_body {|line| _out "> #{line}" }
|
26
28
|
end
|
27
29
|
|
28
|
-
def list
|
30
|
+
def list(args = nil, body = nil)
|
29
31
|
_body {|line| _out " * #{line}" }
|
30
32
|
end
|
31
33
|
|
32
|
-
def olist # Doesn't handle paragraphs yet
|
34
|
+
def olist(args = nil, body = nil) # Doesn't handle paragraphs yet
|
33
35
|
n = 0
|
34
36
|
_body do |line|
|
35
37
|
n += 1
|
data/plugin/pyggish.rb
CHANGED
@@ -1,58 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
module PygmentFix # Remove CSS for Jutoh
|
4
|
-
Styles = {
|
5
|
-
:c => "#408080-i", # Comment
|
6
|
-
:k => "#008000-b", # Keyword
|
7
|
-
:o => "#666666", # Operator
|
8
|
-
:cm => "#408080-i", # Comment.Multiline
|
9
|
-
:cp => "#BC7A00", # Comment.Preproc
|
10
|
-
:c1 => "#408080-i", # Comment.Single
|
11
|
-
:cs => "#408080-i", # Comment.Special
|
12
|
-
:kc => "#008000-b", # Keyword.Constant
|
13
|
-
:kd => "#008000-b", # Keyword.Declaration
|
14
|
-
:kn => "#008000-b", # Keyword.Namespace
|
15
|
-
:kp => "#008000", # Keyword.Pseudo
|
16
|
-
:kr => "#008000-b", # Keyword.Reserved
|
17
|
-
:kt => "#B00040", # Keyword.Type
|
18
|
-
:m => "#666666", # Literal.Number
|
19
|
-
:s => "#BA2121", # Literal.String
|
20
|
-
:na => "#7D9029", # Name.Attribute
|
21
|
-
:nb => "#008000", # Name.Builtin
|
22
|
-
:nc => "#0000FF-b", # Name.Class
|
23
|
-
:no => "#880000", # Name.Constant
|
24
|
-
:nd => "#AA22FF", # Name.Decorator
|
25
|
-
:ni => "#999999-b", # Name.Entity
|
26
|
-
:ne => "#D2413A-b", # Name.Exception
|
27
|
-
:nf => "#0000FF", # Name.Function
|
28
|
-
:nl => "#A0A000", # Name.Label
|
29
|
-
:nn => "#0000FF-b", # Name.Namespace
|
30
|
-
:nt => "#008000-b", # Name.Tag
|
31
|
-
:nv => "#19177C", # Name.Variable
|
32
|
-
:ow => "#AA22FF-b", # Operator.Word
|
33
|
-
:w => "#bbbbbb", # Text.Whitespace
|
34
|
-
:mb => "#666666", # Literal.Number.Bin
|
35
|
-
:mf => "#666666", # Literal.Number.Float
|
36
|
-
:mh => "#666666", # Literal.Number.Hex
|
37
|
-
:mi => "#666666", # Literal.Number.Integer
|
38
|
-
:mo => "#666666", # Literal.Number.Oct
|
39
|
-
:sb => "#BA2121", # Literal.String.Backtick
|
40
|
-
:sc => "#BA2121", # Literal.String.Char
|
41
|
-
:sd => "#BA2121-i", # Literal.String.Doc
|
42
|
-
:s2 => "#BA2121", # Literal.String.Double
|
43
|
-
:se => "#BB6622-b", # Literal.String.Escape
|
44
|
-
:sh => "#BA2121", # Literal.String.Heredoc
|
45
|
-
:si => "#BB6688-b", # Literal.String.Interpol
|
46
|
-
:sx => "#008000", # Literal.String.Other
|
47
|
-
:sr => "#BB6688", # Literal.String.Regex
|
48
|
-
:s1 => "#BA2121", # Literal.String.Single
|
49
|
-
:ss => "#19177C", # Literal.String.Symbol
|
50
|
-
:bp => "#008000", # Name.Builtin.Pseudo
|
51
|
-
:vc => "#19177C", # Name.Variable.Class
|
52
|
-
:vg => "#19177C", # Name.Variable.Global
|
53
|
-
:vi => "#19177C", # Name.Variable.Instance
|
54
|
-
:il => "#666666" # Literal.Number.Integer.Long
|
55
|
-
}
|
1
|
+
require 'rouge'
|
56
2
|
|
57
3
|
def self.pyg_change(code, klass, style)
|
58
4
|
color = style[0..6]
|
@@ -82,13 +28,17 @@ module PygmentFix # Remove CSS for Jutoh
|
|
82
28
|
|
83
29
|
def self.pyg_finalize(code, lexer=:elixir)
|
84
30
|
Styles.each_pair {|klass, style| pyg_change(code, klass, style) }
|
31
|
+
File.open("debug-pf1", "w") {|f| f.puts code }
|
85
32
|
code.sub!(/<pre>/, "<pre>\n")
|
86
33
|
code.gsub!(/<span class="[np]">/, "")
|
87
34
|
code.gsub!(/<\/span>/, "")
|
88
35
|
color = _codebar_color(lexer)
|
89
|
-
code.sub!(/<td class="linenos"/, "<td width=
|
36
|
+
code.sub!(/<td class="linenos"/, "<td width=2%></td><td width=5% bgcolor=#{color}")
|
37
|
+
code.gsub!(/<td/, "<td valign=top ")
|
90
38
|
code.gsub!(/ class="[^"]*?"/, "") # Get rid of remaining Pygments CSS
|
39
|
+
File.open("debug-pf2", "w") {|f| f.puts code }
|
91
40
|
lines = code.split("\n")
|
41
|
+
# lines.each {|line| line << "\n" }
|
92
42
|
n1 = lines.index {|x| x =~ /<pre>/ }
|
93
43
|
n2 = lines.index {|x| x =~ /<\/pre>/ }
|
94
44
|
# FIXME ?
|
@@ -97,15 +47,13 @@ module PygmentFix # Remove CSS for Jutoh
|
|
97
47
|
lines[n1].sub!(/ 1$/, " 1 ")
|
98
48
|
(n1+1).upto(n2) {|n| lines[n].replace(" " + lines[n] + " ") }
|
99
49
|
code = lines.join("\n")
|
50
|
+
File.open("debug-pf3", "w") {|f| f.puts code }
|
100
51
|
code
|
101
52
|
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# Was in 'bookish':
|
105
53
|
|
106
|
-
# include PygmentFix
|
107
54
|
|
108
55
|
def _process_code(text)
|
56
|
+
File.open("debug-pc1", "w") {|f| f.puts text }
|
109
57
|
lines = text.split("\n")
|
110
58
|
lines = lines.select {|x| x !~ /##~ omit/ }
|
111
59
|
@refs = {}
|
@@ -117,28 +65,32 @@ def _process_code(text)
|
|
117
65
|
end
|
118
66
|
end
|
119
67
|
lines.map! {|line| " " + line }
|
120
|
-
|
68
|
+
text2 = lines.join("\n")
|
69
|
+
File.open("debug-pc2", "w") {|f| f.puts text2 }
|
70
|
+
text.replace(text2)
|
121
71
|
end
|
122
72
|
|
123
73
|
def _colorize(code, lexer=:elixir)
|
124
74
|
text = ::Pygments.highlight(code, lexer: lexer, options: {linenos: "table"})
|
125
75
|
_debug "--- in _colorize: text = #{text.inspect}"
|
126
|
-
PygmentFix.pyg_finalize(text, lexer)
|
127
|
-
|
76
|
+
text2 = PygmentFix.pyg_finalize(text, lexer)
|
77
|
+
result = "<!-- colorized code -->\n" + text2
|
78
|
+
result
|
128
79
|
end
|
129
80
|
|
130
81
|
def _colorize!(code, lexer=:elixir)
|
131
82
|
text = ::Pygments.highlight(code, lexer: lexer, options: {})
|
132
83
|
_debug "--- in _colorize!: text = #{text.inspect}"
|
133
|
-
PygmentFix.pyg_finalize(text, lexer)
|
134
|
-
|
84
|
+
text2 = PygmentFix.pyg_finalize(text, lexer)
|
85
|
+
result = "<!-- colorized code -->\n" + text2
|
86
|
+
result
|
135
87
|
end
|
136
88
|
|
137
|
-
def
|
89
|
+
def OLD_ruby
|
138
90
|
file = @_args.first
|
139
91
|
if file.nil?
|
140
92
|
code = "# Ruby code\n"
|
141
|
-
_body {|line| code << line }
|
93
|
+
_body {|line| code << line + "\n" }
|
142
94
|
else
|
143
95
|
code = "# Ruby code\n\n" + ::File.read(file)
|
144
96
|
end
|
@@ -148,11 +100,11 @@ def ruby
|
|
148
100
|
_out "\n#{html}\n "
|
149
101
|
end
|
150
102
|
|
151
|
-
def
|
103
|
+
def OLD_elixir
|
152
104
|
file = @_args.first
|
153
105
|
if file.nil?
|
154
106
|
code = ""
|
155
|
-
_body {|line| code << line }
|
107
|
+
_body {|line| code << line + "\n" }
|
156
108
|
else
|
157
109
|
code = ::File.read(file)
|
158
110
|
end
|
@@ -163,20 +115,10 @@ def elixir
|
|
163
115
|
end
|
164
116
|
|
165
117
|
def fragment
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
code << "# Ruby code\n\n" if lexer == :ruby
|
171
|
-
_body(true) {|line| code << " " + line }
|
172
|
-
_debug "code = \n#{code}\n-----"
|
173
|
-
params = "(code, lexer: #{lexer.inspect}, options: {})"
|
174
|
-
_debug "-- pygments params = #{params}"
|
175
|
-
text = _colorize!(code, lexer)
|
176
|
-
text ||= "ERROR IN HIGHLIGHTER"
|
177
|
-
_debug "text = \n#{text.inspect}\n-----"
|
178
|
-
# PygmentFix.pyg_finalize(text, lexer)
|
179
|
-
_out text + "\n<br>"
|
118
|
+
lang = @_args.empty? ? :elixir : @_args.first.to_sym # ruby or elixir
|
119
|
+
@_args = []
|
120
|
+
send(lang)
|
121
|
+
_out "\n"
|
180
122
|
end
|
181
123
|
|
182
124
|
def code # FIXME ?
|
@@ -186,8 +128,76 @@ end
|
|
186
128
|
|
187
129
|
def mono
|
188
130
|
_out "<pre>"
|
189
|
-
_body
|
131
|
+
_body {|line| _out " " + line }
|
190
132
|
_out "</pre>"
|
191
133
|
end
|
192
134
|
|
135
|
+
def create_code_styles
|
136
|
+
dir = @_outdir || "."
|
137
|
+
theme, back = "Github", "white"
|
138
|
+
css = Rouge::Themes.const_get(theme).render(scope: '.rb_highlight')
|
139
|
+
added = <<~CSS
|
140
|
+
.rb_highlight {
|
141
|
+
font-family: 'Monaco', 'Andale Mono', 'Lucida Grande', 'Courier', 'Lucida Console', 'Courier New', monospace;
|
142
|
+
white-space: pre;
|
143
|
+
background-color: #{back}
|
144
|
+
}
|
145
|
+
CSS
|
146
|
+
|
147
|
+
css.gsub!(/{\n/, "{\n font-family: courier;")
|
148
|
+
css = added + "\n" + css
|
149
|
+
# STDERR.puts "Writing #{theme} theme to ruby.css"
|
150
|
+
File.write("#{dir}/ruby.css", css)
|
151
|
+
|
152
|
+
css = Rouge::Themes.const_get(theme).render(scope: '.ex_highlight')
|
153
|
+
added = added.sub(/rb/, "ex")
|
154
|
+
css.gsub!(/{\n/, "{\n font-family: courier;")
|
155
|
+
css = added + "\n" + css
|
156
|
+
# STDERR.puts "Writing #{theme} theme to elixir.css"
|
157
|
+
File.write("#{dir}/elixir.css", css)
|
158
|
+
end
|
159
|
+
|
193
160
|
|
161
|
+
def format_ruby(source, theme = "Github", back = "black")
|
162
|
+
# theme/back not used now
|
163
|
+
formatter = Rouge::Formatters::HTML.new
|
164
|
+
lexer = Rouge::Lexers::Ruby.new
|
165
|
+
body = formatter.format(lexer.lex(source))
|
166
|
+
text = "<div class=rb_highlight>#{body}</div>"
|
167
|
+
text
|
168
|
+
end
|
169
|
+
|
170
|
+
def format_elixir(source, theme = "Github", back = "black")
|
171
|
+
# theme/back not used now
|
172
|
+
formatter = Rouge::Formatters::HTML.new
|
173
|
+
lexer = Rouge::Lexers::Elixir.new
|
174
|
+
body = formatter.format(lexer.lex(source))
|
175
|
+
text = "<div class=ex_highlight>#{body}</div>"
|
176
|
+
text
|
177
|
+
end
|
178
|
+
|
179
|
+
def ruby
|
180
|
+
file = @_args.first
|
181
|
+
if file.nil?
|
182
|
+
code = " # Ruby code\n\n"
|
183
|
+
_body {|line| code << " " + line + "\n" }
|
184
|
+
else
|
185
|
+
code = "# Ruby code\n\n" + ::File.read(file)
|
186
|
+
end
|
187
|
+
|
188
|
+
html = format_ruby(code)
|
189
|
+
_out html
|
190
|
+
end
|
191
|
+
|
192
|
+
def elixir
|
193
|
+
file = @_args.first
|
194
|
+
if file.nil?
|
195
|
+
code = ""
|
196
|
+
_body {|line| code << " " + line + "\n" }
|
197
|
+
else
|
198
|
+
code = ::File.read(file)
|
199
|
+
end
|
200
|
+
|
201
|
+
html = format_elixir(code)
|
202
|
+
_out html
|
203
|
+
end
|
data/plugin/tutorial.rb
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
|
3
|
-
def title
|
3
|
+
def title(args = nil, body = nil)
|
4
4
|
h1
|
5
|
+
_optional_blank_line
|
5
6
|
end
|
6
7
|
|
7
|
-
def section
|
8
|
+
def section(args = nil, body = nil)
|
8
9
|
h3
|
10
|
+
_optional_blank_line
|
9
11
|
end
|
10
12
|
|
11
|
-
def code
|
13
|
+
def code(args = nil, body = nil)
|
12
14
|
first = true # dumb hack! fixes blank space
|
13
15
|
_body do |line|
|
14
16
|
tag, first = "<pre>", false if first
|
15
17
|
_out "#{tag} #{::CGI.escape_html(line)}" # indentation
|
16
18
|
end
|
17
19
|
_out "</pre>"
|
20
|
+
_optional_blank_line
|
18
21
|
end
|
19
22
|
|
20
23
|
def rx(str)
|
21
24
|
::Regexp.compile(::Regexp.escape(str))
|
22
25
|
end
|
23
26
|
|
24
|
-
def inout
|
27
|
+
def inout(args = nil, body = nil)
|
25
28
|
src, out = _args
|
26
29
|
t1 = ::File.readlines(src) rescue (abort "t1 = #{src}")
|
27
30
|
t2 = ::File.readlines(out) rescue (abort "t2 = #{out}")
|
@@ -45,6 +48,7 @@ def inout
|
|
45
48
|
</tr>
|
46
49
|
</table>
|
47
50
|
HTML
|
51
|
+
_optional_blank_line
|
48
52
|
end
|
49
53
|
|
50
54
|
def put_table(src, exp)
|
@@ -73,11 +77,12 @@ def put_table(src, exp)
|
|
73
77
|
HTML
|
74
78
|
end
|
75
79
|
|
76
|
-
def testcase
|
80
|
+
def testcase(args = nil, body = nil)
|
77
81
|
name = _args.first
|
78
82
|
_out "\n<font size=+1><b>Test: </font><font size=+2><tt>#{name}</tt></font></b></h3><br>"
|
79
83
|
src, exp = "test/data/#{name}/source.lt3", "test/data/#{name}/expected-output.txt"
|
80
84
|
@_args = [src, exp] # Better way to do this??
|
81
85
|
put_table(src, exp)
|
82
86
|
_out "<br>"
|
87
|
+
_optional_blank_line
|
83
88
|
end
|
data/test/all.rb
CHANGED
data/test/snapshots/OMIT.txt
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# Comments are ignored.
|
2
2
|
# Other lines: name_of_snapshot and any comments here are ignored (no # needed)
|
3
|
-
# fake_test_name
|
4
|
-
error_no_such_inc
|
5
|
-
error_no_such_copy
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
+
error_no_such_mixin ^ Same behavior as error_missing_end
|
7
|
+
error_invalid_name ^ Same behavior as error_no_such_inc
|
8
|
+
error_missing_end Output is duplicated somehow. Look for: puts @body or puts @main.body
|
9
|
+
error_inc_line_num Forgot what's wrong here
|
10
|
+
simple_import Not coded yet
|
11
|
+
icanhaz Dummy command similar to import/mixin
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# This file specifies which snapshots will/won't be run.
|
2
|
+
|
3
|
+
# Blank lines and comments are ignored.
|
4
|
+
# Other lines: name_of_snapshot and any comments here are ignored (no # needed)
|
5
|
+
|
6
|
+
# You can start by uncommenting one of these:
|
7
|
+
# Default INCLUDE all
|
8
|
+
# Default EXCLUDE all
|
9
|
+
# If you use neither, INCLUDE is the default (but explicit is better)
|
10
|
+
|
11
|
+
# If you include all, you can specify exclusions with an x:
|
12
|
+
# x my_test_name # this is a comment
|
13
|
+
|
14
|
+
# Likewise if you EXCLUDE all, you can specify inclusions with an i:
|
15
|
+
# i some_other_test # this is a comment
|
16
|
+
|
17
|
+
# The i and x (to include/exclude) must be the first token on
|
18
|
+
# the line (preceding the test name)
|
19
|
+
|
20
|
+
# Note that QUIT (on a line by itself) will stop processing the file
|
21
|
+
|
22
|
+
x error_no_such_inc # Output BEFORE error doesn't get passed through ("leading" output)
|
23
|
+
x error_no_such_copy # ^ Same behavior as error_no_such_inc
|
24
|
+
x error_no_such_mixin # ^ Same behavior as error_missing_end
|
25
|
+
x error_invalid_name # ^ Same behavior as error_no_such_inc
|
26
|
+
x error_missing_end # Output is duplicated somehow. Look for: puts @body or puts @main.body
|
27
|
+
x error_inc_line_num # Forgot what's wrong here
|
28
|
+
|
29
|
+
# Dummy command .icanhaz works like .mixin or .import
|
30
|
+
|
31
|
+
x icanhaz # "Leading" output doesn't get generated (same as error_no_such_inc)
|
32
|
+
icanhaz2
|
33
|
+
|
34
|
+
# Others (usually passing):
|
35
|
+
|
36
|
+
# import/include/mixin, others...
|
37
|
+
|
38
|
+
simple_copy #
|
39
|
+
simple_import #
|
40
|
+
simple_include #
|
41
|
+
simple_mixin #
|
42
|
+
|
43
|
+
# raw input
|
44
|
+
|
45
|
+
single_raw_line #
|
46
|
+
raw_lines #
|
47
|
+
raw_text_block #
|
48
|
+
copy_is_raw #
|
49
|
+
|
50
|
+
# comments
|
51
|
+
|
52
|
+
block_comment #
|
53
|
+
comments_ignored_1 #
|
54
|
+
|
55
|
+
# variables and heredocs
|
56
|
+
|
57
|
+
predef_vars #
|
58
|
+
simple_vars #
|
59
|
+
more_complex_vars #
|
60
|
+
table_with_heredocs #
|
61
|
+
|
62
|
+
# testing def
|
63
|
+
|
64
|
+
def_method #
|
65
|
+
|
66
|
+
# intraline formatting
|
67
|
+
|
68
|
+
basic_formatting #
|
69
|
+
|
70
|
+
# Errors
|
71
|
+
|
72
|
+
error_line_num #
|
73
|
+
error_mismatched_end #
|
74
|
+
error_name_not_permitted #
|
75
|
+
|
76
|
+
# functions
|
77
|
+
|
78
|
+
functions #
|
79
|
+
|
80
|
+
# More/misc...
|
81
|
+
|
82
|
+
example_alpha #
|
83
|
+
example_alpha2 #
|
84
|
+
hello_world #
|
@@ -1 +1 @@
|
|
1
|
-
1 /
|
1
|
+
1 /Name 'foobar' is unknown/
|
@@ -1 +1 @@
|
|
1
|
-
1 /
|
1
|
+
1 /name 'to_s' is invalid/
|
@@ -1 +1 @@
|
|
1
|
-
1 /
|
1
|
+
1 /Name 'foobar' is unknown/
|
@@ -1 +1 @@
|
|
1
|
-
1 /
|
1
|
+
1 /found .end with no opening command/
|
@@ -1 +1 @@
|
|
1
|
-
1 /
|
1
|
+
1 /Expected .end, found end of file/
|
@@ -1 +1 @@
|
|
1
|
-
1 /
|
1
|
+
1 /file nosuchfile.txt not found/
|
@@ -1 +1 @@
|
|
1
|
-
1 /
|
1
|
+
1 /file nosuchinc.lt3 not found/
|
@@ -0,0 +1 @@
|
|
1
|
+
1 /No such mixin 'nonexistent'/
|
File without changes
|
File without changes
|