livetext 0.9.26 → 0.9.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +3 -2
  3. data/imports/bookish.rb +1 -1
  4. data/lib/livetext/expansion.rb +108 -0
  5. data/lib/livetext/formatter.rb +223 -0
  6. data/lib/livetext/functions.rb +9 -0
  7. data/lib/livetext/helpers.rb +44 -28
  8. data/lib/livetext/html.rb +73 -0
  9. data/lib/livetext/more.rb +24 -4
  10. data/lib/livetext/parser/general.rb +1 -1
  11. data/lib/livetext/parser/set.rb +10 -3
  12. data/lib/livetext/parser/string.rb +14 -5
  13. data/lib/livetext/processor.rb +5 -0
  14. data/lib/livetext/skeleton.rb +0 -4
  15. data/lib/livetext/standard.rb +78 -63
  16. data/lib/livetext/userapi.rb +52 -19
  17. data/lib/livetext/version.rb +1 -1
  18. data/lib/livetext.rb +1 -2
  19. data/plugin/bookish.rb +1 -1
  20. data/plugin/bootstrap_menu.rb +140 -0
  21. data/plugin/misc/navbar.rb +162 -0
  22. data/test/extra/README.txt +149 -0
  23. data/test/extra/bracketed.rb +121 -0
  24. data/test/extra/bracketed.txt +44 -0
  25. data/test/extra/double.rb +121 -0
  26. data/test/extra/double.txt +44 -0
  27. data/test/extra/functions.rb +148 -0
  28. data/test/extra/functions.txt +58 -0
  29. data/test/extra/single.rb +139 -0
  30. data/test/extra/single.txt +52 -0
  31. data/test/extra/testgen.rb +104 -0
  32. data/test/{snapshots/basic_formatting/actual-error.txt → extra/variables..rb} +0 -0
  33. data/test/extra/variables.rb +94 -0
  34. data/test/extra/variables.txt +35 -0
  35. data/test/snapshots/basic_formatting/expected-output.txt +2 -2
  36. data/test/snapshots/simple_vars/source.lt3 +1 -1
  37. data/test/snapshots/subset.txt +49 -49
  38. data/test/unit/all.rb +1 -3
  39. data/test/unit/parser/general.rb +2 -2
  40. data/test/unit/parser/set.rb +0 -9
  41. metadata +19 -27
  42. data/lib/livetext/formatline.rb +0 -408
  43. data/lib/livetext/funcall.rb +0 -168
  44. data/lib/livetext/lineparser.rb +0 -441
  45. data/test/snapshots/basic_formatting/actual-output.txt +0 -13
  46. data/test/snapshots/basic_formatting/err-sdiff.txt +0 -1
  47. data/test/snapshots/basic_formatting/out-sdiff.txt +0 -14
  48. data/test/snapshots/error_inc_line_num/README.txt +0 -20
  49. data/test/snapshots/error_invalid_name/foo +0 -5
  50. data/test/snapshots/more_functions/actual-error.txt +0 -0
  51. data/test/snapshots/more_functions/actual-output.txt +0 -37
  52. data/test/snapshots/more_functions/err-sdiff.txt +0 -1
  53. data/test/snapshots/more_functions/out-sdiff.txt +0 -38
  54. data/test/snapshots/simple_vars/actual-error.txt +0 -0
  55. data/test/snapshots/simple_vars/actual-output.txt +0 -6
  56. data/test/snapshots/simple_vars/err-sdiff.txt +0 -1
  57. data/test/snapshots/simple_vars/out-sdiff.txt +0 -7
  58. data/test/snapshots/var_into_func/actual-error.txt +0 -0
  59. data/test/snapshots/var_into_func/actual-output.txt +0 -16
  60. data/test/snapshots/var_into_func/err-sdiff.txt +0 -1
  61. data/test/snapshots/var_into_func/out-sdiff.txt +0 -17
  62. data/test/testlines.rb +0 -37
  63. data/test/unit/formatline.rb +0 -638
  64. data/test/unit/lineparser.rb +0 -650
  65. data/test/unit/tokenizer.rb +0 -534
@@ -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,9 +1,9 @@
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
- and <font size=+1><tt>code font</tt></font>.
6
+ and <tt>code font</tt>.
7
7
  <p>
8
8
 
9
9
  Here are some random punctuation marks:
@@ -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,68 +19,68 @@ 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
-
23
22
  # Others (usually passing):
24
23
 
25
24
  # import/include/mixin, others...
26
25
 
