livetext 0.9.30 → 0.9.31

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.
@@ -0,0 +1,104 @@
1
+ # In theory, test run could cross midnight...
2
+ RX_DATE = "[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}"
3
+ RX_TIME = "[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}"
4
+ RX_USER = "[[:alnum:]]+"
5
+ RX_PATH = "(\\\/[[:alnum:]]+)+\\\/?"
6
+ RX_VERS = "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$"
7
+
8
+ TestLines = []
9
+
10
+ def fix_regex(str)
11
+ str.gsub!(/RX_DATE/, RX_DATE)
12
+ str.gsub!(/RX_TIME/, RX_TIME)
13
+ str.gsub!(/RX_USER/, RX_USER)
14
+ str.gsub!(/RX_PATH/, RX_PATH)
15
+ str.gsub!(/RX_VERS/, RX_VERS)
16
+ str
17
+ end
18
+
19
+ abort "Need filename.txt" unless ARGV.size == 1
20
+
21
+ filename = ARGV.first
22
+ basename = filename.sub(/\.txt$/, "")
23
+ classname = basename.capitalize
24
+ rubycode = basename + ".rb"
25
+
26
+ puts "Writing: #{rubycode}"
27
+ output = File.new(rubycode, "w")
28
+
29
+ test_stanzas = File.new(filename)
30
+ loop do
31
+ items = []
32
+ loop do
33
+ items << test_stanzas.gets.chomp
34
+ break if items.last =~ /^-----/
35
+ end
36
+
37
+ TestLines << items
38
+ break if test_stanzas.eof?
39
+ end
40
+
41
+ output.puts <<~RUBY
42
+ require 'minitest/autorun'
43
+
44
+ require 'livetext'
45
+
46
+ # Just another testing class. Chill.
47
+
48
+ class TestingLivetext#{classname} < MiniTest::Test
49
+
50
+ def setup
51
+ @live = Livetext.new
52
+ end
53
+
54
+ def check_match(exp, actual)
55
+ if exp.is_a? Regexp
56
+ assert_match(exp, actual, "actual does not match expected")
57
+ else
58
+ assert_equal(exp, actual, "actual != expected")
59
+ end
60
+ end
61
+
62
+ RUBY
63
+
64
+ TestLines.each.with_index do |stanza, num|
65
+ init = nil
66
+ ix = stanza.find_index {|x| x =~ /^init: / }
67
+ if ix
68
+ init = stanza[ix].sub(/^init: /, "")
69
+ stanza.delete_at(ix)
70
+ end
71
+
72
+ desc, src, exp = *stanza
73
+ slug = desc.downcase
74
+ slug.gsub!(/[^[[:alpha:]]]/, "_")
75
+ slug.gsub!(/__/, "_")
76
+ src = src[1..-2] # strip off quotes
77
+ src.gsub!("\\n", "\n")
78
+ exp.gsub!("\\n", "\n")
79
+ if exp[0] == "/"
80
+ exp = fix_regex(exp)
81
+ exp = Regexp.compile(exp[1..-2])
82
+ else
83
+ exp = exp[1..-2]
84
+ end
85
+ init = "# No special initialization" unless init
86
+
87
+ # Generate tests...
88
+ name = "test_#{basename}_#{'%03d' % (num + 1)}_#{slug}"
89
+ method_source = <<~RUBY
90
+ def #{name}
91
+ # #{desc}
92
+ #{init}
93
+ src = #{src.inspect}
94
+ exp = #{exp.inspect}
95
+ actual = @live.api.format(src)
96
+ check_match(exp, actual)
97
+ end
98
+ RUBY
99
+ lines = method_source.split("\n")
100
+ lines.map! {|x| " " + x }
101
+ method_source = lines.join("\n")
102
+ output.puts method_source + "\n "
103
+ end
104
+ output.puts "\nend"
@@ -0,0 +1,94 @@
1
+ require 'minitest/autorun'
2
+
3
+ require 'livetext'
4
+
5
+ # Just another testing class. Chill.
6
+
7
+ class TestingLivetextVariables < MiniTest::Test
8
+
9
+ def setup
10
+ @live = Livetext.new
11
+ end
12
+
13
+ def check_match(exp, actual)
14
+ if exp.is_a? Regexp
15
+ assert_match(exp, actual, "actual does not match expected")
16
+ else
17
+ assert_equal(exp, actual, "actual != expected")
18
+ end
19
+ end
20
+
21
+ def test_variables_001_simple_variable
22
+ # Simple variable
23
+ # No special initialization
24
+ src = "User name is $User, and all is well"
25
+ exp = /is [[:alnum:]]+, and/
26
+ actual = @live.api.format(src)
27
+ check_match(exp, actual)
28
+ end
29
+
30
+ def test_variables_002_simple_user_variable
31
+ # Simple user variable
32
+ @live.api.setvar(:whatever, "some var value")
33
+ src = "This is $whatever"
34
+ exp = "This is some var value"
35
+ actual = @live.api.format(src)
36
+ check_match(exp, actual)
37
+ end
38
+
39
+ def test_variables_003_test_undefined_variable
40
+ # Test undefined variable
41
+ # No special initialization
42
+ src = "foo.bar is $foo.bar, apparently."
43
+ exp = /undefined/
44
+ actual = @live.api.format(src)
45
+ check_match(exp, actual)
46
+ end
47
+
48
+ def test_variables_004_variables_user_and_version
49
+ # Variables $User and $Version
50
+ # No special initialization
51
+ src = "I am user $User using Livetext v. $Version"
52
+ exp = /user [[:alnum:]]+ using Livetext v. [[:digit:]]+.[[:digit:]]+.[[:digit:]]+$/
53
+ actual = @live.api.format(src)
54
+ check_match(exp, actual)
55
+ end
56
+
57
+ def test_variables_005_undefined_variable
58
+ # Undefined variable
59
+ # No special initialization
60
+ src = "Here is $no.such.var's value"
61
+ exp = "Here is [no.such.var is undefined]'s value"
62
+ actual = @live.api.format(src)
63
+ check_match(exp, actual)
64
+ end
65
+
66
+ def test_variables_006_escaped_variable_name
67
+ # Escaped variable name
68
+ # No special initialization
69
+ src = "The backslash means that \\$gamma is not a variable"
70
+ exp = "The backslash means that $gamma is not a variable"
71
+ actual = @live.api.format(src)
72
+ check_match(exp, actual)
73
+ end
74
+
75
+ def test_variables_007_backslash_dollar_dollar
76
+ # Backslash dollar dollar
77
+ @live.api.setvar(:amount, 2.37)
78
+ src = "Observe: \\$$amount is not a function"
79
+ exp = "Observe: $2.37 is not a function"
80
+ actual = @live.api.format(src)
81
+ check_match(exp, actual)
82
+ end
83
+
84
+ def test_variables_008_period_after_variable_name
85
+ # Period after variable name
86
+ @live.api.setvar(:pi, 3.14159)
87
+ src = "Pi is roughly $pi."
88
+ exp = "Pi is roughly 3.14159."
89
+ actual = @live.api.format(src)
90
+ check_match(exp, actual)
91
+ end
92
+
93
+
94
+ end
@@ -0,0 +1,35 @@
1
+ Simple variable
2
+ "User name is $User, and all is well"
3
+ /is RX_USER, and/
4
+ -------------------------------------------------
5
+ Simple user variable
6
+ init: @live.api.setvar(:whatever, "some var value")
7
+ "This is $whatever"
8
+ "This is some var value"
9
+ -------------------------------------------------
10
+ Test undefined variable
11
+ "foo.bar is $foo.bar, apparently."
12
+ /undefined/
13
+ -------------------------------------------------
14
+ Variables $User and $Version
15
+ "I am user $User using Livetext v. $Version"
16
+ /user RX_USER using Livetext v. RX_VERS/
17
+ -------------------------------------------------
18
+ Undefined variable
19
+ "Here is $no.such.var's value"
20
+ "Here is [no.such.var is undefined]'s value"
21
+ -------------------------------------------------
22
+ Escaped variable name
23
+ "The backslash means that \$gamma is not a variable"
24
+ "The backslash means that $gamma is not a variable"
25
+ -------------------------------------------------
26
+ Backslash dollar dollar
27
+ init: @live.api.setvar(:amount, 2.37)
28
+ "Observe: \$$amount is not a function"
29
+ "Observe: $2.37 is not a function"
30
+ -------------------------------------------------
31
+ Period after variable name
32
+ init: @live.api.setvar(:pi, 3.14159)
33
+ "Pi is roughly $pi."
34
+ "Pi is roughly 3.14159."
35
+ -------------------------------------------------
@@ -1,6 +1,6 @@
1
1
  Here are examples of <b>boldface</b>
