diff options
| author | Daniel Bovensiepen <[email protected]> | 2013-06-15 00:33:11 +0800 |
|---|---|---|
| committer | Daniel Bovensiepen <[email protected]> | 2013-06-15 00:33:11 +0800 |
| commit | 409541d1fa09e6ce586ce5dfdfd96d565ecf31d8 (patch) | |
| tree | 1ee5c393467482662e760e56fec671e085f483e8 /test/t/literals.rb | |
| parent | b55958b4fa766d845aa247afd8ea93fe10693081 (diff) | |
| download | mruby-409541d1fa09e6ce586ce5dfdfd96d565ecf31d8.tar.gz mruby-409541d1fa09e6ce586ce5dfdfd96d565ecf31d8.zip | |
Improve Literal Tests
Diffstat (limited to 'test/t/literals.rb')
| -rw-r--r-- | test/t/literals.rb | 179 |
1 files changed, 101 insertions, 78 deletions
diff --git a/test/t/literals.rb b/test/t/literals.rb index f40852ff9..c4fe9c993 100644 --- a/test/t/literals.rb +++ b/test/t/literals.rb @@ -3,34 +3,51 @@ assert('Literals Numerical', '8.7.6.2') do # signed and unsigned integer - 1 == 1 and -1 == -1 and +1 == +1 and - # signed and unsigned float - 1.0 == 1.0 and -1.0 == -1.0 and - # binary - 0b10000000 == 128 and 0B10000000 == 128 - # octal - 0o10 == 8 and 0O10 == 8 and 0_10 == 8 - # hex - 0xff == 255 and 0Xff == 255 and - # decimal - 0d999 == 999 and 0D999 == 999 and - # decimal seperator - 10_000_000 == 10000000 and 1_0 == 10 and - # integer with exponent - 1e1 == 10.0 and 1e-1 == 0.1 and 1e+1 == 10.0 - # float with exponent - 1.0e1 == 10.0 and 1.0e-1 == 0.1 and 1.0e+1 == 10.0 + assert_equal 1, 1 + assert_equal(-1, -1) + assert_equal(+1, +1) + # signed and unsigned float + assert_equal 1.0, 1.0 + assert_equal(-1.0, -1.0) + # binary + assert_equal 0b10000000, 128 + assert_equal 0B10000000, 128 + # octal + assert_equal 0o10, 8 + assert_equal 0O10, 8 + assert_equal 0_10, 8 + # hex + assert_equal 0xff, 255 + assert_equal 0Xff, 255 + # decimal + assert_equal 0d999, 999 + assert_equal 0D999, 999 + # decimal seperator + assert_equal 10_000_000, 10000000 + assert_equal 1_0, 10 + # integer with exponent + assert_equal 1e1, 10.0 + assert_equal 1e-1, 0.1 + assert_equal 1e+1, 10.0 + # float with exponent + assert_equal 1.0e1, 10.0 + assert_equal 1.0e-1, 0.1 + assert_equal 1.0e+1, 10.0 end assert('Literals Strings Single Quoted', '8.7.6.3.2') do - 'abc' == 'abc' and '\'' == '\'' and '\\' == '\\' + assert_equal 'abc', 'abc' + assert_equal '\'', '\'' + assert_equal '\\', '\\' end assert('Literals Strings Double Quoted', '8.7.6.3.3') do a = "abc" - "abc" == "abc" and "\"" == "\"" and "\\" == "\\" and - "#{a}" == "abc" + assert_equal "abc", "abc" + assert_equal "\"", "\"" + assert_equal "\\", "\\" + assert_equal "#{a}", "abc" end assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do @@ -42,8 +59,13 @@ assert('Literals Strings Quoted Non-Expanded', '8.7.6.3.4') do f = %q/ab\/c/ g = %q{#{a}} - a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and - e == 'abc' and f == 'ab/c' and g == '#{a}' + assert_equal a, 'abc' + assert_equal b, 'abc' + assert_equal c, 'abc' + assert_equal d, 'abc' + assert_equal e, 'abc' + assert_equal f, 'ab/c' + assert_equal g, '#{a}' end assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do @@ -55,8 +77,13 @@ assert('Literals Strings Quoted Expanded', '8.7.6.3.5') do f = %Q/ab\/c/ g = %Q{#{a}} - a == 'abc' and b == 'abc' and c == 'abc' and d == 'abc' and - e == 'abc' and f == 'ab/c' and g == 'abc' + assert_equal a, 'abc' + assert_equal b, 'abc' + assert_equal c, 'abc' + assert_equal d, 'abc' + assert_equal e, 'abc' + assert_equal f, 'ab/c' + assert_equal g, 'abc' end assert('Literals Strings Here documents', '8.7.6.3.6') do @@ -114,18 +141,18 @@ KKK z = <<'ZZZ' ZZZ - a == "aaa\n" and - b == "bbb\n" and - c == ["c1\n", "c 2\n", "c 3\n"] and - d == "d3DDD\nd\t\nDDD\n\n" and - e == "e\#{1+2}EEE\ne\\t\nEEE\\n\n" and - f == "F\nFFfFFF\nF\n" and - g == " ggg\n" and - h == " hhh\n" and - i == " iii\n" and - j == [" j1j\n", " j2j\n", " j\#{3}j\n"] and - k == 123 and - z == "" + assert_equal a, "aaa\n" + assert_equal b, "bbb\n" + assert_equal c, ["c1\n", "c 2\n", "c 3\n"] + assert_equal d, "d3DDD\nd\t\nDDD\n\n" + assert_equal e, "e\#{1+2}EEE\ne\\t\nEEE\\n\n" + assert_equal f, "F\nFFfFFF\nF\n" + assert_equal g, " ggg\n" + assert_equal h, " hhh\n" + assert_equal i, " iii\n" + assert_equal j, [" j1j\n", " j2j\n", " j\#{3}j\n"] + assert_equal k, 123 + assert_equal z, "" end assert('Literals Array', '8.7.6.4') do @@ -146,15 +173,14 @@ assert('Literals Array', '8.7.6.4') do d x\y x\\y x\\\y) - test1 = (a == ['abc3def', '}g'] and - b == ['abc', '5', 'def', '(g'] and - c == ['7'] and - d == ['9'] and - e == [] and - f == ['[ab', 'cd][ef]'] and - g == ['ab', '-11', '22'] and - h == ["a\nb", 'test abc', "c\nd", "xy", "x\\y", "x\\y"] - ) + assert_equal a, ['abc3def', '}g'] + assert_equal b, ['abc', '5', 'def', '(g'] + assert_equal c, ['7'] + assert_equal d, ['9'] + assert_equal e, [] + assert_equal f, ['[ab', 'cd][ef]'] + assert_equal g, ['ab', '-11', '22'] + assert_equal h, ["a\nb", 'test abc', "c\nd", "xy", "x\\y", "x\\y"] a = %w{abc#{1+2}def \}g} b = %w(abc #{2+3} def \(g) @@ -173,17 +199,14 @@ d d x\y x\\y x\\\y) - test2 = (a == ['abc#{1+2}def', '}g'] and - b == ['abc', '#{2+3}', 'def', '(g'] and - c == ['#{3+4}'] and - d == ['#{4+5}'] and - e == [] and - f == ['[ab', 'cd][ef]'] and - g == ['ab', '#{-1}1', '2#{2}'] and - h == ["a\\nb", "test abc", "c\nd", "x\\y", "x\\y", "x\\\\y"] - ) - - test1 and test2 + assert_equal a, ['abc#{1+2}def', '}g'] + assert_equal b, ['abc', '#{2+3}', 'def', '(g'] + assert_equal c, ['#{3+4}'] + assert_equal d, ['#{4+5}'] + assert_equal e, [] + assert_equal f, ['[ab', 'cd][ef]'] + assert_equal g, ['ab', '#{-1}1', '2#{2}'] + assert_equal h, ["a\\nb", "test abc", "c\nd", "x\\y", "x\\y", "x\\\\y"] end assert('Literals Array of symbols') do @@ -199,14 +222,13 @@ assert('Literals Array of symbols') do 2#{2} } - test1 = (a == [:'abc3def', :'}g'] and - b == [:'abc', :'5', :'def', :'(g'] and - c == [:'7'] and - d == [:'9'] and - e == [] and - f == [:'[ab', :'cd][ef]'] and - g == [:'ab', :'-11', :'22'] - ) + assert_equal a, [:'abc3def', :'}g'] + assert_equal b, [:'abc', :'5', :'def', :'(g'] + assert_equal c, [:'7'] + assert_equal d, [:'9'] + assert_equal e, [] + assert_equal f, [:'[ab', :'cd][ef]'] + assert_equal g, [:'ab', :'-11', :'22'] a = %i{abc#{1+2}def \}g} b = %i(abc #{2+3} def \(g) @@ -220,16 +242,13 @@ assert('Literals Array of symbols') do 2#{2} } - test2 = (a == [:'abc#{1+2}def', :'}g'] and - b == [:'abc', :'#{2+3}', :'def', :'(g'] and - c == [:'#{3+4}'] and - d == [:'#{4+5}'] and - e == [] and - f == [:'[ab', :'cd][ef]'] and - g == [:'ab', :'#{-1}1', :'2#{2}'] - ) - - test1 and test2 + assert_equal a, [:'abc#{1+2}def', :'}g'] + assert_equal b, [:'abc', :'#{2+3}', :'def', :'(g'] + assert_equal c, [:'#{3+4}'] + assert_equal d, [:'#{4+5}'] + assert_equal e, [] + assert_equal f, [:'[ab', :'cd][ef]'] + assert_equal g, [:'ab', :'#{-1}1', :'2#{2}'] end assert('Literals Symbol', '8.7.6.6') do @@ -255,10 +274,14 @@ qwe] g = %s/foo#{1+2}bar/ h = %s{{foo bar}} - a == :'asd qwe' and b == :"foo bar" and c == :a3b and d == :asd and - e == :' foo )' and f == :"asd [\nqwe" and g == :'foo#{1+2}bar' and - h == :'{foo bar}' + assert_equal a, :'asd qwe' + assert_equal b, :"foo bar" + assert_equal c, :a3b + assert_equal d, :asd + assert_equal e, :' foo )' + assert_equal f, :"asd [\nqwe" + assert_equal g, :'foo#{1+2}bar' + assert_equal h, :'{foo bar}' end # Not Implemented ATM assert('Literals Regular expression', '8.7.6.5') do - |
