diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/Makefile | 17 | ||||
| -rw-r--r-- | test/assert.rb | 13 | ||||
| -rw-r--r-- | test/driver.c | 39 | ||||
| -rw-r--r-- | test/t/argumenterror.rb | 5 | ||||
| -rw-r--r-- | test/t/array.rb | 69 | ||||
| -rw-r--r-- | test/t/basicobject.rb | 11 | ||||
| -rw-r--r-- | test/t/bs_block.rb | 12 | ||||
| -rw-r--r-- | test/t/class.rb | 115 | ||||
| -rw-r--r-- | test/t/comparable.rb | 56 | ||||
| -rw-r--r-- | test/t/exception.rb | 62 | ||||
| -rw-r--r-- | test/t/false.rb | 12 | ||||
| -rw-r--r-- | test/t/float.rb | 60 | ||||
| -rw-r--r-- | test/t/hash.rb | 43 | ||||
| -rw-r--r-- | test/t/indexerror.rb | 5 | ||||
| -rw-r--r-- | test/t/integer.rb | 4 | ||||
| -rw-r--r-- | test/t/kernel.rb | 261 | ||||
| -rw-r--r-- | test/t/math.rb | 172 | ||||
| -rw-r--r-- | test/t/module.rb | 101 | ||||
| -rw-r--r-- | test/t/nameerror.rb | 4 | ||||
| -rw-r--r-- | test/t/nomethoderror.rb | 5 | ||||
| -rw-r--r-- | test/t/numeric.rb | 4 | ||||
| -rw-r--r-- | test/t/object.rb | 5 | ||||
| -rw-r--r-- | test/t/proc.rb | 4 | ||||
| -rw-r--r-- | test/t/range.rb | 4 | ||||
| -rw-r--r-- | test/t/rangeerror.rb | 5 | ||||
| -rw-r--r-- | test/t/standarderror.rb | 5 | ||||
| -rw-r--r-- | test/t/string.rb | 24 | ||||
| -rw-r--r-- | test/t/struct.rb | 69 | ||||
| -rw-r--r-- | test/t/symbol.rb | 4 | ||||
| -rw-r--r-- | test/t/syntax.rb | 47 | ||||
| -rw-r--r-- | test/t/time.rb | 222 | ||||
| -rw-r--r-- | test/t/true.rb | 12 | ||||
| -rw-r--r-- | test/t/typeerror.rb | 5 |
33 files changed, 1236 insertions, 240 deletions
diff --git a/test/Makefile b/test/Makefile index 170c1dac8..921442b28 100644 --- a/test/Makefile +++ b/test/Makefile @@ -20,12 +20,19 @@ OBJS := driver.o $(MLIB) LIBS = -lm INCLUDES = -I$(BASEDIR)/../src -I$(BASEDIR)/../include -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -else -CFLAGS = -O3 +ifeq ($(strip $(COMPILE_MODE)),) + # default compile option + COMPILE_MODE = debug +endif + +ifeq ($(COMPILE_MODE),debug) + CFLAGS = -g -O3 +else ifeq ($(COMPILE_MODE),release) + CFLAGS = -O3 +else ifeq ($(COMPILE_MODE),small) + CFLAGS = -Os endif + ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" diff --git a/test/assert.rb b/test/assert.rb index 239730cb9..89e820a00 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -2,6 +2,7 @@ $ok_test = 0 $ko_test = 0 $kill_test = 0 $asserts = [] +$test_start = Time.now if Object.const_defined?(:Time) ## # Print the assertion in a readable way @@ -32,7 +33,7 @@ def assert(str = 'Assertion failed', iso = '') $ok_test += 1 print('.') end - rescue => e + rescue Exception => e $asserts.push(['Error: ', str, iso, e]) $kill_test += 1 print('X') @@ -68,18 +69,24 @@ def report() print('Crash: ') print($kill_test) print("\n") + + if Object.const_defined?(:Time) + print(' Time: ') + print(Time.now - $test_start) + print(" seconds\n") + end end ## # Performs fuzzy check for equality on methods returning floats # on the basis of the Math::TOLERANCE constant. def check_float(a, b) + tolerance = Math::TOLERANCE a = a.to_f b = b.to_f if a.finite? and b.finite? - (a-b).abs < Math::TOLERANCE + (a-b).abs < tolerance else true end end - diff --git a/test/driver.c b/test/driver.c index 4651d75fc..d2ad31b26 100644 --- a/test/driver.c +++ b/test/driver.c @@ -11,6 +11,7 @@ #include <mruby/proc.h> #include <mruby/data.h> #include <mruby/compile.h> +#include <mruby/variable.h> void mrb_init_mrbtest(mrb_state *); @@ -23,39 +24,47 @@ void print_hint(void) printf("Thanks :)\n\n"); } +static int +check_error(mrb_state *mrb) +{ + /* Error check */ + /* $ko_test and $kill_test should be 0 */ + mrb_value ko_test = mrb_gv_get(mrb, mrb_intern(mrb, "$ko_test")); + mrb_value kill_test = mrb_gv_get(mrb, mrb_intern(mrb, "$kill_test")); + + return FIXNUM_P(ko_test) && mrb_fixnum(ko_test) == 0 && FIXNUM_P(kill_test) && mrb_fixnum(kill_test) == 0; +} + int main(void) { - struct mrb_parser_state *parser; mrb_state *mrb; mrb_value return_value; - int byte_code; const char *prog = "report()"; + int ret = EXIT_SUCCESS; print_hint(); /* new interpreter instance */ mrb = mrb_open(); - mrb_init_mrbtest(mrb); - parser = mrb_parse_nstring(mrb, prog, strlen(prog)); - - /* generate bytecode */ - byte_code = mrb_generate_code(mrb, parser->tree); + if (mrb == NULL) { + fprintf(stderr, "Invalid mrb_state, exiting test driver"); + return EXIT_FAILURE; + } - /* evaluate the bytecode */ - return_value = mrb_run(mrb, - /* pass a proc for evaulation */ - mrb_proc_new(mrb, mrb->irep[byte_code]), - mrb_top_self(mrb)); + mrb_init_mrbtest(mrb); + /* evaluate the test */ + return_value = mrb_load_string(mrb, prog); /* did an exception occur? */ if (mrb->exc) { mrb_p(mrb, return_value); mrb->exc = 0; + ret = EXIT_FAILURE; } - else { - /* no */ + else if (!check_error(mrb)) { + ret = EXIT_FAILURE; } mrb_close(mrb); - return 0; + return ret; } diff --git a/test/t/argumenterror.rb b/test/t/argumenterror.rb index ca998f8de..71cf38e26 100644 --- a/test/t/argumenterror.rb +++ b/test/t/argumenterror.rb @@ -13,3 +13,8 @@ assert('ArgumentError', '15.2.24') do ArgumentError.class == Class and e2.class == ArgumentError end + +assert('ArgumentError superclass', '15.2.24.2') do + ArgumentError.superclass == StandardError +end + diff --git a/test/t/array.rb b/test/t/array.rb index dba1b035d..cb99cea6a 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -5,6 +5,10 @@ assert('Array', '15.2.12') do Array.class == Class end +assert('Array superclass', '15.2.12.2') do + Array.superclass == Object +end + assert('Array.[]', '15.2.12.4.1') do Array.[](1,2,3) == [1, 2, 3] end @@ -61,6 +65,7 @@ assert('Array#[]=', '15.2.12.5.5') do end [1,2,3].[]=(1,4) == [1, 4, 3] and + [1,2,3].[]=(1,2,3) == [1, 3] and e2.class == ArgumentError and e3.class == ArgumentError end @@ -113,7 +118,24 @@ assert('Array#first', '15.2.12.5.13') do a = [] b = [1,2,3] - a.first == nil and b.first == 1 + e2 = nil + e3 = nil + begin + # this will cause an exception due to the wrong argument + [1,2,3].first(-1) + rescue => e1 + e2 = e1 + end + begin + # this will cause an exception due to the wrong argument + [1,2,3].first(1,2) + rescue => e1 + e3 = e1 + end + + a.first == nil and b.first == 1 and b.first(0) == [] and + b.first(1) == [1] and b.first(4) == [1,2,3] and + e2.class == ArgumentError and e3.class == ArgumentError end assert('Array#index', '15.2.12.5.14') do @@ -148,7 +170,15 @@ end assert('Array#last', '15.2.12.5.18') do a = [1,2,3] - a.last == 3 and [].last == nil + e2 = nil + begin + # this will cause an exception due to the wrong argument + [1,2,3].last(-1) + rescue => e1 + e2 = e1 + end + + a.last == 3 and [].last == nil and e2.class == ArgumentError end assert('Array#length', '15.2.12.5.19') do @@ -218,7 +248,9 @@ assert('Array#size', '15.2.12.5.28') do end assert('Array#slice', '15.2.12.5.29') do - [1,2,3].[](1) == 2 + a = "12345".slice(1, 3) + b = a.slice(0) + "#{b}:" == "2:" and [1,2,3].[](1) == 2 end assert('Array#unshift', '15.2.12.5.30') do @@ -228,4 +260,35 @@ assert('Array#unshift', '15.2.12.5.30') do a == [1,2,3] and b == [1,2,3] end +assert('Array#to_s', '15.2.12.5.31') do + a = [2, 3, 4, 5] + r1 = a.to_s + r2 = a.inspect + + r1 == r2 and r1 == "[2, 3, 4, 5]" +end + +assert('Array#==', '15.2.12.5.33') do + r1 = [ "a", "c" ] == [ "a", "c", 7 ] #=> false + r2 = [ "a", "c", 7 ] == [ "a", "c", 7 ] #=> true + r3 = [ "a", "c", 7 ] == [ "a", "d", "f" ] #=> false + + r1 == false and r2 == true and r3 == false +end + +assert('Array#<=>', '15.2.12.5.36') do + r1 = [ "a", "a", "c" ] <=> [ "a", "b", "c" ] #=> -1 + r2 = [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1 + + r1 == -1 and r2 == +1 +end + # Not ISO specified + +assert("Array (Shared Array Corruption)") do + a = [ "a", "b", "c", "d", "e", "f" ] + b = a.slice(1, 3) + a.clear + b.clear +end + diff --git a/test/t/basicobject.rb b/test/t/basicobject.rb new file mode 100644 index 000000000..f7e95af89 --- /dev/null +++ b/test/t/basicobject.rb @@ -0,0 +1,11 @@ +## +# BasicObject + +assert('BasicObject') do + BasicObject.class == Class +end + +assert('BasicObject superclass') do + BasicObject.superclass == nil +end + diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb index b290cb914..bef9a8564 100644 --- a/test/t/bs_block.rb +++ b/test/t/bs_block.rb @@ -62,11 +62,11 @@ end assert('BS Block 7') do ans = [] for m in 1..3 - for n in 1..3 + for n in 2..4 a = [m, n] ans << a end - end == 1..3 + end == (1..3) end assert('BS Block 8') do @@ -322,28 +322,28 @@ assert('BS Block [ruby-dev:31147]') do def m yield end - m{|&b| b}.inspect == 'nil' + m{|&b| b} == nil end assert('BS Block [ruby-dev:31160]') do def m() yield end - m {|(v,(*))|}.inspect == 'nil' + m {|(v,(*))|} == nil end assert('BS Block 31') do def m() yield end - m {|((*))|}.inspect == 'nil' + m {|((*))|} == nil end assert('BS Block [ruby-dev:31440]') do def m yield [0] end - m{|v, &b| v}.inspect == '[0]' + m{|v, &b| v} == [0] end assert('BS Block 32') do diff --git a/test/t/class.rb b/test/t/class.rb index 92f3df51d..d6c4715dd 100644 --- a/test/t/class.rb +++ b/test/t/class.rb @@ -5,39 +5,124 @@ assert('Class', '15.2.3') do Class.class == Class end +assert('Class superclass', '15.2.3.2') do + Class.superclass == Module +end + +assert('Class#new', '15.2.3.3.3') do + # at the moment no exception on singleton class + #e1 = nil + #begin + # class1 = e1.singleton_class.new + #rescue => e1 + # e2 = e1 + #end + + class TestClass + def initialize args, &block + @result = if not args.nil? and block.nil? + # only arguments + :only_args + elsif not args.nil? and not block.nil? + # args and block is given + :args_and_block + else + # this should never happen + :broken + end + end + + def result; @result; end + end + + TestClass.new(:arg).result == :only_args + # with block doesn't work yet +end + +assert('Class#superclass', '15.2.3.3.4') do + class SubClass < String; end + SubClass.superclass == String +end + # Not ISO specified assert('Class 1') do - class C; end - C.class == Class + class C1; end + C1.class == Class end assert('Class 2') do - class C; end - C.new.class == C + class C2; end + C2.new.class == C2 end assert('Class 3') do - class C; end - C.new.class.class == Class + class C3; end + C3.new.class.class == Class end assert('Class 4') do - class A; end - class C < A; end - C.class == Class + class C4_A; end + class C4 < C4_A; end + C4.class == Class end assert('Class 5') do - class A; end - class C < A; end - C.new.class == C + class C5_A; end + class C5 < C5_A; end + C5.new.class == C5 end assert('Class 6') do - class A; end - class C < A; end - C.new.class.class == Class + class C6_A; end + class C6 < C6_A; end + C6.new.class.class == Class +end + +assert('Class 7') do + class C7_A; end + class C7_B; end + + class C7 < C7_A; end + + error = false + begin + # Different superclass. + class C7 < C7_B; end + rescue TypeError + error = true + end + + error +end + +assert('Class 8') do + class C8_A; end + + class C8; end # superclass is Object + + error = false + begin + # Different superclass. + class C8 < C8_A; end + rescue TypeError + error = true + end + + error +end + +assert('Class 9') do + Class9Const = "a" + + error = false + begin + class Class9Const; end + rescue TypeError + error = true + end + + error end assert('Class Module 1') do diff --git a/test/t/comparable.rb b/test/t/comparable.rb new file mode 100644 index 000000000..f3c03a9b5 --- /dev/null +++ b/test/t/comparable.rb @@ -0,0 +1,56 @@ + +assert('<', '15.3.3.2.1') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new < Foo.new) == false +end + +assert('<=', '15.3.3.2.2') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new <= Foo.new) == true +end + +assert('==', '15.3.3.2.3') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new == Foo.new) == true +end + +assert('>', '15.3.3.2.4') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new > Foo.new) == false +end + +assert('>=', '15.3.3.2.5') do + class Foo + include Comparable + def <=>(x) + 0 + end + end + + (Foo.new >= Foo.new) == true +end + diff --git a/test/t/exception.rb b/test/t/exception.rb index 6b46314d0..0aed0e2e6 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -5,6 +5,10 @@ assert('Exception', '15.2.22') do Exception.class == Class end +assert('Exception superclass', '15.2.22.2') do + Exception.superclass == Object +end + assert('Exception.exception', '15.2.22.4.1') do e = Exception.exception('a') @@ -20,7 +24,7 @@ end assert('Exception#message', '15.2.22.5.2') do e = Exception.exception('a') - + e.message == 'a' end @@ -37,6 +41,26 @@ assert('Exception.exception', '15.2.22.4.1') do e.message == 'a' end +assert('ScriptError', '15.2.37') do + begin + raise ScriptError.new + rescue ScriptError + true + else + false + end +end + +assert('SyntaxError', '15.2.38') do + begin + raise SyntaxError.new + rescue SyntaxError + true + else + false + end +end + # Not ISO specified assert('Exception 1') do @@ -193,3 +217,39 @@ assert('Exception 10') do 7+7 end == 12 end + +assert('Exception 11') do + a = :ok + begin + begin + raise Exception + rescue + a = :ng + end + rescue Exception + end + a == :ok +end + +assert('Exception 12') do + a = :ok + begin + raise Exception rescue a = :ng + rescue Exception + end + a == :ok +end + +assert('Exception 13') do + a = :ng + begin + raise StandardError + rescue TypeError, ArgumentError + a = :ng + rescue + a = :ok + else + a = :ng + end + a == :ok +end diff --git a/test/t/false.rb b/test/t/false.rb index c2db283c8..50ba5623a 100644 --- a/test/t/false.rb +++ b/test/t/false.rb @@ -5,22 +5,26 @@ assert('FalseClass', '15.2.6') do FalseClass.class == Class end +assert('FalseClass superclass', '15.2.6.2') do + FalseClass.superclass == Object +end + assert('FalseClass false', '15.2.6.1') do not false end assert('FalseClass#&', '15.2.6.3.1') do - not FalseClass.new.&(true) and not FalseClass.new.&(false) + not false.&(true) and not false.&(false) end assert('FalseClass#^', '15.2.6.3.2') do - FalseClass.new.^(true) and not FalseClass.new.^(false) + false.^(true) and not false.^(false) end assert('FalseClass#to_s', '15.2.6.3.3') do - FalseClass.new.to_s == 'false' + false.to_s == 'false' end assert('FalseClass#|', '15.2.6.3.4') do - FalseClass.new.|(true) and not FalseClass.new.|(false) + false.|(true) and not false.|(false) end diff --git a/test/t/float.rb b/test/t/float.rb index fc87a5b22..e2c139c03 100644 --- a/test/t/float.rb +++ b/test/t/float.rb @@ -5,6 +5,10 @@ assert('Float', '15.2.9') do Float.class == Class end +assert('Float superclass', '15.2.9.2') do + Float.superclass == Numeric +end + assert('Float#+', '15.2.9.3.1') do a = 3.123456788 + 0.000000001 b = 3.123456789 + 1 @@ -22,11 +26,11 @@ assert('Float#-', '15.2.9.3.2') do end assert('Float#*', '15.2.9.3.3') do - a = 3.123456789 * 3.123456789 - b = 3.123456789 * 1 + a = 3.125 * 3.125 + b = 3.125 * 1 - check_float(a, 9.75598231275019) and - check_float(b, 3.123456789) + check_float(a, 9.765625) and + check_float(b, 3.125) end assert('Float#/', '15.2.9.3.4') do @@ -38,19 +42,19 @@ assert('Float#/', '15.2.9.3.4') do end assert('Float#%', '15.2.9.3.5') do - a = 3.123456789 % 3.123456789 - b = 3.123456789 % 1 + a = 3.125 % 3.125 + b = 3.125 % 1 check_float(a, 0.0) and - check_float(b, 0.123456789) + check_float(b, 0.125) end assert('Float#<=>', '15.2.9.3.6') do - a = 3.123456789 <=> 3.123456788 - b = 3.123456789 <=> 3.123456789 - c = 3.123456789 <=> 3.123456790 - a2 = 3.123456789 <=> 3 - c2 = 3.123456789 <=> 4 + a = 3.125 <=> 3.123 + b = 3.125 <=> 3.125 + c = 3.125 <=> 3.126 + a2 = 3.125 <=> 3 + c2 = 3.125 <=> 4 a == 1 and b == 0 and c == -1 and a2 == 1 and c2 == -1 @@ -61,7 +65,11 @@ assert('Float#==', '15.2.9.3.7') do end assert('Float#ceil', '15.2.9.3.8') do - 3.123456789.ceil == 4 + a = 3.123456789.ceil + b = 3.0.ceil + c = -3.123456789.ceil + d = -3.0.ceil + a == 4 and b == 3 and c == -3 and d == -3 end assert('Float#finite?', '15.2.9.3.9') do @@ -70,20 +78,34 @@ assert('Float#finite?', '15.2.9.3.9') do end assert('Float#floor', '15.2.9.3.10') do - 3.123456789.floor == 3 + a = 3.123456789.floor + b = 3.0.floor + c = -3.123456789.floor + d = -3.0.floor + a == 3 and b == 3 and c == -4 and d == -3 end assert('Float#infinite?', '15.2.9.3.11') do - not 3.123456789.infinite? and - (1.0 / 0.0).infinite? + a = 3.123456789.infinite? + b = (1.0 / 0.0).infinite? + c = (-1.0 / 0.0).infinite? + + a == nil and b == 1 and c == -1 end assert('Float#round', '15.2.9.3.12') do a = 3.123456789.round b = 3.5.round - c = 3.499999999.round + c = 3.4999.round + d = (-3.123456789).round + e = (-3.5).round + f = 12345.67.round(-1) + g = 3.423456789.round(0) + h = 3.423456789.round(1) + i = 3.423456789.round(3) - a == 3 and b == 4 and c == 3 + a == 3 and b == 4 and c == 3 and d == -3 and e == -4 and + f == 12350 and g == 3 and h == 3.4 and i == 3.423 end assert('Float#to_f', '15.2.9.3.13') do @@ -97,5 +119,5 @@ assert('Float#to_i', '15.2.9.3.14') do end assert('Float#truncate', '15.2.9.3.15') do - 3.123456789.truncate == 3 + 3.123456789.truncate == 3 and -3.1.truncate == -3 end diff --git a/test/t/hash.rb b/test/t/hash.rb index af662688a..04a9a1c24 100644 --- a/test/t/hash.rb +++ b/test/t/hash.rb @@ -5,6 +5,10 @@ assert('Hash', '15.2.13') do Hash.class == Class end +assert('Hash superclass', '15.2.13.2') do + Hash.superclass == Object +end + assert('Hash#==', '15.2.13.4.1') do ({ 'abc' => 'abc' } == { 'abc' => 'abc' }) and not ({ 'abc' => 'abc' } == { 'cba' => 'cba' }) @@ -224,3 +228,42 @@ assert('Hash#values', '15.2.13.4.28') do a.values == ['abc_value'] end + +# Not ISO specified + +assert('Hash#reject') do + h = {:one => 1, :two => 2, :three => 3, :four => 4} + ret = h.reject do |k,v| + v % 2 == 0 + end + ret == {:one => 1, :three => 3} and + h == {:one => 1, :two => 2, :three => 3, :four => 4} +end + +assert('Hash#reject!') do + h = {:one => 1, :two => 2, :three => 3, :four => 4} + ret = h.reject! do |k,v| + v % 2 == 0 + end + ret == {:one => 1, :three => 3} and + h == {:one => 1, :three => 3} +end + +assert('Hash#select') do + h = {:one => 1, :two => 2, :three => 3, :four => 4} + ret = h.select do |k,v| + v % 2 == 0 + end + ret == {:two => 2, :four => 4} and + h == {:one => 1, :two => 2, :three => 3, :four => 4} +end + +assert('Hash#select!') do + h = {:one => 1, :two => 2, :three => 3, :four => 4} + ret = h.select! do |k,v| + v % 2 == 0 + end + ret == {:two => 2, :four => 4} and + h == {:two => 2, :four => 4} +end + diff --git a/test/t/indexerror.rb b/test/t/indexerror.rb index d0cb81f32..d7c8ba148 100644 --- a/test/t/indexerror.rb +++ b/test/t/indexerror.rb @@ -4,3 +4,8 @@ assert('IndexError', '15.2.33') do IndexError.class == Class end + +assert('IndexError superclass', '15.2.33.2') do + IndexError.superclass == StandardError +end + diff --git a/test/t/integer.rb b/test/t/integer.rb index 8c112861a..872723445 100644 --- a/test/t/integer.rb +++ b/test/t/integer.rb @@ -5,6 +5,10 @@ assert('Integer', '15.2.8') do Integer.class == Class end +assert('Integer superclass', '15.2.8.2') do + Integer.superclass == Numeric +end + assert('Integer#+', '15.2.8.3.1') do a = 1+1 b = 1+1.0 diff --git a/test/t/kernel.rb b/test/t/kernel.rb index cd1f2d99e..b96e85134 100644 --- a/test/t/kernel.rb +++ b/test/t/kernel.rb @@ -6,7 +6,21 @@ assert('Kernel', '15.3.1') do end assert('Kernel.block_given?', '15.3.1.2.2') do - Kernel.block_given? == false + def bg_try(&b) + if Kernel.block_given? + yield + else + "no block" + end + end + + (Kernel.block_given? == false) and + # test without block + (bg_try == "no block") and + # test with block + ((bg_try { "block" }) == "block") and + # test with block + ((bg_try do "block" end) == "block") end assert('Kernel.global_variables', '15.3.1.2.4') do @@ -22,13 +36,16 @@ assert('Kernel.lambda', '15.3.1.2.6') do true end - l.call and l.class == Proc -end + m = Kernel.lambda(&l) -assert('Kernel.local_variables', '15.3.1.2.7') do - Kernel.local_variables.class == Array + l.call and l.class == Proc and m.call and m.class == Proc end +# Not implemented at the moment +#assert('Kernel.local_variables', '15.3.1.2.7') do +# Kernel.local_variables.class == Array +#end + assert('Kernel.loop', '15.3.1.2.8') do i = 0 @@ -55,28 +72,182 @@ assert('Kernel.puts', '15.3.1.2.11') do true end -# TODO fails at the moment without arguments assert('Kernel.raise', '15.3.1.2.12') do e_list = [] begin - raise RuntimeError.new + Kernel.raise rescue => e e_list << e end - e_list[0].class == RuntimeError + begin + Kernel.raise RuntimeError.new + rescue => e + e_list << e + end + + # result without argument + e_list[0].class == RuntimeError and + # result with RuntimeError argument + e_list[1].class == RuntimeError +end + +assert('Kernel#__id__', '15.3.1.3.3') do + __id__.class == Fixnum +end + +assert('Kernel#__send__', '15.3.1.3.4') do + # test with block + l = __send__(:lambda) do + true + end + + l.call and l.class == Proc and + # test with argument + __send__(:respond_to?, :nil?) and + # test without argument and without block + __send__(:public_methods).class == Array +end + +assert('Kernel#block_given?', '15.3.1.3.6') do + def bg_try(&b) + if block_given? + yield + else + "no block" + end + end + + (block_given? == false) and + (bg_try == "no block") and + ((bg_try { "block" }) == "block") and + ((bg_try do "block" end) == "block") +end + +assert('Kernel#class', '15.3.1.3.7') do + Kernel.class == Module +end + +assert('Kernel#clone', '15.3.1.3.8') do + class KernelCloneTest + def initialize + @v = 0 + end + + def get + @v + end + + def set(v) + @v = v + end + end + + a = KernelCloneTest.new + a.set(1) + b = a.clone + + def a.test + end + a.set(2) + c = a.clone + + a.get == 2 and b.get == 1 and c.get == 2 && + a.respond_to?(:test) == true and + b.respond_to?(:test) == false and + c.respond_to?(:test) == true +end + +assert('Kernel#dup', '15.3.1.3.9') do + class KernelDupTest + def initialize + @v = 0 + end + + def get + @v + end + + def set(v) + @v = v + end + end + + a = KernelDupTest.new + a.set(1) + b = a.dup + + def a.test + end + a.set(2) + c = a.dup + + a.get == 2 and b.get == 1 and c.get == 2 and + a.respond_to?(:test) == true and + b.respond_to?(:test) == false and + c.respond_to?(:test) == false +end + +assert('Kernel#extend', '15.3.1.3.13') do + class Test4ExtendClass + end + + module Test4ExtendModule + def test_method; end + end + + a = Test4ExtendClass.new + a.extend(Test4ExtendModule) + b = Test4ExtendClass.new + + a.respond_to?(:test_method) == true && b.respond_to?(:test_method) == false +end + +assert('Kernel#global_variables', '15.3.1.3.14') do + global_variables.class == Array end -assert('Kernel#hash', '15.3.1.2.15') do +assert('Kernel#hash', '15.3.1.3.15') do hash == hash end -assert('Kernel#local_variables', '15.3.1.2.28') do - local_variables.class == Array +assert('Kernel#inspect', '15.3.1.3.17') do + inspect.class == String +end + +assert('Kernel#instance_variables', '15.3.1.3.23') do + instance_variables.class == Array +end + +assert('Kernel#is_a?', '15.3.1.3.24') do + is_a?(Kernel) and not is_a?(Array) +end + +assert('Kernel#iterator?', '15.3.1.3.25') do + iterator? == false +end + +assert('Kernel#kind_of?', '15.3.1.3.26') do + kind_of?(Kernel) and not kind_of?(Array) end -assert('Kernel#loop', '15.3.1.2.29') do +assert('Kernel#lambda', '15.3.1.3.27') do + l = lambda do + true + end + + m = lambda(&l) + + l.call and l.class == Proc and m.call and m.class == Proc +end + +# Not implemented yet +#assert('Kernel#local_variables', '15.3.1.3.28') do +# local_variables.class == Array +#end + +assert('Kernel#loop', '15.3.1.3.29') do i = 0 loop do @@ -87,38 +258,78 @@ assert('Kernel#loop', '15.3.1.2.29') do i == 100 end -assert('Kernel#methods', '15.3.1.2.31') do +assert('Kernel#methods', '15.3.1.3.31') do methods.class == Array end -assert('Kernel#nil?', '15.3.1.2.32') do - # TODO why is Kernel nil ???? - nil? == true +assert('Kernel#nil?', '15.3.1.3.32') do + nil.nil? == true +end + +assert('Kernel#object_id', '15.3.1.3.33') do + object_id.class == Fixnum end -assert('Kernel#private_methods', '15.3.1.2.36') do - private_methods.class == Array +assert('Kernel#private_methods', '15.3.1.3.36') do + private_methods.class == Array end -assert('Kernel#protected_methods', '15.3.1.2.37') do +assert('Kernel#protected_methods', '15.3.1.3.37') do protected_methods.class == Array end -assert('Kernel#public_methods', '15.3.1.2.38') do +assert('Kernel#public_methods', '15.3.1.3.38') do public_methods.class == Array end -assert('Kernel#respond_to?', '15.3.1.2.43') do - respond_to? :nil? +assert('Kernel#raise', '15.3.1.3.40') do + e_list = [] + + begin + raise + rescue => e + e_list << e + end + + begin + raise RuntimeError.new + rescue => e + e_list << e + end + + # result without argument + e_list[0].class == RuntimeError and + # result with RuntimeError argument + e_list[1].class == RuntimeError +end + +assert('Kernel#respond_to?', '15.3.1.3.43') do + class Test4RespondTo + def test_method; end + undef test_method + end + + respond_to?(:nil?) and Test4RespondTo.new.respond_to?(:test_method) == false end -# TODO at the moment doesn't comply to ISO assert('Kernel#send', '15.3.1.2.44') do +assert('Kernel#send', '15.3.1.3.44') do + # test with block + l = send(:lambda) do + true + end + + l.call and l.class == Proc and + # test with argument + send(:respond_to?, :nil?) and + # test without argument and without block + send(:public_methods).class == Array +end -assert('Kernel#singleton_methods', '15.3.1.2.45') do +assert('Kernel#singleton_methods', '15.3.1.3.45') do singleton_methods.class == Array end -assert('Kernel#to_s', '15.3.1.2.46') do +assert('Kernel#to_s', '15.3.1.3.46') do # TODO looks strange.. to_s == '' end diff --git a/test/t/math.rb b/test/t/math.rb index 5b9da4cb3..d71e44fc9 100644 --- a/test/t/math.rb +++ b/test/t/math.rb @@ -1,105 +1,117 @@ ## # Math Test -assert('Math.sin 0') do - check_float(Math.sin(0), 0) -end +if Object.const_defined?(:Math) + assert('Math.sin 0') do + check_float(Math.sin(0), 0) + end -assert('Math.sin PI/2') do - check_float(Math.sin(Math::PI / 2), 1) -end + assert('Math.sin PI/2') do + check_float(Math.sin(Math::PI / 2), 1) + end + assert('Fundamental trig identities') do + result = true + N = 13 + N.times do |i| + a = Math::PI / N * i + ca = Math::PI / 2 - a + s = Math.sin(a) + c = Math.cos(a) + t = Math.tan(a) + result &= check_float(s, Math.cos(ca)) + result &= check_float(t, 1 / Math.tan(ca)) + result &= check_float(s ** 2 + c ** 2, 1) + result &= check_float(t ** 2 + 1, (1/c) ** 2) + result &= check_float((1/t) ** 2 + 1, (1/s) ** 2) + end + result + end -assert('Fundamental trig identities') do - result = true - N = 15 - N.times do |i| - a = Math::PI / N * i - ca = Math::PI / 2 - a - s = Math.sin(a) - c = Math.cos(a) - t = Math.tan(a) - result &= check_float(s, Math.cos(ca)) - result &= check_float(t, 1 / Math.tan(ca)) - result &= check_float(s ** 2 + c ** 2, 1) - result &= check_float(t ** 2 + 1, (1/c) ** 2) - result &= check_float((1/t) ** 2 + 1, (1/s) ** 2) - end - result -end + assert('Math.erf 0') do + check_float(Math.erf(0), 0) + end -assert('Math.erf 0') do - check_float(Math.erf(0), 0) -end + assert('Math.exp 0') do + check_float(Math.exp(0), 1.0) + end -assert('Math.exp 0') do - check_float(Math.exp(0), 1.0) -end + assert('Math.exp 1') do + check_float(Math.exp(1), 2.718281828459045) + end -assert('Math.exp 1') do - check_float(Math.exp(1), 2.718281828459045) -end + assert('Math.exp 1.5') do + check_float(Math.exp(1.5), 4.4816890703380645) + end -assert('Math.exp 1.5') do - check_float(Math.exp(1.5), 4.4816890703380645) -end + assert('Math.log 1') do + check_float(Math.log(1), 0) + end -assert('Math.log 1') do - check_float(Math.log(1), 0) -end + assert('Math.log E') do + check_float(Math.log(Math::E), 1.0) + end -assert('Math.log E') do - check_float(Math.log(Math::E), 1.0) -end + assert('Math.log E**3') do + check_float(Math.log(Math::E**3), 3.0) + end -assert('Math.log E**3') do - check_float(Math.log(Math::E**3), 3.0) -end + assert('Math.log2 1') do + check_float(Math.log2(1), 0.0) + end -assert('Math.log2 1') do - check_float(Math.log2(1), 0.0) -end + assert('Math.log2 2') do + check_float(Math.log2(2), 1.0) + end -assert('Math.log2 2') do - check_float(Math.log2(2), 1.0) -end + assert('Math.log10 1') do + check_float(Math.log10(1), 0.0) + end -assert('Math.log10 1') do - check_float(Math.log10(1), 0.0) -end + assert('Math.log10 10') do + check_float(Math.log10(10), 1.0) + end -assert('Math.log10 10') do - check_float(Math.log10(10), 1.0) -end + assert('Math.log10 10**100') do + check_float(Math.log10(10**100), 100.0) + end -assert('Math.log10 10**100') do - check_float(Math.log10(10**100), 100.0) -end + assert('Math.sqrt') do + num = [0.0, 1.0, 2.0, 3.0, 4.0] + sqr = [0, 1, 4, 9, 16] + result = true + sqr.each_with_index do |v,i| + result &= check_float(Math.sqrt(v), num[i]) + end + result + end -assert('Math.cbrt') do - num = [-2.0, -1.0, 0.0, 1.0, 2.0] - cub = [-8, -1, 0, 1, 8] - result = true - cub.each_with_index do |v,i| - result &= check_float(Math.cbrt(v), num[i]) + assert('Math.cbrt') do + num = [-2.0, -1.0, 0.0, 1.0, 2.0] + cub = [-8, -1, 0, 1, 8] + result = true + cub.each_with_index do |v,i| + result &= check_float(Math.cbrt(v), num[i]) + end + result end - result -end -assert('Math.hypot') do - check_float(Math.hypot(3, 4), 5.0) -end + assert('Math.hypot') do + check_float(Math.hypot(3, 4), 5.0) + end -assert('Math.frexp 1234') do - n = 1234 - fraction, exponent = Math.frexp(n) - check_float(Math.ldexp(fraction, exponent), n) -end + assert('Math.frexp 1234') do + n = 1234 + fraction, exponent = Math.frexp(n) + check_float(Math.ldexp(fraction, exponent), n) + end -assert('Math.erf 1') do - check_float(Math.erf(1), 0.842700792949715) -end + assert('Math.erf 1') do + check_float(Math.erf(1), 0.842700792949715) + end -assert('Math.erfc 1') do - check_float(Math.erfc(1), 0.157299207050285) + assert('Math.erfc 1') do + check_float(Math.erfc(1), 0.157299207050285) + end end + diff --git a/test/t/module.rb b/test/t/module.rb index 854be75a5..5b847e8b7 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -5,6 +5,103 @@ assert('Module', '15.2.2') do Module.class == Class end -# TODO not implemented ATM assert('Module.constants', '15.2.2') do +assert('Module superclass', '15.2.2.2') do + Module.superclass == Object +end + +# TODO not implemented ATM assert('Module.constants', '15.2.2.3.1') do + +# TODO not implemented ATM assert('Module.nesting', '15.2.2.3.2') do + +assert('Module#ancestors', '15.2.2.4.9') do + r = String.ancestors + r.class == Array and r.include?(String) and r.include?(Object) +end + +assert('Module#append_features', '15.2.2.4.10') do + module Test4AppendFeatures + def self.append_features(mod) + Test4AppendFeatures2.const_set(:Const4AppendFeatures2, mod) + end + end + module Test4AppendFeatures2 + include Test4AppendFeatures + end + + Test4AppendFeatures2.const_get(:Const4AppendFeatures2) == Test4AppendFeatures2 +end + +assert('Module#const_defined?', '15.2.2.4.20') do + module Test4ConstDefined + Const4Test4ConstDefined = true + end + + Test4ConstDefined.const_defined?(:Const4Test4ConstDefined) and + not Test4ConstDefined.const_defined?(:NotExisting) +end + +assert('Module#const_get', '15.2.2.4.21') do + module Test4ConstGet + Const4Test4ConstGet = 42 + end + + Test4ConstGet.const_get(:Const4Test4ConstGet) == 42 +end + +assert('Module.const_missing', '15.2.2.4.22') do + e1 = nil -# TODO not implemented ATM assert('Module.nesting', '15.2.2') do + module Test4ConstMissing + def self.const_missing(sym) + 42 # the answer to everything + end + end + + Test4ConstMissing.const_get(:ConstDoesntExist) == 42 +end + +assert('Module#const_get', '15.2.2.4.23') do + module Test4ConstSet + Const4Test4ConstSet = 42 + end + + Test4ConstSet.const_set(:Const4Test4ConstSet, 23) + Test4ConstSet.const_get(:Const4Test4ConstSet) == 23 +end + +assert('Module#include', '15.2.2.4.27') do + module Test4Include + Const4Include = 42 + end + module Test4Include2 + include Test4Include + end + + Test4Include2.const_get(:Const4Include) == 42 +end + +assert('Module#included', '15.2.2.4.29') do + module Test4Included + Const4Included = 42 + def self.included mod + Test4Included.const_set(:Const4Included2, mod) + end + end + module Test4Included2 + include Test4Included + end + + Test4Included2.const_get(:Const4Included) == 42 and + Test4Included2.const_get(:Const4Included2) == Test4Included2 +end + +assert('Module#included_modules', '15.2.2.4.30') do + module Test4includedModules + end + module Test4includedModules2 + include Test4includedModules + end + + r = Test4includedModules2.included_modules + r.class == Array and r.include?(Test4includedModules) +end diff --git a/test/t/nameerror.rb b/test/t/nameerror.rb index 67451ecf8..8e57ac18b 100644 --- a/test/t/nameerror.rb +++ b/test/t/nameerror.rb @@ -5,6 +5,10 @@ assert('NameError', '15.2.31') do NameError.class == Class end +assert('NameError superclass', '15.2.31.2') do + NameError.superclass == StandardError +end + # TODO 15.2.31.2.1 NameError#name assert('NameError#initialize', '15.2.31.2.2') do diff --git a/test/t/nomethoderror.rb b/test/t/nomethoderror.rb index 9eb122158..caab04a41 100644 --- a/test/t/nomethoderror.rb +++ b/test/t/nomethoderror.rb @@ -11,3 +11,8 @@ assert('NoMethodError', '15.2.32') do NoMethodError.class == Class and e2.class == NoMethodError end + +assert('NoMethodError superclass', '15.2.32.2') do + NoMethodError.superclass == NameError +end + diff --git a/test/t/numeric.rb b/test/t/numeric.rb index 924889a0e..3cdb9a8cf 100644 --- a/test/t/numeric.rb +++ b/test/t/numeric.rb @@ -5,6 +5,10 @@ assert('Numeric', '15.2.7') do Numeric.class == Class end +assert('Numeric superclass', '15.2.7.2') do + Numeric.superclass == Object +end + assert('Numeric#+@', '15.2.7.4.1') do +1 == +1 end diff --git a/test/t/object.rb b/test/t/object.rb index 96929031b..7dfaf6589 100644 --- a/test/t/object.rb +++ b/test/t/object.rb @@ -4,3 +4,8 @@ assert('Object', '15.2.1') do Object.class == Class end + +assert('Object superclass', '15.2.1.2') do + Object.superclass == BasicObject +end + diff --git a/test/t/proc.rb b/test/t/proc.rb index 6d98cb40c..c0a1cf90f 100644 --- a/test/t/proc.rb +++ b/test/t/proc.rb @@ -5,6 +5,10 @@ assert('Proc', '15.2.17') do Proc.class == Class end +assert('Proc superclass', '15.2.17.2') do + Proc.superclass == Object +end + assert('Proc.new', '15.2.17.3.1') do a = nil diff --git a/test/t/range.rb b/test/t/range.rb index 05bac8779..691ca7898 100644 --- a/test/t/range.rb +++ b/test/t/range.rb @@ -5,6 +5,10 @@ assert('Range', '15.2.14') do Range.class == Class end +assert('Range superclass', '15.2.14.2') do + Range.superclass == Object +end + assert('Range#==', '15.2.14.4.1') do (1..10) == (1..10) and not (1..10) == (1..100) end diff --git a/test/t/rangeerror.rb b/test/t/rangeerror.rb index 7edb5d2d9..57afdc4bd 100644 --- a/test/t/rangeerror.rb +++ b/test/t/rangeerror.rb @@ -4,3 +4,8 @@ assert('RangeError', '15.2.26') do RangeError.class == Class end + +assert('RangeError superclass', '15.2.26.2') do + RangeError.superclass == StandardError +end + diff --git a/test/t/standarderror.rb b/test/t/standarderror.rb index 550c337c1..3868d7567 100644 --- a/test/t/standarderror.rb +++ b/test/t/standarderror.rb @@ -4,3 +4,8 @@ assert('StandardError', '15.2.23') do StandardError.class == Class end + +assert('StandardError superclass', '15.2.23.2') do + StandardError.superclass == Exception +end + diff --git a/test/t/string.rb b/test/t/string.rb index f38790c17..3338e4318 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -5,6 +5,10 @@ assert('String', '15.2.10') do String.class == Class end +assert('String superclass', '15.2.10.2') do + String.superclass == Object +end + assert('String#*', '15.2.10.5.1') do 'a' * 5 == 'aaaaa' end @@ -252,6 +256,9 @@ assert('String#slice', '15.2.10.5.34') do d1 = 'abc'.slice(0, 0) e1 = 'abc'.slice(1, 2) + # slice of shared string + e11 = e1.slice(0) + # args is RegExp # TODO SEGFAULT ATM @@ -261,16 +268,17 @@ assert('String#slice', '15.2.10.5.34') do a == 'a' and b == 'c' and c == nil and d == nil and a1 == nil and b1 == nil and c1 == nil and d1 == '' and - e1 == 'bc' and + e1 == 'bc' and e11 == 'b' and a3 == 'bc' and b3 == nil end # TODO Broken ATM assert('String#split', '15.2.10.5.35') do # without RegExp behavior is actually unspecified - a = 'abc abc abc'.split - - a == ['abc', 'abc', 'abc'] + 'abc abc abc'.split == ['abc', 'abc', 'abc'] and + 'a,b,c,,d'.split(',') == ["a", "b", "c", "", "d"] and + 'abc abc abc'.split(nil) == ['abc', 'abc', 'abc'] and + 'abc'.split("") == ['a', 'b', 'c'] end # TODO ATM broken assert('String#sub', '15.2.10.5.36') do @@ -319,3 +327,11 @@ assert('String#upcase!', '15.2.10.5.43') do a == 'ABC' end + +# Not ISO specified + +assert('String interpolation (mrb_str_concat for shared strings)') do + a = "A" * 32 + "#{a}:" == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:" +end + diff --git a/test/t/struct.rb b/test/t/struct.rb index c41319f8a..5cf6929b8 100644 --- a/test/t/struct.rb +++ b/test/t/struct.rb @@ -1,6 +1,71 @@ ## # Struct ISO Test -assert('Struct', '15.2.18') do - Struct.class == Class +if Object.const_defined?(:Struct) + assert('Struct', '15.2.18') do + Struct.class == Class + end + + assert('Struct superclass', '15.2.18.2') do + Struct.superclass == Object + end + + assert('Struct.new', '15.2.18.3.1') do + c = Struct.new(:m1, :m2) + c.superclass == Struct and + c.members == [:m1,:m2] + end + + assert('Struct#==', '15.2.18.4.1') do + c = Struct.new(:m1, :m2) + cc1 = c.new(1,2) + cc2 = c.new(1,2) + cc1 == cc2 + end + + assert('Struct#[]', '15.2.18.4.2') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc[:m1] == 1 and cc["m2"] == 2 + end + + assert('Struct#[]=', '15.2.18.4.3') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc[:m1] = 3 + cc[:m1] == 3 + end + + assert('Struct#each', '15.2.18.4.4') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + a = [] + cc.each{|x| + a << x + } + a[0] == 1 and a[1] == 2 + end + + assert('Struct#each_pair', '15.2.18.4.5') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + a = [] + cc.each_pair{|k,v| + a << [k,v] + } + a[0] == [:m1, 1] and a[1] == [:m2, 2] + end + + assert('Struct#members', '15.2.18.4.6') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc.members == [:m1,:m2] + end + + assert('Struct#select', '15.2.18.4.7') do + c = Struct.new(:m1, :m2) + cc = c.new(1,2) + cc.select{|v| v % 2 == 0} == [2] + end end + diff --git a/test/t/symbol.rb b/test/t/symbol.rb index e9c310971..b28573e92 100644 --- a/test/t/symbol.rb +++ b/test/t/symbol.rb @@ -5,6 +5,10 @@ assert('Symbol', '15.2.11') do Symbol.class == Class end +assert('Symbol superclass', '15.2.11.2') do + Symbol.superclass == Object +end + assert('Symbol#===', '15.2.11.3.1') do :abc === :abc and not :abc === :cba end diff --git a/test/t/syntax.rb b/test/t/syntax.rb new file mode 100644 index 000000000..7898a0b7d --- /dev/null +++ b/test/t/syntax.rb @@ -0,0 +1,47 @@ +assert('super', '11.3.4') do + test = false + begin + super + rescue NoMethodError + test = true + end + + class SuperFoo + def foo + true + end + def bar(*a) + a + end + end + class SuperBar < SuperFoo + def foo + super + end + def bar(*a) + super(*a) + end + end + bar = SuperBar.new + test &&= bar.foo + test &&= (bar.bar(1,2,3) == [1,2,3]) + test +end + +assert('yield', '11.3.5') do + begin + yield + rescue LocalJumpError + true + else + false + end +end + +assert('Abbreviated variable assignment', '11.4.2.3.2') do + a ||= 1 + b &&= 1 + c = 1 + c += 2 + a == 1 and b == nil and c == 3 +end diff --git a/test/t/time.rb b/test/t/time.rb index 22fc2e7c3..6140be1a8 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -1,73 +1,191 @@ ## # Time ISO Test -assert('Time', '15.2.19') do - Time.class == Class -end +if Object.const_defined?(:Time) + assert('Time.new', '15.2.3.3.3') do + Time.new.class == Time + end -assert('Time.at', '15.2.19.6.1') do - Time.at(1300000000.0) -end + assert('Time', '15.2.19') do + Time.class == Class + end -assert('Time.gm', '15.2.19.6.2') do - Time.gm(2012, 12, 23) -end + assert('Time superclass', '15.2.19.2') do + Time.superclass == Object + end -assert('Time#asctime', '15.2.19.7.4') do - Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011" -end + assert('Time.at', '15.2.19.6.1') do + Time.at(1300000000.0) + end -assert('Time#initialize_copy', '15.2.19.7.17') do - time_tmp_2 = Time.at(7.0e6) - time_tmp_2.clone == time_tmp_2 -end + assert('Time.gm', '15.2.19.6.2') do + Time.gm(2012, 12, 23) + end -assert('Time#mday', '15.2.19.7.19') do - Time.gm(2012, 12, 23).mday == 23 -end + assert('Time.local', '15.2.19.6.3') do + Time.local(2012, 12, 23) + end -assert('Time#month', '15.2.19.7.22') do - Time.gm(2012, 12, 23).month == 12 -end + assert('Time.mktime', '15.2.19.6.4') do + Time.mktime(2012, 12, 23) + end -assert('Time#to_f', '15.2.19.7.24') do - Time.at(1300000000.0).to_f == 1300000000.0 -end + assert('Time.now', '15.2.19.6.5') do + Time.now.class == Time + end -assert('Time#to_i', '15.2.19.7.25') do - Time.at(1300000000.0).to_i == 1300000000 -end + assert('Time.utc', '15.2.19.6.6') do + Time.utc(2012, 12, 23) + end -assert('Time#usec', '15.2.19.7.26') do - Time.at(1300000000.0).usec == 0 -end + assert('Time#+', '15.2.19.7.1') do + t1 = Time.at(1300000000.0) + t2 = t1.+(60) -assert('Time#utc', '15.2.19.7.27') do - Time.at(1300000000.0).utc -end + t2.utc.asctime == "Sun Mar 13 07:07:40 UTC 2011" + end -assert('Time#utc?', '15.2.19.7.28') do - Time.at(1300000000.0).utc.utc? -end + assert('Time#-', '15.2.19.7.2') do + t1 = Time.at(1300000000.0) + t2 = t1.-(60) -assert('Time#wday', '15.2.19.7.30') do - Time.at(1300000000.0).utc.wday == 0 -end + t2.utc.asctime == "Sun Mar 13 07:05:40 UTC 2011" + end -assert('Time#yday', '15.2.19.7.31') do - Time.at(1300000000.0).utc.yday == 71 -end + assert('Time#<=>', '15.2.19.7.3') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1400000000.0) + t3 = Time.at(1500000000.0) -assert('Time#year', '15.2.19.7.32') do - Time.gm(2012, 12, 23).year == 2012 -end + t2.<=>(t1) == 1 and + t2.<=>(t2) == 0 and + t2.<=>(t3) == -1 and + t2.<=>(nil) == nil + end -assert('Time#zone', '15.2.19.7.33') do - Time.at(1300000000.0).utc.zone == 'UTC' -end + assert('Time#asctime', '15.2.19.7.4') do + Time.at(1300000000.0).utc.asctime == "Sun Mar 13 07:06:40 UTC 2011" + end + + assert('Time#ctime', '15.2.19.7.5') do + Time.at(1300000000.0).utc.ctime == "Sun Mar 13 07:06:40 UTC 2011" + end + + assert('Time#day', '15.2.19.7.6') do + Time.gm(2012, 12, 23).day == 23 + end + + assert('Time#dst?', '15.2.19.7.7') do + not Time.gm(2012, 12, 23).utc.dst? + end + + assert('Time#getgm', '15.2.19.7.8') do + Time.at(1300000000.0).getgm.asctime == "Sun Mar 13 07:06:40 UTC 2011" + end + + assert('Time#getlocal', '15.2.19.7.9') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1300000000.0) + t3 = t1.getlocal + + t1 == t3 and t3 == t2.getlocal + end + + assert('Time#getutc', '15.2.19.7.10') do + Time.at(1300000000.0).getutc.asctime == "Sun Mar 13 07:06:40 UTC 2011" + end -# Not ISO specified + assert('Time#gmt?', '15.2.19.7.11') do + Time.at(1300000000.0).utc.gmt? + end -assert('Time#new') do - Time.new.class == Time + # ATM not implemented + # assert('Time#gmt_offset', '15.2.19.7.12') do + + assert('Time#gmtime', '15.2.19.7.13') do + Time.at(1300000000.0).gmtime + end + + # ATM not implemented + # assert('Time#gmtoff', '15.2.19.7.14') do + + assert('Time#hour', '15.2.19.7.15') do + Time.gm(2012, 12, 23, 7, 6).hour == 7 + end + + # ATM doesn't really work + # assert('Time#initialize', '15.2.19.7.16') do + + assert('Time#initialize_copy', '15.2.19.7.17') do + time_tmp_2 = Time.at(7.0e6) + time_tmp_2.clone == time_tmp_2 + end + + assert('Time#localtime', '15.2.19.7.18') do + t1 = Time.at(1300000000.0) + t2 = Time.at(1300000000.0) + + t1.localtime + t1 == t2.getlocal + end + + assert('Time#mday', '15.2.19.7.19') do + Time.gm(2012, 12, 23).mday == 23 + end + + assert('Time#min', '15.2.19.7.20') do + Time.gm(2012, 12, 23, 7, 6).min == 6 + end + + assert('Time#mon', '15.2.19.7.21') do + Time.gm(2012, 12, 23).mon == 12 + end + + assert('Time#month', '15.2.19.7.22') do + Time.gm(2012, 12, 23).month == 12 + end + + assert('Times#sec', '15.2.19.7.23') do + Time.gm(2012, 12, 23, 7, 6, 40).sec == 40 + end + + assert('Time#to_f', '15.2.19.7.24') do + Time.at(1300000000.0).to_f == 1300000000.0 + end + + assert('Time#to_i', '15.2.19.7.25') do + Time.at(1300000000.0).to_i == 1300000000 + end + + assert('Time#usec', '15.2.19.7.26') do + Time.at(1300000000.0).usec == 0 + end + + assert('Time#utc', '15.2.19.7.27') do + Time.at(1300000000.0).utc + end + + assert('Time#utc?', '15.2.19.7.28') do + Time.at(1300000000.0).utc.utc? + end + + # ATM not implemented + # assert('Time#utc_offset', '15.2.19.7.29') do + + assert('Time#wday', '15.2.19.7.30') do + Time.gm(2012, 12, 23).wday == 0 + end + + assert('Time#yday', '15.2.19.7.31') do + Time.gm(2012, 12, 23).yday == 357 + end + + assert('Time#year', '15.2.19.7.32') do + Time.gm(2012, 12, 23).year == 2012 + end + + assert('Time#zone', '15.2.19.7.33') do + Time.at(1300000000.0).utc.zone == 'UTC' + end end + diff --git a/test/t/true.rb b/test/t/true.rb index bb648a7cd..ae83e0baa 100644 --- a/test/t/true.rb +++ b/test/t/true.rb @@ -5,22 +5,26 @@ assert('TrueClass', '15.2.5') do TrueClass.class == Class end +assert('TrueClass superclass', '15.2.5.2') do + TrueClass.superclass == Object +end + assert('TrueClass true', '15.2.5.1') do true end assert('TrueClass#&', '15.2.5.3.1') do - TrueClass.new.&(true) and not TrueClass.new.&(false) + true.&(true) and not true.&(false) end assert('TrueClass#^', '15.2.5.3.2') do - not TrueClass.new.^(true) and TrueClass.new.^(false) + not true.^(true) and true.^(false) end assert('TrueClass#to_s', '15.2.5.3.3') do - TrueClass.new.to_s == 'true' + true.to_s == 'true' end assert('TrueClass#|', '15.2.5.3.4') do - TrueClass.new.|(true) and TrueClass.new.|(false) + true.|(true) and true.|(false) end diff --git a/test/t/typeerror.rb b/test/t/typeerror.rb index c4434aa24..d48db111a 100644 --- a/test/t/typeerror.rb +++ b/test/t/typeerror.rb @@ -4,3 +4,8 @@ assert('TypeError', '15.2.29') do TypeError.class == Class end + +assert('TypeError superclass', '15.2.29.2') do + TypeError.superclass == StandardError +end + |