27
- error_no_such_inc # Output BEFORE error doesn't get passed through ("leading" output)
28
- error_no_such_copy # ^ Same behavior as error_no_such_inc
29
- error_no_such_mixin # ^ Same behavior as error_missing_end
30
- simple_copy #
31
- simple_import #
32
- simple_include #
33
- simple_mixin #
34
- import # "Leading" output doesn't get generated (same as error_no_such_inc)
35
- import2 #
36
- mixin_bookish #
37
- import_bookish #
38
-
39
- # raw input
40
-
41
- single_raw_line #
42
- raw_lines #
43
- raw_text_block #
44
- copy_is_raw #
45
-
46
- # comments
47
-
48
- block_comment #
49
- comments_ignored_1 #
50
-
51
- # variables and heredocs
52
-
53
- predef_vars #
54
- simple_vars #
55
- more_complex_vars #
56
- table_with_heredocs #
26
+ error_no_such_inc # Output BEFORE error doesn't get passed through ("leading" output)
27
+ error_no_such_copy # ^ Same behavior as error_no_such_inc
28
+ error_no_such_mixin # ^ Same behavior as error_missing_end
29
+ simple_copy #
30
+ simple_import #
31
+ simple_include #
32
+ simple_mixin #
33
+ import # "Leading" output doesn't get generated (same as error_no_such_inc)
34
+ import2 #
35
+ mixin_bookish #
36
+ import_bookish #
37
+ test_wtf_bookish #
38
+
39
+ # raw input
40
+
41
+ single_raw_line #
42
+ raw_lines #
43
+ raw_text_block #
44
+ copy_is_raw #
45
+
46
+ # comments
47
+
48
+ block_comment #
49
+ comments_ignored_1 #
50
+
51
+ # variables and heredocs
52
+
53
+ predef_vars #
54
+ simple_vars #
55
+ more_complex_vars #
56
+ table_with_heredocs #
57
57
 
58
58
  # testing def
59
59
 
60
- def_method #
61
-
60
+ def_method #
61
+
62
62
  # intraline formatting
63
63
 
64
- basic_formatting #
65
- test_formatting_34 #
66
- test_formatting_35 #
64
+ basic_formatting #
65
+ test_formatting_34 #
66
+ test_formatting_35 #
67
67
 
68
68
  # Errors
69
69
 
70
- error_line_num #
71
- error_mismatched_end #
72
- error_name_not_permitted #
73
- error_invalid_name # ^ Same behavior as error_no_such_inc
74
- error_missing_end # Output is duplicated somehow. Look for: puts @body or puts @main.body
75
- error_inc_line_num # Forgot what's wrong here
70
+ error_line_num #
71
+ error_mismatched_end #
72
+ error_name_not_permitted #
73
+ error_invalid_name # ^ Same behavior as error_no_such_inc
74
+ error_missing_end # Output is duplicated somehow. Look for: puts @body or puts @main.body
75
+ error_inc_line_num # Forgot what's wrong here
76
76
 
77
77
  # functions
78
78
 
79
- functions #
80
- more_functions #
79
+ functions #
80
+ more_functions #
81
+
82
+ # More/misc...
81
83
 
82
- # More/misc...
83
-
84
- example_alpha #
85
- example_alpha2 #
86
- hello_world #
84
+ example_alpha #
85
+ example_alpha2 #
86
+ hello_world #
data/test/unit/all.rb CHANGED
@@ -1,6 +1,4 @@
1
1
 
2
2
  require_relative 'standard'
3
3
  require_relative 'parser' # nested
4
- # require_relative 'formatline'
5
- require_relative 'lineparser'
6
- require_relative 'tokenizer'
4
+ require_relative 'html'
@@ -33,11 +33,11 @@ class TestParseGeneral < MiniTest::Test
33
33
  def test_variables
34
34
  vars = ["foo 234\n", "bar 456\n"]
35
35
  expect = [%w[foo 234], %w[bar 456]]
36
- assert_equal ParseGeneral.parse_vars(vars), expect
36
+ assert_equal ParseGeneral.parse_vars(vars), expect, "case 1 failed"
37
37
 
38
38
  vars = ["foo2 234", "bar2 456"] # newline irrelevant
39
39
  expect = [%w[foo2 234], %w[bar2 456]]
40
- assert_equal ParseGeneral.parse_vars(vars), expect
40
+ assert_equal ParseGeneral.parse_vars(vars), expect, "case 2 failed"
41
41
 
42
42
  # quotes are not stripped... hmm
43
43
  vars = ["alpha 'simple string'", 'beta "another string"']
@@ -145,15 +145,6 @@ class TestParseSet < MiniTest::Test
145
145
  # ^ ParseSet isn't smart enough to know about variables/functions
146
146
  end
147
147
 
148
- def test_var_eq_func
149
- set = ParseSet.new("date = $$date").parse
150
- set = set.first # [["var", "value"]]
151
- assert_equal set.first, "date"
152
- p set.last
153
- assert set.last =~ /undefined/, "Found 'undefined' for variable value"
154
- # ^ ParseSet isn't smart enough to know about variables/functions
155
- end
156
-
157
148
  def xtest_two_strings
158
149
  line = %[bday="May 31", date='5/31']
159
150
  set = ParseSet.new(line).parse
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.26
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-03-05 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
@@ -29,8 +29,8 @@ files:
29
29
  - lib/cmdargs.rb
30
30
  - lib/livetext.rb
31
31
  - lib/livetext/errors.rb
32
- - lib/livetext/formatline.rb
33
- - lib/livetext/funcall.rb
32
+ - lib/livetext/expansion.rb
33
+ - lib/livetext/formatter.rb
34
34
  - lib/livetext/functions.rb
35
35
  - lib/livetext/global_helpers.rb
36
36
  - lib/livetext/handler.rb
@@ -38,7 +38,6 @@ files:
38
38
  - lib/livetext/handler/mixin.rb
39
39
  - lib/livetext/helpers.rb
40
40
  - lib/livetext/html.rb
41
- - lib/livetext/lineparser.rb
42
41
  - lib/livetext/more.rb
43
42
  - lib/livetext/parser.rb
44
43
  - lib/livetext/parser/general.rb
@@ -54,19 +53,30 @@ files:
54
53
  - lib/livetext/version.rb
55
54
  - livetext.gemspec
56
55
  - plugin/bookish.rb
56
+ - plugin/bootstrap_menu.rb
57
57
  - plugin/calibre.rb
58
58
  - plugin/livemagick.rb
59
59
  - plugin/markdown.rb
60
+ - plugin/misc/navbar.rb
60
61
  - plugin/pyggish.rb
61
62
  - plugin/tutorial.rb
62
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
63
77
  - test/snapshots.rb
64
- - test/snapshots/basic_formatting/actual-error.txt
65
- - test/snapshots/basic_formatting/actual-output.txt
66
- - test/snapshots/basic_formatting/err-sdiff.txt
67
78
  - test/snapshots/basic_formatting/expected-error.txt
68
79
  - test/snapshots/basic_formatting/expected-output.txt
69
- - test/snapshots/basic_formatting/out-sdiff.txt
70
80
  - test/snapshots/basic_formatting/source.lt3
71
81
  - test/snapshots/block_comment/expected-error.txt
72
82
  - test/snapshots/block_comment/expected-output.txt
@@ -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
@@ -142,12 +150,8 @@ files:
142
150
  - test/snapshots/more_complex_vars/expected-error.txt
143
151
  - test/snapshots/more_complex_vars/expected-output.txt
144
152
  - test/snapshots/more_complex_vars/source.lt3
145
- - test/snapshots/more_functions/actual-error.txt
146
- - test/snapshots/more_functions/actual-output.txt
147
- - test/snapshots/more_functions/err-sdiff.txt
148
153
  - test/snapshots/more_functions/expected-error.txt
149
154
  - test/snapshots/more_functions/expected-output.txt
150
- - test/snapshots/more_functions/out-sdiff.txt
151
155
  - test/snapshots/more_functions/source.lt3
152
156
  - test/snapshots/predef_vars/expected-error.txt
153
157
  - test/snapshots/predef_vars/match-output.txt
@@ -175,12 +179,8 @@ files:
175
179
  - test/snapshots/simple_mixin/expected-output.txt
176
180
  - test/snapshots/simple_mixin/simple_mixin.rb
177
181
  - test/snapshots/simple_mixin/source.lt3
178
- - test/snapshots/simple_vars/actual-error.txt
179
- - test/snapshots/simple_vars/actual-output.txt
180
- - test/snapshots/simple_vars/err-sdiff.txt
181
182
  - test/snapshots/simple_vars/expected-error.txt
182
183
  - test/snapshots/simple_vars/expected-output.txt
183
- - test/snapshots/simple_vars/out-sdiff.txt
184
184
  - test/snapshots/simple_vars/source.lt3
185
185
  - test/snapshots/single_raw_line/expected-error.txt
186
186
  - test/snapshots/single_raw_line/expected-output.txt
@@ -189,18 +189,11 @@ files:
189
189
  - test/snapshots/table_with_heredocs/expected-error.txt
190
190
  - test/snapshots/table_with_heredocs/expected-output.txt
191
191
  - test/snapshots/table_with_heredocs/source.lt3
192
- - test/snapshots/var_into_func/actual-error.txt
193
- - test/snapshots/var_into_func/actual-output.txt
194
- - test/snapshots/var_into_func/err-sdiff.txt
195
192
  - test/snapshots/var_into_func/expected-error.txt
196
193
  - test/snapshots/var_into_func/expected-output.txt
197
- - test/snapshots/var_into_func/out-sdiff.txt
198
194
  - test/snapshots/var_into_func/source.lt3
199
- - test/testlines.rb
200
195
  - test/unit/all.rb
201
- - test/unit/formatline.rb
202
196
  - test/unit/html.rb
203
- - test/unit/lineparser.rb
204
197
  - test/unit/parser.rb
205
198
  - test/unit/parser/all.rb
206
199
  - test/unit/parser/general.rb
@@ -209,7 +202,6 @@ files:
209
202
  - test/unit/parser/string.rb
210
203
  - test/unit/standard.rb
211
204
  - test/unit/stringparser.rb
212
- - test/unit/tokenizer.rb
213
205
  homepage: https://github.com/Hal9000/livetext
214
206
  licenses:
215
207
  - Ruby