2
2
  and <i>italics</i>
3
- and <font size=+1><tt>code</tt></font>
3
+ and <tt>code</tt>
4
4
  as well as <b>more complex</b> examples
5
5
  of <i>italicized text</i>
6
6
  and <tt>code font</tt>.
@@ -9,4 +9,5 @@ and <tt>code font</tt>.
9
9
  Here are some random punctuation marks:
10
10
  ; # . * _ ` : @ % ^ & $
11
11
  <p>
12
+
12
13
  No need to escape these: * _ `
File without changes
File without changes
@@ -3,5 +3,5 @@ some text.
3
3
  .set name=GulliverFoyle, nation=Terra
4
4
  Hi, there.
5
5
  $name is my name, and $nation is my nation.
6
- I'm $name, from $nation\.
6
+ I'm $name, from $nation.
7
7
  That's all.
@@ -19,8 +19,6 @@ h This file specifies which snapshots will/won't be run.
19
19
 
20
20
  # Note that QUIT (on a line by itself) will stop processing the file
21
21
 
22
- # Bootstrap
23
-
24
22
  # Others (usually passing):
25
23
 
26
24
  # import/include/mixin, others...
data/test/unit/all.rb CHANGED
@@ -1,5 +1,4 @@
1
1
 
2
2
  require_relative 'standard'
3
3
  require_relative 'parser' # nested
4
- # require_relative 'lineparser'
5
- # require_relative 'tokenizer'
4
+ require_relative 'html'
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.30
4
+ version: 0.9.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-25 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A smart text processor extensible in Ruby
14
14
  email: rubyhacker@gmail.com
@@ -61,6 +61,19 @@ files:
61
61
  - plugin/pyggish.rb
62
62
  - plugin/tutorial.rb
63
63
  - test/all.rb
64
+ - test/extra/README.txt
65
+ - test/extra/bracketed.rb
66
+ - test/extra/bracketed.txt
67
+ - test/extra/double.rb
68
+ - test/extra/double.txt
69
+ - test/extra/functions.rb
70
+ - test/extra/functions.txt
71
+ - test/extra/single.rb
72
+ - test/extra/single.txt
73
+ - test/extra/testgen.rb
74
+ - test/extra/variables..rb
75
+ - test/extra/variables.rb
76
+ - test/extra/variables.txt
64
77
  - test/snapshots.rb
65
78
  - test/snapshots/basic_formatting/expected-error.txt
66
79
  - test/snapshots/basic_formatting/expected-output.txt
@@ -68,9 +81,6 @@ files:
68
81
  - test/snapshots/block_comment/expected-error.txt
69
82
  - test/snapshots/block_comment/expected-output.txt
70
83
  - test/snapshots/block_comment/source.lt3
71
- - test/snapshots/bootstrap_menu/expected-error.txt
72
- - test/snapshots/bootstrap_menu/expected-output.txt
73
- - test/snapshots/bootstrap_menu/source.lt3
74
84
  - test/snapshots/comments_ignored_1/expected-error.txt
75
85
  - test/snapshots/comments_ignored_1/expected-output.txt
76
86
  - test/snapshots/comments_ignored_1/source.lt3
@@ -81,13 +91,11 @@ files:
81
91
  - test/snapshots/def_method/expected-error.txt
82
92
  - test/snapshots/def_method/expected-output.txt
83
93
  - test/snapshots/def_method/source.lt3
84
- - test/snapshots/error_inc_line_num/README.txt
85
94
  - test/snapshots/error_inc_line_num/expected-output.txt
86
95
  - test/snapshots/error_inc_line_num/file2.lt3
87
96
  - test/snapshots/error_inc_line_num/match-error.txt
88
97
  - test/snapshots/error_inc_line_num/source.lt3
89
98
  - test/snapshots/error_invalid_name/expected-output.txt
90
- - test/snapshots/error_invalid_name/foo
91
99
  - test/snapshots/error_invalid_name/match-error.txt
92
100
  - test/snapshots/error_invalid_name/source.lt3
93
101
  - test/snapshots/error_line_num/expected-output.txt
@@ -134,9 +142,11 @@ files:
134
142
  - test/snapshots/import_bookish/expected-error.txt
135
143
  - test/snapshots/import_bookish/expected-output.txt
136
144
  - test/snapshots/import_bookish/source.lt3
145
+ - test/snapshots/import_bookish/toc.tmp
137
146
  - test/snapshots/mixin_bookish/expected-error.txt
138
147
  - test/snapshots/mixin_bookish/expected-output.txt
139
148
  - test/snapshots/mixin_bookish/source.lt3
149
+ - test/snapshots/mixin_bookish/toc.tmp
140
150
  - test/snapshots/more_complex_vars/expected-error.txt
141
151
  - test/snapshots/more_complex_vars/expected-output.txt
142
152
  - test/snapshots/more_complex_vars/source.lt3
@@ -184,8 +194,6 @@ files:
184
194
  - test/snapshots/var_into_func/source.lt3
185
195
  - test/unit/all.rb
186
196
  - test/unit/html.rb
187
- - test/unit/lineparser.rb
188
- - test/unit/new_lineparser.rb
189
197
  - test/unit/parser.rb
190
198
  - test/unit/parser/all.rb
191
199
  - test/unit/parser/general.rb
@@ -1,4 +0,0 @@
1
- abc 123
2
- this is a test
3
- more stuff
4
- still more stuff
@@ -1,17 +0,0 @@
1
- .nopara
2
-
3
- .mixin bootstrap_menu
4
-
5
- .menu
6
- .menu_link "Home", "http://fake.com/home"
7
- .menu_dropdown "Blog"
8
- .menu_dropdown_link "Home", "http://fake.com/blog"
9
- .menu_dropdown_link "Design", "http://fake.com/design"
10
- .menu_dropdown_link "HTML", "http://fake.com/html"
11
- .menu_dropdown_link "CSS", "http://fake.com/css"
12
- .menu_dropdown_link "Javascript", "http://fake.com/jscript"
13
- .menu_dropdown "Work"
14
- .menu_dropdown_item "Web Design", "http://fake.com/webdes"
15
- .menu_dropdown_item "Typography", "http://fake.com/typog"
16
- .menu_dropdown_item "Front-end", "http://fake.com/fronten"
17
- .menu_link "About", "http://fake.com/about"
@@ -1,20 +0,0 @@
1
- ---- File: source.lt3
2
-
3
- This is my
4
- source file
5
- which includes file2 here:
6
- .include file2.lt3
7
-
8
- And here we are
9
- back in the
10
- original file.
11
-
12
- --- File: file2.lt3
13
-
14
- This is file2
15
- which has an error
16
- about an unknown command
17
- in line 5
18
- .foobar
19
-
20
- And this is file2 line 7.
@@ -1,5 +0,0 @@
1
- T
2
- a
3
- t
4
- <p>
5
-