test/unit/formatline.rb in livetext-0.9.21 vs test/unit/formatline.rb in livetext-0.9.22

- old
+ new

@@ -2,136 +2,229 @@ require_relative '../../lib/livetext' class TestingLivetext < MiniTest::Test -# Some (most) methods were generated via... + # Some (most) methods were generated via the code + # seen in the comment at the bottom of this file... -=begin - TestLines = [] + def test_simple_string + parse = FormatLine.new("only testing") + tokens = parse.tokenize + assert_equal tokens, [[:str, "only testing"]], "Tokens were: #{tokens.inspect}" + expected = "only testing" + result = parse.evaluate + assert_equal expected, result + end - items = [] - formatting_tests = File.open("test/snapshots/formatting-tests.txt") - loop do - 4.times { items << formatting_tests.gets.chomp } - # Blank line terminates each "stanza" - raise "Oops? #{items.inspect}" unless items.last.empty? - TestLines << items - break if formatting_tests.eof? + def test_variable_interpolation + parse = FormatLine.new("File is $File and user is $User") + tokens = parse.tokenize + expected_tokens = [[:str, "File is "], + [:var, "File"], + [:str, " and user is "], + [:var, "User"]] + assert_equal expected_tokens, tokens + result = parse.evaluate + expected = "File is [File is undefined] and user is [User is undefined]" + assert_equal expected, result end - STDERR.puts <<~RUBY - require 'minitest/autorun' + def test_func_expansion + parse = FormatLine.new("myfunc() results in $$myfunc apparently.") + tokens = parse.tokenize + expected_tokens = [[:str, "myfunc() results in "], + [:func, "myfunc"], + [:str, " apparently."]] + assert_equal expected_tokens, tokens + result = parse.evaluate + expected = "myfunc() results in [Error evaluating $$myfunc()] apparently." + assert_equal expected, result + end - require_relative '../lib/livetext' +# These tests follow this form: +# +# def test_func_SUFFIX +# str = "WHATEVER" +# parse = FormatLine.new(str) +# tokens_expected = [[], [], ...] +# tokens = parse.tokenize +# assert_equal tokens_expected, tokens +# result = parse.evaluate +# regex_expected = /Today is ....-..-../ +# assert_match regex_expected, result, "Found unexpected: #{result.inspect}" +# end - # Just another testing class. Chill. + def test_func_2 + str = "Today is $$date" + parse = FormatLine.new(str) + tokens_expected = [[:str, "Today is "], [:func, "date"]] + tokens = parse.tokenize + assert_equal tokens_expected, tokens, "Tokens were: #{tokens.inspect}" + result = parse.evaluate + regex_expected = /Today is ....-..-../ + assert_match regex_expected, result, "Found unexpected: #{result.inspect}" + end - class TestingLivetext < MiniTest::Test - RUBY + def test_var_before_comma + str = "User name is $User, and all is well" + parse = FormatLine.new(str) + tokens_expected = [[:str, "User name is "], [:var, "User"], [:str, ", and all is well"]] + tokens = parse.tokenize + assert_equal tokens_expected, tokens, "Tokens were: #{tokens.inspect}" + result = parse.evaluate + regex_expected = /User name is .*, / + assert_match regex_expected, result, "Found unexpected: #{result.inspect}" + end - TestLines.each.with_index do |item, num| - msg, src, exp, blank = *item - # generate tests... - name = "test_formatting_#{'%02d' % (num + 1)}" - method_source = <<~RUBY - def #{name} # #{msg} - msg, src, exp = <<~STUFF.split("\\n") - #{msg} - #{src} - #{exp} - STUFF + def test_var_at_EOS + str = "File name is $File" + parse = FormatLine.new(str) + tokens_expected = [[:str, "File name is "], [:var, "File"]] + tokens = parse.tokenize + assert_equal tokens_expected, tokens + result = parse.evaluate + string_expected = "File name is [File is undefined]" + assert_equal string_expected, result, "Found unexpected: #{result.inspect}" + end - actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end - end + def test_var_starts_string + str = "$File is my file name" + parse = FormatLine.new(str) + tokens_expected = [[:var, "File"], [:str, " is my file name"]] + tokens = parse.tokenize + assert_equal tokens_expected, tokens + result = parse.evaluate + string_expected = "[File is undefined] is my file name" + assert_equal string_expected, result, "Found unexpected: #{result.inspect}" + end - RUBY - STDERR.puts method_source +# Next one is/will be a problem... +# I permit periods *inside* variable names + + def test_var_before_period + str = "This is $File." + parse = FormatLine.new(str) + tokens_expected = [[:str, "This is "], [:var, "File"], [:str, "."]] + tokens = parse.tokenize + assert_equal tokens_expected, tokens + result = parse.evaluate + string_expected = "This is [File is undefined]." + assert_equal string_expected, result, "Found unexpected: #{result.inspect}" end - STDERR.puts "\nend" -end -=end - def test_simple_string - parse = FormatLine.new("only testing") + def test_func_needing_parameter_colon_eos # colon, param, EOS + str = "Square root of 225 is $$isqrt:225" + parse = FormatLine.new(str) + tokens_expected = [[:str, "Square root of 225 is "], [:func, "isqrt"], [:colon, "225"]] tokens = parse.tokenize - assert_equal tokens, [[:str, "only testing"]] - expected = "only testing" + assert_equal tokens_expected, tokens result = parse.evaluate - assert result == expected + string_expected = "Square root of 225 is 15" + assert_equal string_expected, result, "Found unexpected: #{result.inspect}" end - def test_variable_interpolation - parse = FormatLine.new("File is $File and user is $User") + def test_func_needing_parameter_colon # colon, param, more chars + str = "Answer is $$isqrt:225 today" + parse = FormatLine.new(str) + tokens_expected = [[:str, "Answer is "], + [:func, "isqrt"], + [:colon, "225"], + [:str, " today"]] tokens = parse.tokenize - assert_equal tokens, [[:str, "File is "], - [:var, "File"], - [:str, " and user is "], - [:var, "User"] - ] + assert_equal tokens_expected, tokens result = parse.evaluate - expected = "File is [File is undefined] and user is [User is undefined]" - assert result == expected + string_expected = "Answer is 15 today" + assert_equal string_expected, result, "Found unexpected: #{result.inspect}" end - def test_func_expansion - parse = FormatLine.new("myfunc() results in $$myfunc apparently.") + # isqrt: Not real tests?? + + def test_isqrt_empty_colon_param + str = "Calculate $$isqrt:" + parse = FormatLine.new(str) + tokens_expected = [[:str, "Calculate "], + [:func, "isqrt"] # , [:colon, ""] + ] + # If param is null, we don't get [:colon, value]! + # ^ FIXME function should be more like: [:func, name, param] tokens = parse.tokenize - assert_equal tokens, [[:str, "myfunc() results in "], - [:func, "myfunc"], - [:str, " apparently."] - ] + assert_equal tokens_expected, tokens result = parse.evaluate - expected = "myfunc() results in [Error evaluating $$myfunc()] apparently." - assert result == expected + string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]" + assert_equal string_expected, result, "Found unexpected: #{result.inspect}" end + def test_isqrt_empty_bracket_param + str = "Calculate $$isqrt[]" + parse = FormatLine.new(str) + tokens_expected = [[:str, "Calculate "], + [:func, "isqrt"] # , [:colon, ""] + ] + # If param is null, we don't get [:colon, value]! + # ^ FIXME function should be more like: [:func, name, param] + tokens = parse.tokenize + assert_equal tokens_expected, tokens + result = parse.evaluate + string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]" + assert_equal string_expected, result, "Found unexpected: #{result.inspect}" + end + + def test_isqrt_malformed_number + str = "Calculate $$isqrt[3a5]" + parse = FormatLine.new(str) + tokens_expected = [[:str, "Calculate "], + [:func, "isqrt"], + [:brackets, "3a5"] + ] + # ^ FIXME function should be more like: [:func, name, param] + tokens = parse.tokenize + assert_equal tokens_expected, tokens + result = parse.evaluate + string_expected = "Calculate [Error evaluating $$isqrt(3a5)]" + assert_equal string_expected, result, "Found unexpected: #{result.inspect}" + end + +# ...end of this group + def test_func_with_colon parse = FormatLine.new("Calling $$myfunc:foo here.") tokens = parse.tokenize assert_equal tokens, [[:str, "Calling "], [:func, "myfunc"], [:colon, "foo"], [:str, " here."] ] result = parse.evaluate expected = "Calling [Error evaluating $$myfunc(foo)] here." - assert result == expected + assert_equal expected, result end def test_func_with_brackets parse = FormatLine.new("Calling $$myfunc2[foo bar] here.") tokens = parse.tokenize assert_kind_of Array, tokens - assert tokens.size == 4 - assert_equal tokens, [[:str, "Calling "], - [:func, "myfunc2"], - [:brackets, "foo bar"], - [:str, " here."] - ] + assert_equal 4, tokens.size + expected_tokens = [[:str, "Calling "], + [:func, "myfunc2"], + [:brackets, "foo bar"], + [:str, " here."]] + assert_equal expected_tokens, tokens result = parse.evaluate expected = "Calling [Error evaluating $$myfunc2(foo bar)] here." - assert result == expected + assert_equal expected, result end def test_formatting_01 # Check output of $$date msg, src, exp = <<~STUFF.split("\n") Check output of $$date Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -143,12 +236,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -160,12 +252,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -177,12 +268,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -194,12 +284,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -211,12 +300,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -228,12 +316,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -245,12 +332,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -262,12 +348,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -279,12 +364,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -296,12 +380,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -313,12 +396,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -330,12 +412,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -347,12 +428,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -364,12 +444,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -381,12 +460,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -398,12 +476,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -415,12 +492,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -432,12 +508,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -449,12 +524,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -466,12 +540,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -483,12 +556,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -500,12 +572,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -517,12 +588,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -534,12 +604,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -551,12 +620,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -568,12 +636,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -585,12 +652,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -602,12 +668,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -619,12 +684,11 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end @@ -636,15 +700,68 @@ Today is $$date, I guess /Today is \\d\\d\\d\\d-\\d\\d-\\d\\d, I guess/ STUFF actual = FormatLine.parse!(src) - # FIXME could simplify assert logic? - if exp[0] == "/" # regex! FIXME doesn't honor %r[...] + if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end end end + +# Test generation logic: + +=begin + TestLines = [] + + items = [] + formatting_tests = File.open("test/snapshots/formatting-tests.txt") + loop do + 4.times { items << formatting_tests.gets.chomp } + # Blank line terminates each "stanza" + raise "Oops? #{items.inspect}" unless items.last.empty? + TestLines << items + break if formatting_tests.eof? + end + + STDERR.puts <<~RUBY + require 'minitest/autorun' + + require_relative '../lib/livetext' + + # Just another testing class. Chill. + + class TestingLivetext < MiniTest::Test + RUBY + + TestLines.each.with_index do |item, num| + msg, src, exp, blank = *item + # generate tests... + name = "test_formatting_#{'%02d' % (num + 1)}" + method_source = <<~RUBY + def #{name} # #{msg} + msg, src, exp = <<~STUFF.split("\\n") + #{msg} + #{src} + #{exp} + STUFF + + actual = FormatLine.parse!(src) + # FIXME could simplify assert logic? + if exp[0] == "/" + exp = Regexp.compile(exp[1..-2]) # skip slashes + assert_match(exp, actual, msg) + else + assert_equal(exp, actual, msg) + end + end + + RUBY + STDERR.puts method_source + end + STDERR.puts "\nend" +end +=end