livetext 0.9.15 → 0.9.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.lt3 +4 -2
  3. data/README.md +330 -339
  4. data/bin/livetext +0 -2
  5. data/imports/bookish.rb +288 -0
  6. data/imports/calibre.rb +28 -0
  7. data/imports/livemagick.rb +133 -0
  8. data/imports/markdown.rb +44 -0
  9. data/imports/markdown_importable.rb +45 -0
  10. data/imports/pyggish.rb +204 -0
  11. data/imports/tutorial.rb +95 -0
  12. data/lib/cmdargs.rb +26 -17
  13. data/lib/formatline.rb +4 -4
  14. data/lib/handler/icanhaz.rb +35 -0
  15. data/lib/handler.rb +1 -0
  16. data/lib/helpers.rb +59 -2
  17. data/lib/livetext.rb +6 -1
  18. data/lib/parser/general.rb +1 -1
  19. data/lib/parser/import.rb +1 -3
  20. data/lib/parser/mixin.rb +1 -16
  21. data/lib/parser/set.rb +2 -2
  22. data/lib/parser/string.rb +9 -8
  23. data/lib/processor.rb +19 -11
  24. data/lib/standard.rb +13 -2
  25. data/lib/userapi.rb +3 -2
  26. data/livetext.gemspec +2 -1
  27. data/plugin/markdown.rb +6 -6
  28. data/plugin/tutorial.rb +4 -3
  29. data/test/snapshots/icanhaz/expected-output.txt +5 -0
  30. data/test/snapshots/icanhaz/match-error.txt +1 -0
  31. data/test/snapshots/icanhaz/simple_import.rb +5 -0
  32. data/test/snapshots/icanhaz/source.lt3 +10 -0
  33. data/test/snapshots/{error_invalid_name/actual-output.txt → icanhaz2/expected-error.txt} +0 -0
  34. data/test/snapshots/icanhaz2/expected-output.txt +6 -0
  35. data/test/snapshots/icanhaz2/simple_canhaz.rb +5 -0
  36. data/test/snapshots/icanhaz2/source.lt3 +6 -0
  37. data/test/snapshots/subset.txt +84 -0
  38. data/test/snapshots.rb +71 -37
  39. data/test/unit/parser/set.rb +17 -15
  40. data/test/unit/parser/string.rb +45 -6
  41. metadata +19 -33
  42. data/test/affirm/kbks.jpg +0 -0
  43. data/test/affirm/lm-kbks.lt +0 -19
  44. data/test/cleanup +0 -1
  45. data/test/newtest +0 -14
  46. data/test/sdtest +0 -6
  47. data/test/snapshots/OMIT.txt +0 -9
  48. data/test/snapshots/clusion.txt +0 -35
  49. data/test/snapshots/crap +0 -16
  50. data/test/snapshots/error_inc_line_num/actual-error.txt +0 -14
  51. data/test/snapshots/error_inc_line_num/actual-output.txt +0 -7
  52. data/test/snapshots/error_inc_line_num/out-sdiff.txt +0 -14
  53. data/test/snapshots/error_invalid_name/actual-error.txt +0 -10
  54. data/test/snapshots/error_invalid_name/out-sdiff.txt +0 -6
  55. data/test/snapshots/error_missing_end/actual-error.txt +0 -10
  56. data/test/snapshots/error_missing_end/actual-output.txt +0 -0
  57. data/test/snapshots/error_missing_end/out-sdiff.txt +0 -6
  58. data/test/snapshots/error_no_such_copy/actual-error.txt +0 -10
  59. data/test/snapshots/error_no_such_copy/actual-output.txt +0 -0
  60. data/test/snapshots/error_no_such_copy/out-sdiff.txt +0 -5
  61. data/test/snapshots/error_no_such_inc/actual-error.txt +0 -10
  62. data/test/snapshots/error_no_such_inc/actual-output.txt +0 -0
  63. data/test/snapshots/error_no_such_inc/out-sdiff.txt +0 -6
  64. data/test/snapshots/error_no_such_mixin/actual-error.txt +0 -37
  65. data/test/snapshots/error_no_such_mixin/actual-output.txt +0 -0
  66. data/test/snapshots/error_no_such_mixin/out-sdiff.txt +0 -6
  67. data/test/snapshots/fixit +0 -6
  68. data/test/snapshots/simple_import/actual-error.txt +0 -8
  69. data/test/snapshots/simple_import/actual-output.txt +0 -3
  70. data/test/snapshots/simple_import/err-sdiff.txt +0 -9
  71. data/test/snapshots/simple_import/out-sdiff.txt +0 -9
data/lib/processor.rb CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  class Livetext
4
4
 
5
+ def self.interpolate(str)
6
+ FormatLine.var_func_parse(str)
7
+ end
8
+
5
9
  # Class Processor does the actual work of processing input.
6
10
 
7
11
  class Processor
@@ -11,17 +15,21 @@ class Livetext
11
15
  include Livetext::Standard
12
16
  include Livetext::UserAPI
13
17
 
14
- Disallowed = %i[ ! != !~ <=> == === =~ __binding__ __id__ __send__ class
15
- clone define_singleton_method display dup enum_for eql?
16
- equal? extend freeze frozen? hash inspect instance_eval
17
- instance_exec instance_of? instance_variable_defined?
18
- instance_variable_get instance_variable_set instance_variables is_a?
19
- kind_of? method methods nil? object_id
20
- pretty_inspect private_methods protected_methods public_method
21
- public_methods public_send remove_instance_variable
22
- respond_to? send singleton_class singleton_method
23
- singleton_methods taint tainted? tap to_enum
24
- to_s trust untaint untrust untrusted?]
18
+ Disallowed =
19
+ %i[ __binding__ __id__ __send__ class
20
+ clone display dup enum_for
21
+ eql? equal? extend freeze
22
+ frozen? hash inspect instance_eval
23
+ instance_exec instance_of? is_a? kind_of?
24
+ method methods nil? object_id
25
+ pretty_inspect private_methods protected_methods public_method
26
+ public_methods public_send respond_to? send
27
+ singleton_class singleton_method singleton_methods taint
28
+ tainted? tap to_enum to_s
29
+ trust untaint untrust untrusted?
30
+ define_singleton_method instance_variable_defined?
31
+ instance_variable_get instance_variable_set
32
+ remove_instance_variable instance_variables ]
25
33
 
26
34
  def initialize(parent, output = nil)
27
35
  @parent = parent
data/lib/standard.rb CHANGED
@@ -118,7 +118,7 @@ module Livetext::Standard
118
118
 
119
119
  def banner(args = nil, body = nil)
120
120
  str = _format(@_data.chomp)
121
- num = str.length - 1
121
+ num = str.length
122
122
  decor = "-"*num + "\n"
123
123
  puts decor + str + "\n" + decor
124
124
  end
@@ -187,7 +187,7 @@ module Livetext::Standard
187
187
  text = _body.join("\n")
188
188
  rhs = ""
189
189
  text.each_line do |line|
190
- str = FormatLine.var_func_parse(line.chomp)
190
+ str = Livetext.interpolate(line.chomp)
191
191
  rhs << str + "<br>"
192
192
  end
193
193
  indent = @parent.indentation.last
@@ -234,6 +234,17 @@ module Livetext::Standard
234
234
  _optional_blank_line
235
235
  end
236
236
 
237
+ def icanhaz(args = nil, body = nil)
238
+ name = @_args.first # Expect a module name
239
+ return if @_mixins.include?(name)
240
+ @_mixins << name
241
+ mod = Livetext::Handler::ICanHaz.get_module(name) # FIXME??
242
+ self.extend(mod)
243
+ init = "init_#{name}"
244
+ self.send(init) if self.respond_to? init
245
+ _optional_blank_line
246
+ end
247
+
237
248
  def import(args = nil, body = nil)
238
249
  name = @_args.first # Expect a module name
239
250
  return if @_mixins.include?(name)
data/lib/userapi.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative 'formatline'
4
4
 
5
5
  # UserAPI deals mostly with user-level methods.
6
+
6
7
  module Livetext::UserAPI
7
8
 
8
9
  def setvar(var, val)
@@ -113,9 +114,9 @@ module Livetext::UserAPI
113
114
  end
114
115
 
115
116
  def _format(line)
116
- return "" if line == "\n"
117
+ return "" if line == "\n" || line.nil?
117
118
  line2 = FormatLine.parse!(line)
118
- line.replace(line2) unless line.nil?
119
+ line.replace(line2)
119
120
  line
120
121
  end
121
122
 
