test/unit/formatline.rb in livetext-0.9.25 vs test/unit/formatline.rb in livetext-0.9.26

- old
+ new

@@ -4,10 +4,22 @@ class TestingLivetext < MiniTest::Test FormatLine = Livetext::FormatLine + def invoke_test(msg, src, exp) + actual = FormatLine.parse!(src) + if exp[0] == "/" + exp = Regexp.compile(exp[1..-2]) # skip slashes + $testme = false + assert_match(exp, actual, msg) + else + $testme = false + assert_equal(exp, actual, msg) + end + end + # Some (most) methods were generated via the code # seen in the comment at the bottom of this file... def test_simple_string parse = FormatLine.new("only testing") @@ -54,44 +66,44 @@ # result = parse.evaluate # regex_expected = /Today is ....-..-../ # assert_match regex_expected, result, "Found unexpected: #{result.inspect}" # end - def test_func_2 + def xtest_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 - def test_var_before_comma + def xtest_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 - def test_var_at_EOS + def xtest_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 - def test_var_starts_string + def xtest_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 @@ -101,33 +113,33 @@ end # Next one is/will be a problem... # I permit periods *inside* variable names - def test_var_before_period + def xtest_var_before_period str = "This is $File\\." # FIXME escaped for now... 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 - def test_func_needing_parameter_colon_eos # colon, param, EOS + def xtest_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_expected, tokens result = parse.evaluate string_expected = "Square root of 225 is 15" assert_equal string_expected, result, "Found unexpected: #{result.inspect}" end - def test_func_needing_parameter_colon # colon, param, more chars + def xtest_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"], @@ -139,11 +151,11 @@ assert_equal string_expected, result, "Found unexpected: #{result.inspect}" end # isqrt: Not real tests?? - def test_isqrt_empty_colon_param + def xtest_isqrt_empty_colon_param str = "Calculate $$isqrt:" parse = FormatLine.new(str) tokens_expected = [[:str, "Calculate "], [:func, "isqrt"] # , [:colon, ""] ] @@ -154,11 +166,11 @@ result = parse.evaluate string_expected = "Calculate [Error evaluating $$isqrt(NO PARAM)]" assert_equal string_expected, result, "Found unexpected: #{result.inspect}" end - def test_isqrt_empty_bracket_param + def xtest_isqrt_empty_bracket_param str = "Calculate $$isqrt[]" parse = FormatLine.new(str) tokens_expected = [[:str, "Calculate "], [:func, "isqrt"] # , [:colon, ""] ] @@ -169,11 +181,11 @@ 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 + def xtest_isqrt_malformed_number str = "Calculate $$isqrt[3a5]" parse = FormatLine.new(str) tokens_expected = [[:str, "Calculate "], [:func, "isqrt"], [:brackets, "3a5"] @@ -186,11 +198,11 @@ assert_equal string_expected, result, "Found unexpected: #{result.inspect}" end # ...end of this group - def test_func_with_colon + def xtest_func_with_colon parse = FormatLine.new("Calling $$myfunc:foo here.") tokens = parse.tokenize assert_equal tokens, [[:str, "Calling "], [:func, "myfunc"], [:colon, "foo"], @@ -199,11 +211,11 @@ result = parse.evaluate expected = "Calling [Error evaluating $$myfunc(foo)] here." assert_equal expected, result end - def test_func_with_brackets + def xtest_func_with_brackets parse = FormatLine.new("Calling $$myfunc2[foo bar] here.") tokens = parse.tokenize assert_kind_of Array, tokens assert_equal 4, tokens.size expected_tokens = [[:str, "Calling "], @@ -214,503 +226,360 @@ result = parse.evaluate expected = "Calling [Error evaluating $$myfunc2(foo bar)] here." assert_equal expected, result end - def test_formatting_01 # Check output of $$date + def xtest_parse_formatting msg, src, exp = <<~STUFF.split("\n") + Check simple formatting + This is *bold and _italics ... + This is <b>bold</b> and <i>italics</i> ... + STUFF + invoke_test(msg, src, exp) + end + + def xtest_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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_02 # Check output of $$date + def xtest_formatting_02 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_03 # Check output of $$date + def xtest_formatting_03 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_04 # Check output of $$date + def xtest_formatting_04 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_05 # Check output of $$date + def xtest_formatting_05 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_06 # Check output of $$date + def xtest_formatting_06 # 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 + invoke_test(msg, src, exp) actual = FormatLine.parse!(src) if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end end - def test_formatting_07 # Check output of $$date + def xtest_formatting_07 # 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 + invoke_test(msg, src, exp) actual = FormatLine.parse!(src) if exp[0] == "/" exp = Regexp.compile(exp[1..-2]) # skip slashes assert_match(exp, actual, msg) else assert_equal(exp, actual, msg) end end - def test_formatting_08 # Check output of $$date + def xtest_formatting_08 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_09 # Check output of $$date + def xtest_formatting_09 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_10 # Check output of $$date + def xtest_formatting_10 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_11 # Check output of $$date + def xtest_formatting_11 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_12 # Check output of $$date + def xtest_formatting_12 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_13 # Check output of $$date + def xtest_formatting_13 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_14 # Check output of $$date + def xtest_formatting_14 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_15 # Check output of $$date + def xtest_formatting_15 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_16 # Check output of $$date + def xtest_formatting_16 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_17 # Check output of $$date + def xtest_formatting_17 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_18 # Check output of $$date + def xtest_formatting_18 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_19 # Check output of $$date + def xtest_formatting_19 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_20 # Check output of $$date + def xtest_formatting_20 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_21 # Check output of $$date + def xtest_formatting_21 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_22 # Check output of $$date + def xtest_formatting_22 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_23 # Check output of $$date + def xtest_formatting_23 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_24 # Check output of $$date + def xtest_formatting_24 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_25 # Check output of $$date + def xtest_formatting_25 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_26 # Check output of $$date + def xtest_formatting_26 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_27 # Check output of $$date + def xtest_formatting_27 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_28 # Check output of $$date + def xtest_formatting_28 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_29 # Check output of $$date + def xtest_formatting_29 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_30 # Check output of $$date + def xtest_formatting_30 # 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) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + invoke_test(msg, src, exp) end - def test_formatting_31 # Check output of $$date + def xtest_formatting_31 # 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 + invoke_test(msg, src, exp) + end - actual = FormatLine.parse!(src) - if exp[0] == "/" - exp = Regexp.compile(exp[1..-2]) # skip slashes - assert_match(exp, actual, msg) - else - assert_equal(exp, actual, msg) - end + def xtest_formatting_32 # Check "real" dollar signs + msg, src, exp = <<~STUFF.split("\n") + Check "real" dollar signs + You paid $75 for that item. + You paid $75 for that item. + STUFF + invoke_test(msg, src, exp) + end + + def xtest_formatting_33 # Check dollar-space + msg, src, exp = <<~STUFF.split("\n") + Check dollar-space + He paid $ 76 for it... + He paid $ 76 for it... + STUFF + invoke_test(msg, src, exp) + end + + def test_formatting_34 # Check escaped dollar signs + $testme = true + msg, src, exp = <<~STUFF.split("\n") + Check escaped dollar signs + I paid \\$78 for it, though. + I paid $78 for it, though. + STUFF + invoke_test(msg, src, exp) + $testme = false + end + + def xtest_formatting_35 # Check ignored function param (bug or feature?) + $testme = true + msg, src, exp = <<~STUFF.split("\n") + Check ignored function param (bug or feature?) + Today is $$date:foobar, apparently. + /Today is \\d\\d\\d\\d.\\d\\d.\\d\\d apparently./ + STUFF + invoke_test(msg, src, exp) + $testme = false + end + + def xtest_formatting_36 # Check ignored function bracket param (bug or feature?) + msg, src, exp = <<~STUFF.split("\n") + Check ignored function bracket param (bug or feature?) + Today is $$date[a useless parameter], apparently. + /Today is \\d\\\d\\d\\d.\\d\\d.\\d\\d, apparently./ + STUFF + invoke_test(msg, src, exp) end end # Test generation logic: