livetext 0.9.21 → 0.9.25

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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +8 -8
  3. data/bin/livetext +57 -40
  4. data/imports/bookish.rb +89 -90
  5. data/imports/calibre.rb +3 -3
  6. data/imports/livemagick.rb +17 -17
  7. data/imports/markdown.rb +10 -10
  8. data/imports/pyggish.rb +15 -47
  9. data/imports/tutorial.rb +18 -18
  10. data/lib/cmdargs.rb +10 -6
  11. data/lib/{errors.rb → livetext/errors.rb} +1 -1
  12. data/lib/{formatline.rb → livetext/formatline.rb} +69 -125
  13. data/lib/livetext/funcall.rb +84 -0
  14. data/lib/{functions.rb → livetext/functions.rb} +16 -3
  15. data/lib/livetext/global_helpers.rb +37 -0
  16. data/lib/livetext/handler/import.rb +44 -0
  17. data/lib/livetext/handler/mixin.rb +37 -0
  18. data/lib/livetext/handler.rb +3 -0
  19. data/lib/{helpers.rb → livetext/helpers.rb} +89 -67
  20. data/lib/{html.rb → livetext/html.rb} +3 -2
  21. data/lib/{parser → livetext/parser}/general.rb +0 -3
  22. data/lib/{parser → livetext/parser}/set.rb +1 -6
  23. data/lib/{parser → livetext/parser}/string.rb +2 -2
  24. data/lib/{parser.rb → livetext/parser.rb} +0 -1
  25. data/lib/livetext/parsing.rb +29 -0
  26. data/lib/livetext/paths.rb +13 -0
  27. data/lib/livetext/processor.rb +89 -0
  28. data/lib/livetext/reopen.rb +12 -0
  29. data/lib/livetext/skeleton.rb +17 -0
  30. data/lib/{standard.rb → livetext/standard.rb} +152 -122
  31. data/lib/livetext/userapi.rb +153 -0
  32. data/lib/livetext/version.rb +6 -0
  33. data/lib/livetext.rb +66 -27
  34. data/plugin/bookish.rb +85 -85
  35. data/plugin/calibre.rb +3 -3
  36. data/plugin/livemagick.rb +17 -17
  37. data/plugin/markdown.rb +10 -10
  38. data/plugin/pyggish.rb +131 -162
  39. data/plugin/tutorial.rb +15 -16
  40. data/test/all.rb +6 -0
  41. data/test/snapshots/def_method/expected-output.txt +2 -0
  42. data/test/snapshots/def_method/source.lt3 +4 -2
  43. data/test/snapshots/error_inc_line_num/OUT +17 -0
  44. data/test/snapshots/error_inc_line_num/README.txt +20 -0
  45. data/test/snapshots/error_inc_line_num/expected-output.txt +0 -6
  46. data/test/snapshots/error_inc_line_num/match-error.txt +1 -1
  47. data/test/snapshots/error_line_num/match-error.txt +1 -1
  48. data/test/snapshots/error_missing_end/expected-output.txt +0 -1
  49. data/test/snapshots/error_name_not_permitted/expected-output.txt +4 -0
  50. data/test/snapshots/error_name_not_permitted/match-error.txt +1 -1
  51. data/test/snapshots/error_no_such_copy/duh +26 -0
  52. data/test/snapshots/error_no_such_copy/expected-output.txt +1 -0
  53. data/test/snapshots/error_no_such_copy/match-error.txt +1 -1
  54. data/test/snapshots/error_no_such_copy/mystery.txt +36 -0
  55. data/test/snapshots/error_no_such_inc/match-error.txt +1 -1
  56. data/test/snapshots/error_no_such_mixin/expected-output.txt +1 -0
  57. data/test/snapshots/error_no_such_mixin/match-error.txt +1 -1
  58. data/test/snapshots/error_no_such_mixin/source.lt3 +1 -1
  59. data/test/snapshots/example_alpha/source.lt3 +2 -2
  60. data/test/snapshots/example_alpha2/expected-output.txt +0 -2
  61. data/test/snapshots/example_alpha2/source.lt3 +5 -4
  62. data/test/snapshots/{icanhaz → import}/expected-output.txt +2 -1
  63. data/test/snapshots/import/match-error.txt +1 -0
  64. data/test/snapshots/{icanhaz → import}/simple_import.rb +1 -1
  65. data/test/snapshots/{icanhaz → import}/source.lt3 +2 -2
  66. data/test/snapshots/{icanhaz2 → import2}/expected-error.txt +0 -0
  67. data/test/snapshots/{icanhaz2 → import2}/expected-output.txt +3 -1
  68. data/test/snapshots/{icanhaz2/simple_canhaz.rb → import2/simple_import.rb} +1 -1
  69. data/test/snapshots/import2/source.lt3 +8 -0
  70. data/test/snapshots/import_bookish/expected-error.txt +0 -0
  71. data/test/snapshots/import_bookish/expected-output.txt +10 -0
  72. data/test/snapshots/import_bookish/source.lt3 +7 -0
  73. data/test/snapshots/import_bookish/toc.tmp +0 -0
  74. data/test/snapshots/mixin_bookish/expected-error.txt +0 -0
  75. data/test/snapshots/mixin_bookish/expected-output.txt +10 -0
  76. data/test/snapshots/mixin_bookish/source.lt3 +7 -0
  77. data/test/snapshots/mixin_bookish/toc.tmp +0 -0
  78. data/test/snapshots/more_functions/expected-error.txt +0 -0
  79. data/test/snapshots/more_functions/expected-output.txt +37 -0
  80. data/test/snapshots/more_functions/source.lt3 +40 -0
  81. data/test/snapshots/raw_lines/expected-output.txt +0 -2
  82. data/test/snapshots/simple_import/expected-output.txt +2 -0
  83. data/test/snapshots/simple_import/simple_import.rb +1 -1
  84. data/test/snapshots/simple_import/source.lt3 +3 -1
  85. data/test/snapshots/simple_mixin/simple_mixin.rb +1 -1
  86. data/test/snapshots/single_raw_line/expected-output.txt +0 -2
  87. data/test/snapshots/subset.txt +14 -14
  88. data/test/snapshots.rb +30 -13
  89. data/test/unit/formatline.rb +253 -134
  90. data/test/unit/html.rb +2 -3
  91. data/test/unit/parser/general.rb +1 -2
  92. data/test/unit/parser/mixin.rb +1 -3
  93. data/test/unit/parser/set.rb +8 -12
  94. data/test/unit/parser/string.rb +6 -6
  95. data/test/unit/parser.rb +0 -1
  96. data/test/unit/standard.rb +0 -2
  97. metadata +47 -30
  98. data/imports/markdown_importable.rb +0 -45
  99. data/lib/handler/icanhaz.rb +0 -35
  100. data/lib/handler.rb +0 -1
  101. data/lib/livetext/importable.rb +0 -2
  102. data/lib/parser/file.rb +0 -8
  103. data/lib/parser/import.rb +0 -15
  104. data/lib/parser/mixin.rb +0 -38
  105. data/lib/processor.rb +0 -83
  106. data/lib/userapi.rb +0 -160
  107. data/test/snapshots/icanhaz/match-error.txt +0 -1
  108. data/test/snapshots/icanhaz2/source.lt3 +0 -6
  109. data/test/unit/parser/importable.rb +0 -19
@@ -1,5 +1,6 @@
1
- Test fake command .icanhaz:
1
+ Test .import:
2
2
  we give an error
3
3
  when a .rb does not
4
4
  exist:
5
5
  <p>
6
+
@@ -0,0 +1 @@
1
+ 1 /file 'nonexistent' not found/
@@ -1,5 +1,5 @@
1
1
  module SimpleImport
2
2
  def hello_world
3
- _out "Hello, world."
3
+ api.out "Hello, world."
4
4
  end
5
5
  end
@@ -1,9 +1,9 @@
1
- Test fake command .icanhaz:
1
+ Test .import:
2
2
  we give an error
3
3
  when a .rb does not
4
4
  exist:
5
5
 
6
- .icanhaz nonexistent
6
+ .import nonexistent
7
7
 
8
8
  We shouldn't
9
9
  reach this point
@@ -1,6 +1,8 @@
1
- Testing fake command .icanhaz:
1
+ Testing .import:
2
2
  <p>
3
3
 
4
4
  Now call a method:
5
5
  Hello, world.
6
+ <p>
7
+
6
8
  That's all.
@@ -1,5 +1,5 @@
1
1
  module SimpleImport
2
2
  def hello_world
3
- _out "Hello, world."
3
+ api.out "Hello, world."
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ Testing .import:
2
+
3
+ .import simple_import
4
+
5
+ Now call a method:
6
+ .hello_world
7
+
8
+ That's all.
File without changes
@@ -0,0 +1,10 @@
1
+ <table cellpadding=2>
2
+ <tr>
3
+ <td width=[0, 0]% valign=top>this</td>
4
+ <td width=[0, 0]% valign=top>that</td>
5
+ </tr>
6
+ <tr>
7
+ <td width=[0, 0]% valign=top>foo</td>
8
+ <td width=[0, 0]% valign=top>bar</td>
9
+ </tr>
10
+ </table>
@@ -0,0 +1,7 @@
1
+ .import bookish
2
+
3
+ .simple_table
4
+ this :: that
5
+ foo :: bar
6
+ .end
7
+
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ <table cellpadding=2>
2
+ <tr>
3
+ <td width=[0, 0]% valign=top>this</td>
4
+ <td width=[0, 0]% valign=top>that</td>
5
+ </tr>
6
+ <tr>
7
+ <td width=[0, 0]% valign=top>foo</td>
8
+ <td width=[0, 0]% valign=top>bar</td>
9
+ </tr>
10
+ </table>
@@ -0,0 +1,7 @@
1
+ .mixin bookish
2
+
3
+ .simple_table
4
+ this :: that
5
+ foo :: bar
6
+ .end
7
+
File without changes
File without changes
@@ -0,0 +1,37 @@
1
+ Testing some more functions here...
2
+ <p>
3
+
4
+ Here I am calling a function with
5
+ a colon parameter...
6
+ <p>
7
+
8
+ <p>
9
+
10
+ Next let's <b>do*</b> something with our parameter:
11
+ <p>
12
+
13
+ I'll call these variants...
14
+ <p>
15
+
16
+ "Motel" spelled backwards is letom :)
17
+ <p>
18
+
19
+ "lamina" reversed is animal
20
+ <p>
21
+
22
+ I can also use the erutaef tekcarb here.
23
+ <p>
24
+
25
+ If I don't use a parameter for [Error evaluating $$reverse()] - it gives
26
+ me an error. (Bug or feature??)
27
+ <p>
28
+
29
+ What if a function doesn't use parameters at all, but
30
+ we pass them? Hmm...
31
+ <p>
32
+
33
+ Now we succeed and succeed some more
34
+ and finally we succeed in life.
35
+ <p>
36
+
37
+ But can we succeed, when our beds are burning?
@@ -0,0 +1,40 @@
1
+ Testing some more functions here...
2
+
3
+ .func just_do_it
4
+ item = param
5
+ # Do "something" with the parameter...
6
+ return "" # parameter disappears!
7
+ .end
8
+
9
+ Here I am calling a function $$just_do_it:foobar with
10
+ a colon parameter...
11
+
12
+
13
+ Next let's *do* something with our parameter:
14
+
15
+ .func reverse
16
+ param.reverse # just reverse it
17
+ .end
18
+
19
+ I'll call these variants...
20
+
21
+ "Motel" spelled backwards is $$reverse:motel :)
22
+
23
+ "lamina" reversed is $$reverse:lamina
24
+
25
+ I can also use the $$reverse[bracket feature] here.
26
+
27
+ If I don't use a parameter for $$reverse - it gives
28
+ me an error. (Bug or feature??)
29
+
30
+ What if a function doesn't use parameters at all, but
31
+ we pass them? Hmm...
32
+
33
+ .func meditate
34
+ "succeed" # just replaces params with this verb
35
+ .end
36
+
37
+ Now we $$meditate:slowly and $$meditate some more
38
+ and finally we $$meditate[on various things] in life.
39
+
40
+ But can we $$meditate, when our beds are burning?
@@ -8,6 +8,4 @@ Ordinary line... plus two blank lines:
8
8
  No formatting: *foo `foo _foo ~foo
9
9
  No variables: $alpha $beta
10
10
  No functions: $$this $$that
11
- <p>
12
-
13
11
  That's all.
@@ -4,4 +4,6 @@ testing a simple import
4
4
 
5
5
  Now call a method:
6
6
  Hello, world.
7
+ <p>
8
+
7
9
  That's all.
@@ -1,5 +1,5 @@
1
1
  module SimpleImport
2
2
  def hello_world
3
- _out "Hello, world."
3
+ api.out "Hello, world."
4
4
  end
5
5
  end
@@ -1,7 +1,9 @@
1
1
  Here I am
2
2
  testing a simple import
3
- .mixin simple_import
3
+
4
+ .import simple_import
4
5
 
5
6
  Now call a method:
6
7
  .hello_world
8
+
7
9
  That's all.
@@ -1,3 +1,3 @@
1
1
  def hello_world
2
- _out "Hello, world."
2
+ api.out "Hello, world."
3
3
  end
@@ -5,6 +5,4 @@ without interpretation:
5
5
  .comment This is not a real comment.
6
6
  This is not _italics or *boldface
7
7
  This is not a $variable reference
8
- <p>
9
-
10
8
  That's all.
@@ -1,4 +1,4 @@
1
- # This file specifies which snapshots will/won't be run.
1
+ h This file specifies which snapshots will/won't be run.
2
2
 
3
3
  # Blank lines and comments are ignored.
4
4
  # Other lines: name_of_snapshot and any comments here are ignored (no # needed)
@@ -19,27 +19,23 @@
19
19
 
20
20
  # Note that QUIT (on a line by itself) will stop processing the file
21
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 # works?
33
22
 
34
23
  # Others (usually passing):
35
24
 
36
25
  # import/include/mixin, others...
37
26
 
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
38
30
  simple_copy #
39
- x simple_import # not working yet (but *could* sub in .icanhaz)
31
+ simple_import #
40
32
  simple_include #
41
33
  simple_mixin #
42
-
34
+ import # "Leading" output doesn't get generated (same as error_no_such_inc)
35
+ import2 #
36
+ mixin_bookish #
37
+ import_bookish #
38
+
43
39
  # raw input
44
40
 
45
41
  single_raw_line #
@@ -72,10 +68,14 @@ x simple_import # not working yet (but *could* sub in .icanhaz)
72
68
  error_line_num #
73
69
  error_mismatched_end #
74
70
  error_name_not_permitted #
71
+ error_invalid_name # ^ Same behavior as error_no_such_inc
72
+ error_missing_end # Output is duplicated somehow. Look for: puts @body or puts @main.body
73
+ error_inc_line_num # Forgot what's wrong here
75
74
 
76
75
  # functions
77
76
 
78
77
  functions #
78
+ more_functions #
79
79
 
80
80
  # More/misc...
81
81
 
data/test/snapshots.rb CHANGED
@@ -1,3 +1,12 @@
1
+ require 'simplecov' # These two lines must go first
2
+ SimpleCov.use_merging(true)
3
+ SimpleCov.start do
4
+ puts "SimpleCov: Snapshots"
5
+ add_filter "/test/"
6
+ enable_coverage :branch
7
+ primary_coverage :branch
8
+ end
9
+
1
10
  require 'minitest/autorun'
2
11
 
3
12
  require_relative '../lib/livetext'
@@ -7,10 +16,10 @@ Snapshots...
7
16
 
8
17
  NOTE that the external_files method has been replaced by the Snapshot class.
9
18
 
10
- You can add any ordinary test method above. But so far, most of these tests simply
19
+ You can add any ordinary test method above. But so far, most of these tests simply
11
20
  call Snapshot.new
12
21
 
13
- It works this way:
22
+ It works this way:
14
23
  - If the test (caller) method is test_my_silly_feature, then we will
15
24
  look for a directory called snapshots/my_silly_feature
16
25
  - In here, there must be a source.lt3
@@ -20,12 +29,12 @@ It works this way:
20
29
  - The expected-* files are "literal" data
21
30
  * compared byte-for-byte
22
31
  * watch spaces and bad regexes, etc. #duh
23
- * each of these files corresponds to a single assertion
24
- - A match-* file has two entries per line:
32
+ * each of these files corresponds to a single assertion
33
+ - A match-* file has two entries per line:
25
34
  * a ONE-BASED line number (in actual-* file)
26
35
  * a String OR a Regexp (to match against that line)
27
36
  * If there is nonsense here, it currently isn't caught
28
- * each of these files MAY correspond to many assertions
37
+ * each of these files MAY correspond to many assertions
29
38
  - We run livetext on the source and compare actual vs expected (stdout, stderr)
30
39
  - The error output gets checked first (expected or match), THEN standard output
31
40
  - Of course, both must compare correctly for the test to pass
@@ -45,8 +54,8 @@ class TestingLivetext < MiniTest::Test
45
54
 
46
55
  TTY = File.open("/dev/tty","w")
47
56
 
48
- def self.get_dir # FIXME - uh what?
49
- cmdline = ARGV.first == "cmdline" # FIXME remove??
57
+ def self.get_dir # FIXME - uh what? remove this??
58
+ cmdline = ARGV.first == "cmdline"
50
59
  if cmdline
51
60
  dir = "../"
52
61
  Dir.chdir `livetext --path`.chomp.chomp
@@ -55,17 +64,24 @@ class TestingLivetext < MiniTest::Test
55
64
  end
56
65
  end
57
66
 
58
- args = ARGV - ["cmdline"]
59
-
67
+ Args = ARGV - ["cmdline"]
60
68
  dir = self.get_dir
61
-
62
69
  Data = "#{dir}test/snapshots"
63
70
  Dir.chdir(Data)
64
-
65
71
  TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
66
72
 
73
+ Specified = []
74
+ Args.each do |name|
75
+ which = TestDirs.select {|tdir| Regexp.new(name) =~ tdir }
76
+ which.each {|item| Specified << item }
77
+ end
78
+ Specified.uniq!
67
79
 
68
80
  def self.filter
81
+ unless Args.empty?
82
+ puts "Running: #{Args.map {|arg| "/#{arg}/" }}"
83
+ return Args
84
+ end
69
85
  all = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
70
86
  @included, @excluded = all, []
71
87
  @reasons = []
@@ -105,7 +121,7 @@ class TestingLivetext < MiniTest::Test
105
121
  end
106
122
  unless @excluded.empty?
107
123
  puts "\nExcluded:\n "
108
- @excluded.each.with_index do |name, num|
124
+ @excluded.each.with_index do |name, num|
109
125
  printf " %-20s %s\n", name, @reasons[num]
110
126
  end
111
127
  puts
@@ -191,7 +207,8 @@ class TestingLivetext < MiniTest::Test
191
207
  end
192
208
  end
193
209
 
194
- Subset = Snapshot.filter
210
+ Subset = Specified = Snapshot::Specified
211
+ Subset.replace(Snapshot.filter) if Specified.empty?
195
212
 
196
213
  Subset.each do |tdir|
197
214
  define_method("test_#{tdir}") do