data/livetext.gemspec CHANGED
@@ -15,7 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.executables << "livetext"
16
16
 
17
17
  # Files...
18
- main = Find.find("bin").to_a + Find.find("lib").to_a + Find.find("plugin").to_a
18
+ main = Find.find("bin").to_a + Find.find("lib").to_a +
19
+ Find.find("plugin").to_a + Find.find("imports").to_a
19
20
  misc = %w[./README.lt3 ./README.md livetext.gemspec]
20
21
  test = Find.find("test").to_a
21
22
 
data/plugin/markdown.rb CHANGED
@@ -8,12 +8,12 @@ SimpleFormats[:t] = %w[` `]
8
8
  SimpleFormats[:s] = %w[<strike> </strike>]
9
9
 
10
10
 
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
11
+ def h1(args = nil, body = nil); _out "# #{Livetext.interpolate(@_data)}"; _optional_blank_line end # atx style for now
12
+ def h2(args = nil, body = nil); _out "## #{Livetext.interpolate(@_data)}"; _optional_blank_line end
13
+ def h3(args = nil, body = nil); _out "### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
14
+ def h4(args = nil, body = nil); _out "#### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
15
+ def h5(args = nil, body = nil); _out "##### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
16
+ def h6(args = nil, body = nil); _out "###### #{Livetext.interpolate(@_data)}"; _optional_blank_line end
17
17
 
18
18
  def title(args = nil, body = nil)
19
19
  h1
data/plugin/tutorial.rb CHANGED
@@ -52,8 +52,9 @@ def inout(args = nil, body = nil)
52
52
  end
53
53
 
54
54
  def put_table(src, exp)
55
- t1 = ::File.readlines(src) rescue (abort "t1 = #{src}")
56
- t2 = ::File.readlines(exp) rescue (abort "t2 = #{out}")
55
+ STDERR.puts "put_table: #{[src, exp].inspect}"
56
+ t1 = ::File.readlines(src) rescue (abort "Fail - src = #{src} t1 = #{src}")
57
+ t2 = ::File.readlines(exp) rescue (abort "Fail - src = #{exp} t2 = #{out}")
57
58
  t1 = t1.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
58
59
  t2 = t2.map {|x| " " + x.sub(/ +$/,"").gsub(/_/, "\\_") }.join
59
60
 
@@ -80,7 +81,7 @@ end
80
81
  def testcase(args = nil, body = nil)
81
82
  name = _args.first
82
83
  _out "\n<font size=+1><b>Test: </font><font size=+2><tt>#{name}</tt></font></b></h3><br>"
83
- src, exp = "test/data/#{name}/source.lt3", "test/data/#{name}/expected-output.txt"
84
+ src, exp = "test/snapshots/#{name}/source.lt3", "test/snapshots/#{name}/expected-output.txt"
84
85
  @_args = [src, exp] # Better way to do this??
85
86
  put_table(src, exp)
86
87
  _out "<br>"
@@ -0,0 +1,5 @@
1
+ Test fake command .icanhaz:
2
+ we give an error
3
+ when a .rb does not
4
+ exist:
5
+ <p>
@@ -0,0 +1 @@
1
+ 1 /No such mixin 'nonexistent'/
@@ -0,0 +1,5 @@
1
+ module SimpleImport
2
+ def hello_world
3
+ _out "Hello, world."
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ Test fake command .icanhaz:
2
+ we give an error
3
+ when a .rb does not
4
+ exist:
5
+
6
+ .icanhaz nonexistent
7
+
8
+ We shouldn't
9
+ reach this point
10
+ in the file.
@@ -0,0 +1,6 @@
1
+ Testing fake command .icanhaz:
2
+ <p>
3
+
4
+ Now call a method:
5
+ Hello, world.
6
+ That's all.
@@ -0,0 +1,5 @@
1
+ module SimpleImport
2
+ def hello_world
3
+ _out "Hello, world."
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ Testing fake command .icanhaz:
2
+
3
+ .icanhaz simple_canhaz
4
+ Now call a method:
5
+ .hello_world
6
+ That's all.
@@ -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 # works?
33
+
34
+ # Others (usually passing):
35
+
36
+ # import/include/mixin, others...
37
+
38
+ simple_copy #
39
+ x simple_import # not working yet (but *could* sub in .icanhaz)
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 #
data/test/snapshots.rb CHANGED
@@ -43,6 +43,76 @@ class TestingLivetext < MiniTest::Test
43
43
  EXP_OUT, EXP_ERR = "expected-output.txt", "expected-error.txt"
44
44
  MATCH_OUT, MATCH_ERR = "match-output.txt", "match-error.txt"
45
45
 
46
+ TTY = File.open("/dev/tty","w")
47
+
48
+ def self.get_dir # FIXME - uh what?
49
+ cmdline = ARGV.first == "cmdline" # FIXME remove??
50
+ if cmdline
51
+ dir = "../"
52
+ Dir.chdir `livetext --path`.chomp.chomp
53
+ else
54
+ dir = ""
55
+ end
56
+ end
57
+
58
+ args = ARGV - ["cmdline"]
59
+
60
+ dir = self.get_dir
61
+
62
+ Data = "#{dir}test/snapshots"
63
+ Dir.chdir(Data)
64
+
65
+ TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
66
+
67
+
68
+ def self.filter
69
+ all = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
70
+ @included, @excluded = all, []
71
+ @reasons = []
72
+ @iflag, @eflag = true, false # defaults to INCLUDE
73
+ control = File.new("subset.txt")
74
+ control.each_line do |raw_line|
75
+ line = raw_line.dup
76
+ line.sub!(/#.*/, "")
77
+ line.strip!
78
+ line.chomp!
79
+ lower = line.downcase
80
+ dejavu = false
81
+ case
82
+ when lower.empty?
83
+ # ignore
84
+ when lower == "default include all"
85
+ raise "Only one 'default' allowed" if dejavu
86
+ @iflag, @eflag = true, false # defaults to INCLUDE
87
+ dejavu = true
88
+ when lower == "default exclude all"
89
+ raise "Only one 'default' allowed" if dejavu
90
+ @included = []
91
+ @iflag, @eflag = false, true
92
+ dejavu = true
93
+ when lower == "quit"
94
+ break
95
+ when lower[0] == "i" && lower[1] == " "
96
+ TTY.puts "Warning: Can't include with 'i' when that is default" if @iflag
97
+ val = raw_line.split(" ", 2)[1]
98
+ @included << val unless val.nil? # add to @included
99
+ when lower[0] == "x" && lower[1] == " "
100
+ TTY.puts "Warning: Can't exclude with 'x' when that is default" if @eflag
101
+ val, why = raw_line.split(" ", 3).values_at(1, 2)
102
+ @excluded << val unless val.nil? # add to @excluded
103
+ @reasons << why.chomp
104
+ end
105
+ end
106
+ unless @excluded.empty?
107
+ puts "\nExcluded:\n "
108
+ @excluded.each.with_index do |name, num|
109
+ printf " %-20s %s\n", name, @reasons[num]
110
+ end
111
+ puts
112
+ end
113
+ @included - @excluded
114
+ end
115
+
46
116
  def initialize(base, assertion = nil)
47
117
  @assertion = assertion
48
118
  @base = base
@@ -109,9 +179,6 @@ class TestingLivetext < MiniTest::Test
109
179
  system("rm -f #{ACTUAL_OUT} #{ACTUAL_ERR} *sdiff.txt")
110
180
  end
111
181
 
112
- def filter # TODO move subset/omit logic here??
113
- end
114
-
115
182
  def run
116
183
  @errors = false # oops, need to reset
117
184
  Dir.chdir(@base) do
@@ -124,40 +191,7 @@ class TestingLivetext < MiniTest::Test
124
191
  end
125
192
  end
126
193
 
127
- TTY = File.open("/dev/tty","w")
128
-
129
- cmdline = ARGV.first == "cmdline" # FIXME remove??
130
- if cmdline
131
- dir = "../"
132
- Dir.chdir `livetext --path`.chomp.chomp
133
- else
134
- dir = ""
135
- end
136
-
137
- Data = "#{dir}test/snapshots"
138
- Dir.chdir(Data)
139
-
140
- TestDirs = Dir.entries(".").reject {|fname| ! File.directory?(fname) } - %w[. ..]
141
-
142
- selected = File.readlines("subset.txt").map(&:chomp)
143
-
144
- omitfile = "OMIT.txt"
145
- omitted = File.readlines(omitfile).map(&:chomp)
146
- omitted.reject! {|line| line.start_with?("#") }
147
- omit_names = omitted.map {|line| line.split.first }
148
- STDERR.puts
149
- STDERR.puts " >>> Warning: Omitting #{omitted.size} snapshot tests:\n "
150
- indented = " "*7
151
- omitted.each do |line|
152
- STDERR.print indented
153
- name, info = line.split(" ", 2)
154
- STDERR.printf "%-20s %s\n", name, info
155
- end
156
- STDERR.puts
157
-
158
- wanted = selected.empty? ? TestDirs : selected
159
-
160
- Subset = wanted - omit_names
194
+ Subset = Snapshot.filter
161
195
 
162
196
  Subset.each do |tdir|
163
197
  define_method("test_#{tdir}") do
@@ -13,7 +13,7 @@ class TestParseSet < MiniTest::Test
13
13
  def teardown
14
14
  end
15
15
 
16
- def ztest_one_unquoted
16
+ def test_one_unquoted
17
17
  set = ParseSet.new('my_var_123 = 789').parse
18
18
  pair = set.first
19
19
  assert_equal pair, %w[my_var_123 789]
@@ -23,38 +23,37 @@ class TestParseSet < MiniTest::Test
23
23
  assert_equal pair, %w[var_234 naked_string]
24
24
  end
25
25
 
26
- def ztest_one_single_quoted
26
+ def test_one_single_quoted
27
27
  set = ParseSet.new("fancy.var.name = 'simple string'").parse
28
28
  pair = set.first
29
29
  assert_equal pair, ["fancy.var.name", "simple string"]
30
30
  end
31
31
 
32
- def ztest_one_double_quoted
32
+ def test_one_double_quoted
33
33
  set = ParseSet.new('fancy.var2 = "another string"').parse
34
34
  pair = set.first
35
35
  assert_equal pair, ["fancy.var2", "another string"]
36
36
  end
37
37
 
38
- def ztest_multiple_unquoted
39
- puts __method__
38
+ def test_multiple_unquoted
40
39
  pair1, pair2 = ParseSet.new("this=345, that=678").parse
41
40
  assert_equal pair1, %w[this 345]
42
41
  assert_equal pair2, %w[that 678]
43
42
  end
44
43
 
45
- def ztest_multiple_unquoted_quoted
44
+ def test_multiple_unquoted_quoted
46
45
  pair1, pair2 = ParseSet.new('alpha = 567, beta = "oh well"').parse
47
46
  assert_equal pair1, %w[alpha 567]
48
47
  assert_equal pair2, ["beta", "oh well"]
49
48
  end
50
49
 
51
- def ztest_quote_embedded_comma
50
+ def test_quote_embedded_comma
52
51
  set = ParseSet.new('gamma = "oh, well"').parse
53
52
  pair = set.first
54
53
  assert_equal pair, ["gamma", "oh, well"]
55
54
  end
56
55
 
57
- def ztest_get_var
56
+ def test_get_var
58
57
  @parse = ParseSet.new("foo=345")
59
58
  assert_equal @parse.get_var, "foo"
60
59
  @parse = ParseSet.new("foo = 345")
@@ -79,7 +78,7 @@ puts __method__
79
78
  assert_raises(BadVariableName) { @parse.get_var }
80
79
  end
81
80
 
82
- def ztest_skip_equal
81
+ def test_skip_equal
83
82
  @parse = ParseSet.new("=")
84
83
  assert_nil @parse.skip_equal
85
84
  @parse = ParseSet.new(" = ")
@@ -97,7 +96,7 @@ puts __method__
97
96
  assert_raises(NoEqualSign) { @parse.skip_equal }
98
97
  end
99
98
 
100
- def ztest_quoted_value
99
+ def test_quoted_value
101
100
  @parse = ParseSet.new(%['this'])
102
101
  assert_equal @parse.quoted_value, "this"
103
102
  @parse = ParseSet.new(%["that"])
@@ -119,7 +118,7 @@ puts __method__
119
118
  # - allow (escaped?) comma in quoted string
120
119
  end
121
120
 
122
- def ztest_unquoted_value
121
+ def test_unquoted_value
123
122
  # Note: an unquoted value is still a string!
124
123
  @parse = ParseSet.new(%[342 ])
125
124
  assert_equal @parse.unquoted_value, "342"
@@ -140,19 +139,22 @@ puts __method__
140
139
 
141
140
  # BUG: FormatLine doesn't know variables in this context!
142
141
 
143
- def xtest_4 # FIXME
142
+ def test_var_eq_var
144
143
  set = ParseSet.new("file = $File").parse
144
+ set = set.first # [["var", "value"]]
145
145
  assert_equal set.first, "file"
146
- assert set.last !~ /undefined/
146
+ refute set.last =~ /undefined/, "Found 'undefined' for variable value"
147
147
  end
148
148
 
149
149
  # BUG: ...or functions.
150
150
  # (Additional bug: Failing silently seems wrong.)
151
151
 
152
- def xtest_5 # FIXME
152
+ def test_var_eq_func
153
153
  set = ParseSet.new("date = $$date").parse
154
+ set = set.first # [["var", "value"]]
154
155
  assert_equal set.first, "date"
155
- assert set.last =~ /^\d\d.\d\d.\d\d/
156
+ refute set.last =~ /undefined/, "Found 'undefined' for variable value"
157
+ assert set.last =~ /^\d\d.\d\d.\d\d/, "Did not find 6-digit date with two separators"
156
158
  end
157
159
 
158
160
  def test_two_strings
@@ -58,7 +58,7 @@ class TestStringParser < MiniTest::Test
58
58
  assert @zero.eos?
59
59
 
60
60
  @one.grab
61
- assert @one.eos?
61
+ assert @one.eos? # FIXME??
62
62
  @one.grab
63
63
  assert @one.eos?
64
64
 
@@ -81,19 +81,15 @@ class TestStringParser < MiniTest::Test
81
81
  assert_nil char1
82
82
  assert_nil char2
83
83
  assert @zero.i == 0
84
- assert @zero.last?
85
84
  assert @zero.eos?
86
85
 
87
- refute @one.last? # FIXME??
88
86
  char1 = @one.peek
89
- refute @one.last? # FIXME??
90
87
  char2 = @one.grab
91
88
  char3 = @one.peek
92
89
  assert char1
93
90
  assert char2 == char1
94
91
  assert char3 == @str1[1]
95
92
  assert @one.i == 1
96
- assert @one.last?
97
93
  assert @one.eos? # FIXME??
98
94
 
99
95
  char1 = @many.peek
@@ -103,7 +99,6 @@ class TestStringParser < MiniTest::Test
103
99
  assert char2 == char1
104
100
  assert char3 == @strN[1]
105
101
  assert @many.i == 1
106
- refute @many.last?
107
102
  refute @many.eos?
108
103
  end
109
104
 
@@ -126,5 +121,49 @@ class TestStringParser < MiniTest::Test
126
121
  refute some.peek == " "
127
122
  assert_equal some.peek, "x"
128
123
  assert_equal some.i, 3
124
+
125
+ some = StringParser.new("abc 123")
126
+ 3.times { some.grab }
127
+ assert_equal some.peek, " "
128
+ some.skip_spaces
129
+ refute some.peek == " "
130
+ assert_equal some.peek, "1"
131
+ assert_equal some.i, 6
132
+ end
133
+
134
+ def test_ungrab
135
+ parse = StringParser.new("abcdef")
136
+ assert_equal parse.i, 0
137
+ assert_equal parse.peek, "a"
138
+ 3.times { parse.grab }
139
+ assert_equal parse.i, 3
140
+ assert_equal parse.peek, "d"
141
+ parse.ungrab
142
+ assert_equal parse.i, 2
143
+ assert_equal parse.peek, "c"
144
+ end
145
+
146
+ def test_next_bang
147
+ parse = StringParser.new("abcdef")
148
+ assert_equal parse.peek, "a"
149
+ assert_equal parse.next!, "b"
150
+ assert_equal parse.i, 0
151
+ 3.times { parse.grab }
152
+ before = parse.i
153
+ assert_equal parse.next!, "e"
154
+ after = parse.i
155
+ assert_equal before, after
156
+ end
157
+
158
+ def test_prev
159
+ parse = StringParser.new("abcdef")
160
+ assert_nil parse.prev
161
+ assert_equal parse.i, 0
162
+ 3.times { parse.grab }
163
+ before = parse.i
164
+ assert_equal parse.prev, "c"
165
+ after = parse.i
166
+ assert_equal before, after
129
167
  end
168
+
130
169
  end