mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge remote-tracking branch 'remotes/mruby/master'
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
MRuby::CrossBuild.new("Arduino Due") do |conf|
|
||||
toolchain :gcc
|
||||
|
||||
# Mac OS X
|
||||
# ARDUINO_PATH = '/Applications/Arduino.app/Contents/Resources/Java'
|
||||
# GNU Linux
|
||||
ARDUINO_PATH = '/opt/arduino'
|
||||
BIN_PATH = "#{ARDUINO_PATH}/hardware/tools/g++_arm_none_eabi/bin"
|
||||
@@ -13,13 +15,29 @@ MRuby::CrossBuild.new("Arduino Due") do |conf|
|
||||
|
||||
conf.cc do |cc|
|
||||
cc.command = "#{BIN_PATH}/arm-none-eabi-gcc"
|
||||
cc.include_paths = ["#{SAM_PATH}/system/libsam -I#{SAM_PATH}/system/CMSIS/CMSIS/Include/",
|
||||
cc.include_paths << ["#{SAM_PATH}/system/libsam -I#{SAM_PATH}/system/CMSIS/CMSIS/Include/",
|
||||
"#{SAM_PATH}/system/CMSIS/Device/ATMEL/",
|
||||
"#{SAM_PATH}/cores/arduino -I#{TARGET_PATH}",
|
||||
"#{MRUBY_ROOT}/include"]
|
||||
cc.flags << '-g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 ' +
|
||||
'-Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=152 -D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON'
|
||||
"#{SAM_PATH}/cores/arduino -I#{TARGET_PATH}"]
|
||||
cc.flags = %w(-g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
|
||||
-Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=152 -D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON)
|
||||
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
|
||||
|
||||
#configuration for low memory environment
|
||||
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
|
||||
cc.defines << %w(MRB_USE_IV_SEGLIST)
|
||||
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
|
||||
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
|
||||
cc.defines << %w(MRB_GC_STRESS)
|
||||
#cc.defines << %w(DISABLE_STDIO) #if you dont need stdio.
|
||||
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
|
||||
end
|
||||
|
||||
conf.cxx do |cxx|
|
||||
cxx.command = conf.cc.command.dup
|
||||
cxx.include_paths = conf.cc.include_paths.dup
|
||||
cxx.flags = conf.cc.flags.dup
|
||||
cxx.defines = conf.cc.defines.dup
|
||||
cxx.compile_options = conf.cc.compile_options.dup
|
||||
end
|
||||
|
||||
conf.archiver do |archiver|
|
||||
@@ -27,4 +45,21 @@ MRuby::CrossBuild.new("Arduino Due") do |conf|
|
||||
archiver.archive_options = 'rcs %{outfile} %{objs}'
|
||||
end
|
||||
|
||||
#no executables
|
||||
conf.bins = []
|
||||
|
||||
#do not build executable test
|
||||
conf.build_mrbtest_lib_only
|
||||
|
||||
#gems from core
|
||||
conf.gem :core => "mruby-print"
|
||||
conf.gem :core => "mruby-math"
|
||||
conf.gem :core => "mruby-enum-ext"
|
||||
|
||||
#light-weight regular expression
|
||||
conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
|
||||
|
||||
#Arduino API
|
||||
#conf.gem :github =>"kyab/mruby-arduino", :branch => "master"
|
||||
|
||||
end
|
||||
|
||||
@@ -9,21 +9,38 @@ MRuby::CrossBuild.new("chipKitMax32") do |conf|
|
||||
toolchain :gcc
|
||||
|
||||
# Mac OS X
|
||||
# MPIDE_PATH = '/Applications/mpide.app/Contents/Resources/Java'
|
||||
# MPIDE_PATH = '/Applications/Mpide.app/Contents/Resources/Java'
|
||||
# GNU Linux
|
||||
MPIDE_PATH = '/opt/mpide-0023-linux-20120903'
|
||||
|
||||
PIC32_PATH = "#{MPIDE_PATH}/hardware/pic32"
|
||||
|
||||
conf.cc do |cc|
|
||||
cc.command="#{PIC32_PATH}/compiler/pic32-tools/bin/pic32-gcc"
|
||||
cc.include_paths = ["#{PIC32_PATH}/cores/pic32",
|
||||
cc.command = "#{PIC32_PATH}/compiler/pic32-tools/bin/pic32-gcc"
|
||||
cc.include_paths << ["#{PIC32_PATH}/cores/pic32",
|
||||
"#{PIC32_PATH}/variants/Max32",
|
||||
"#{MRUBY_ROOT}/include"]
|
||||
cc.flags << "-O2 -mno-smart-io -w -ffunction-sections -fdata-sections -g -mdebugger -Wcast-align " +
|
||||
"-fno-short-double -mprocessor=32MX795F512L -DF_CPU=80000000L -DARDUINO=23 -D_BOARD_MEGA_ " +
|
||||
"-DMPIDEVER=0x01000202 -DMPIDE=23"
|
||||
"#{PIC32_PATH}/libraries"]
|
||||
cc.flags = %w(-O2 -mno-smart-io -w -ffunction-sections -fdata-sections -g -mdebugger -Wcast-align
|
||||
-fno-short-double -mprocessor=32MX795F512L -DF_CPU=80000000L -DARDUINO=23 -D_BOARD_MEGA_
|
||||
-DMPIDEVER=0x01000202 -DMPIDE=23)
|
||||
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
|
||||
|
||||
#configuration for low memory environment
|
||||
cc.defines << %w(MRB_HEAP_PAGE_SIZE=64)
|
||||
cc.defines << %w(MRB_USE_IV_SEGLIST)
|
||||
cc.defines << %w(KHASH_DEFAULT_SIZE=8)
|
||||
cc.defines << %w(MRB_STR_BUF_MIN_SIZE=20)
|
||||
cc.defines << %w(MRB_GC_STRESS)
|
||||
#cc.defines << %w(DISABLE_STDIO) #if you dont need stdio.
|
||||
#cc.defines << %w(POOL_PAGE_SIZE=1000) #effective only for use with mruby-eval
|
||||
end
|
||||
|
||||
conf.cxx do |cxx|
|
||||
cxx.command = conf.cc.command.dup
|
||||
cxx.include_paths = conf.cc.include_paths.dup
|
||||
cxx.flags = conf.cc.flags.dup
|
||||
cxx.defines = conf.cc.defines.dup
|
||||
cxx.compile_options = conf.cc.compile_options.dup
|
||||
end
|
||||
|
||||
conf.archiver do |archiver|
|
||||
@@ -31,4 +48,21 @@ MRuby::CrossBuild.new("chipKitMax32") do |conf|
|
||||
archiver.archive_options = 'rcs %{outfile} %{objs}'
|
||||
end
|
||||
|
||||
#no executables
|
||||
conf.bins = []
|
||||
|
||||
#do not build test executable
|
||||
conf.build_mrbtest_lib_only
|
||||
|
||||
#gems from core
|
||||
conf.gem :core => "mruby-print"
|
||||
conf.gem :core => "mruby-math"
|
||||
conf.gem :core => "mruby-enum-ext"
|
||||
|
||||
#light-weight regular expression
|
||||
conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master"
|
||||
|
||||
#Arduino API
|
||||
#conf.gem :github =>"kyab/mruby-arduino", :branch => "master"
|
||||
|
||||
end
|
||||
|
||||
@@ -105,7 +105,7 @@ static const char *mon_names[] = {
|
||||
};
|
||||
|
||||
static const char *wday_names[] = {
|
||||
"Sun", "Mon", "Tus", "Wed", "Thu", "Fri", "Sat",
|
||||
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
|
||||
};
|
||||
|
||||
struct mrb_time {
|
||||
|
||||
+1
-1
@@ -1168,7 +1168,7 @@ mrb_init_array(mrb_state *mrb)
|
||||
mrb_define_method(mrb, a, "unshift", mrb_ary_unshift_m, MRB_ARGS_ANY()); /* 15.2.12.5.30 */
|
||||
|
||||
mrb_define_method(mrb, a, "inspect", mrb_ary_inspect, MRB_ARGS_NONE()); /* 15.2.12.5.31 (x) */
|
||||
mrb_define_alias(mrb, a, "to_s", "inspect"); /* 15.2.12.5.32 (x) */
|
||||
mrb_define_alias(mrb, a, "to_s", "inspect"); /* 15.2.12.5.32 (x) */
|
||||
mrb_define_method(mrb, a, "==", mrb_ary_equal, MRB_ARGS_REQ(1)); /* 15.2.12.5.33 (x) */
|
||||
mrb_define_method(mrb, a, "eql?", mrb_ary_eql, MRB_ARGS_REQ(1)); /* 15.2.12.5.34 (x) */
|
||||
mrb_define_method(mrb, a, "<=>", mrb_ary_cmp, MRB_ARGS_REQ(1)); /* 15.2.12.5.36 (x) */
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "mruby.h"
|
||||
#include "mruby/array.h"
|
||||
#include "mruby/class.h"
|
||||
|
||||
+7
-2
@@ -539,7 +539,9 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
|
||||
size_t sirep;
|
||||
struct rite_section_header section_header;
|
||||
long fpos;
|
||||
const size_t block_size = 1 << 14;
|
||||
size_t block_size = 1 << 14;
|
||||
const uint8_t block_fallback_count = 4;
|
||||
int i;
|
||||
const size_t buf_size = sizeof(struct rite_binary_header);
|
||||
|
||||
if ((mrb == NULL) || (fp == NULL)) {
|
||||
@@ -564,7 +566,10 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
|
||||
/* verify CRC */
|
||||
fpos = ftell(fp);
|
||||
/* You don't need use SIZE_ERROR as block_size is enough small. */
|
||||
buf = mrb_malloc(mrb, block_size);
|
||||
for (i = 0; i < block_fallback_count; i++,block_size >>= 1){
|
||||
buf = mrb_malloc(mrb, block_size);
|
||||
if (buf) break;
|
||||
}
|
||||
if (!buf) {
|
||||
return MRB_DUMP_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
+3
-11
@@ -104,10 +104,9 @@ mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len)
|
||||
mrb_str_modify(mrb, s);
|
||||
slen = s->len;
|
||||
if (len != slen) {
|
||||
if (slen < len || slen -len > 1024) {
|
||||
s->ptr = (char *)mrb_realloc(mrb, s->ptr, len+1);
|
||||
if (slen < len || slen - len > 256) {
|
||||
RESIZE_CAPA(s, len);
|
||||
}
|
||||
s->aux.capa = len;
|
||||
s->len = len;
|
||||
s->ptr[len] = '\0'; /* sentinel */
|
||||
}
|
||||
@@ -261,14 +260,7 @@ mrb_str_new_cstr(mrb_state *mrb, const char *p)
|
||||
len = 0;
|
||||
}
|
||||
|
||||
s = mrb_obj_alloc_string(mrb);
|
||||
s->ptr = (char *)mrb_malloc(mrb, len+1);
|
||||
if (p) {
|
||||
memcpy(s->ptr, p, len);
|
||||
}
|
||||
s->ptr[len] = 0;
|
||||
s->len = (mrb_int)len;
|
||||
s->aux.capa = (mrb_int)len;
|
||||
s = str_new(mrb, p, len);
|
||||
|
||||
return mrb_obj_value(s);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ module MRuby
|
||||
instance_eval(&@build_config_initializer) if @build_config_initializer
|
||||
|
||||
compilers.each do |compiler|
|
||||
compiler.define_rules build_dir, "#{dir}/"
|
||||
compiler.define_rules build_dir, "#{dir}"
|
||||
end
|
||||
|
||||
define_gem_init_builder
|
||||
|
||||
+35
-2
@@ -62,7 +62,7 @@ def assert(str = 'Assertion failed', iso = '')
|
||||
$asserts.push(assertion_string('Error: ', str, iso, e))
|
||||
$kill_test += 1
|
||||
t_print('X')
|
||||
end
|
||||
end
|
||||
ensure
|
||||
$mrbtest_assert = nil
|
||||
end
|
||||
@@ -99,12 +99,30 @@ def assert_false(ret, msg = nil, diff = nil)
|
||||
!ret
|
||||
end
|
||||
|
||||
def assert_equal(exp, act, msg = nil)
|
||||
def assert_equal(arg1, arg2 = nil, arg3 = nil)
|
||||
if block_given?
|
||||
exp, act, msg = yield, arg1, arg2
|
||||
else
|
||||
exp, act, msg = arg1, arg2, arg3
|
||||
end
|
||||
|
||||
msg = "Expected to be equal" unless msg
|
||||
diff = assertion_diff(exp, act)
|
||||
assert_true(exp == act, msg, diff)
|
||||
end
|
||||
|
||||
def assert_not_equal(arg1, arg2 = nil, arg3 = nil)
|
||||
if block_given?
|
||||
exp, act, msg = yield, arg1, arg2
|
||||
else
|
||||
exp, act, msg = arg1, arg2, arg3
|
||||
end
|
||||
|
||||
msg = "Expected to be not equal" unless msg
|
||||
diff = assertion_diff(exp, act)
|
||||
assert_false(exp == act, msg, diff)
|
||||
end
|
||||
|
||||
def assert_nil(obj, msg = nil)
|
||||
msg = "Expected #{obj.inspect} to be nil" unless msg
|
||||
diff = assertion_diff(nil, obj)
|
||||
@@ -118,6 +136,13 @@ def assert_include(collection, obj, msg = nil)
|
||||
assert_true(collection.include?(obj), msg, diff)
|
||||
end
|
||||
|
||||
def assert_not_include(collection, obj, msg = nil)
|
||||
msg = "Expected #{collection.inspect} to not include #{obj.inspect}" unless msg
|
||||
diff = " Collection: #{collection.inspect}\n" +
|
||||
" Object: #{obj.inspect}"
|
||||
assert_false(collection.include?(obj), msg, diff)
|
||||
end
|
||||
|
||||
def assert_raise(*exp)
|
||||
ret = true
|
||||
if $mrbtest_assert
|
||||
@@ -156,6 +181,14 @@ def assert_kind_of(cls, obj, msg = nil)
|
||||
assert_true(obj.kind_of?(cls), msg, diff)
|
||||
end
|
||||
|
||||
##
|
||||
# Fails unless +exp+ is equal to +act+ in terms of a Float
|
||||
def assert_float(exp, act, msg = nil)
|
||||
msg = "Float #{exp} expected to be equal to float #{act}" unless msg
|
||||
diff = assertion_diff(exp, act)
|
||||
assert_true check_float(exp, act), msg, diff
|
||||
end
|
||||
|
||||
##
|
||||
# Report the test result and print all assertions
|
||||
# which were reported broken.
|
||||
|
||||
@@ -11,10 +11,11 @@ assert('ArgumentError', '15.2.24') do
|
||||
e2 = e1
|
||||
end
|
||||
|
||||
ArgumentError.class == Class and e2.class == ArgumentError
|
||||
assert_equal(ArgumentError.class, Class)
|
||||
assert_equal(e2.class, ArgumentError)
|
||||
end
|
||||
|
||||
assert('ArgumentError superclass', '15.2.24.2') do
|
||||
ArgumentError.superclass == StandardError
|
||||
assert_equal(ArgumentError.superclass, StandardError)
|
||||
end
|
||||
|
||||
|
||||
+79
-91
@@ -2,156 +2,129 @@
|
||||
# Array ISO Test
|
||||
|
||||
assert('Array', '15.2.12') do
|
||||
Array.class == Class
|
||||
assert_equal(Array.class, Class)
|
||||
end
|
||||
|
||||
assert('Array superclass', '15.2.12.2') do
|
||||
Array.superclass == Object
|
||||
assert_equal(Array.superclass, Object)
|
||||
end
|
||||
|
||||
assert('Array.[]', '15.2.12.4.1') do
|
||||
Array.[](1,2,3) == [1, 2, 3]
|
||||
assert_equal(Array.[](1,2,3), [1, 2, 3])
|
||||
end
|
||||
|
||||
assert('Array#*', '15.2.12.5.1') do
|
||||
e2 = nil
|
||||
begin
|
||||
assert_raise(ArgumentError) do
|
||||
# this will cause an exception due to the wrong argument
|
||||
[1].*(-1)
|
||||
rescue => e1
|
||||
e2 = e1
|
||||
end
|
||||
a = [1].*(3)
|
||||
b = [1].*(0)
|
||||
a == [1, 1, 1] and b == [] and
|
||||
e2.class == ArgumentError
|
||||
assert_equal([1].*(3), [1, 1, 1])
|
||||
assert_equal([1].*(0), [])
|
||||
end
|
||||
|
||||
assert('Array#+', '15.2.12.5.2') do
|
||||
[1].+([1]) == [1, 1]
|
||||
assert_equal([1].+([1]), [1, 1])
|
||||
end
|
||||
|
||||
assert('Array#<<', '15.2.12.5.3') do
|
||||
[1].<<(1) == [1, 1]
|
||||
assert_equal([1].<<(1), [1, 1])
|
||||
end
|
||||
|
||||
assert('Array#[]', '15.2.12.5.4') do
|
||||
e2 = nil
|
||||
e3 = nil
|
||||
a = Array.new
|
||||
begin
|
||||
assert_raise(ArgumentError) do
|
||||
# this will cause an exception due to the wrong arguments
|
||||
a.[]()
|
||||
rescue => e1
|
||||
e2 = e1
|
||||
end
|
||||
begin
|
||||
assert_raise(ArgumentError) do
|
||||
# this will cause an exception due to the wrong arguments
|
||||
a.[](1,2,3)
|
||||
rescue => e1
|
||||
e3 = e1
|
||||
end
|
||||
|
||||
[1,2,3].[](1) == 2 and
|
||||
e2.class == ArgumentError and
|
||||
e3.class == ArgumentError
|
||||
assert_equal([1,2,3].[](1), 2)
|
||||
end
|
||||
|
||||
assert('Array#[]=', '15.2.12.5.5') do
|
||||
e2 = nil
|
||||
e3 = nil
|
||||
a = Array.new
|
||||
begin
|
||||
assert_raise(ArgumentError) do
|
||||
# this will cause an exception due to the wrong arguments
|
||||
a.[]=()
|
||||
rescue => e1
|
||||
e2 = e1
|
||||
end
|
||||
begin
|
||||
assert_raise(ArgumentError) do
|
||||
# this will cause an exception due to the wrong arguments
|
||||
a.[]=(1,2,3,4)
|
||||
rescue => e1
|
||||
e3 = e1
|
||||
end
|
||||
|
||||
[1,2,3].[]=(1,4) == 4 and
|
||||
[1,2,3].[]=(1,2,3) == 3 and
|
||||
e2.class == ArgumentError and
|
||||
e3.class == ArgumentError
|
||||
assert_equal([1,2,3].[]=(1,4), 4)
|
||||
assert_equal([1,2,3].[]=(1,2,3), 3)
|
||||
end
|
||||
|
||||
assert('Array#clear', '15.2.12.5.6') do
|
||||
a = [1]
|
||||
a.clear
|
||||
a == []
|
||||
assert_equal(a, [])
|
||||
end
|
||||
|
||||
assert('Array#collect!', '15.2.12.5.7') do
|
||||
a = [1,2,3]
|
||||
a.collect! { |i| i + i }
|
||||
a == [2,4,6]
|
||||
assert_equal(a, [2,4,6])
|
||||
end
|
||||
|
||||
assert('Array#concat', '15.2.12.5.8') do
|
||||
a = [1,2]
|
||||
b = [3,4]
|
||||
a.concat(b) == [1,2,3,4]
|
||||
assert_equal([1, 2].concat([3, 4]), [1,2,3,4])
|
||||
end
|
||||
|
||||
assert('Array#delete_at', '15.2.12.5.9') do
|
||||
a = [1,2,3]
|
||||
a.delete_at(1)
|
||||
a == [1,3]
|
||||
assert_equal(a, [1,3])
|
||||
end
|
||||
|
||||
assert('Array#each', '15.2.12.5.10') do
|
||||
a = [1,2,3]
|
||||
b = 0
|
||||
a.each {|i| b += i}
|
||||
b == 6
|
||||
assert_equal(b, 6)
|
||||
end
|
||||
|
||||
assert('Array#each_index', '15.2.12.5.11') do
|
||||
a = [1]
|
||||
b = nil
|
||||
a.each_index {|i| b = i}
|
||||
b == 0
|
||||
assert_equal(b, 0)
|
||||
end
|
||||
|
||||
assert('Array#empty?', '15.2.12.5.12') do
|
||||
a = []
|
||||
b = [b]
|
||||
a.empty? and not b.empty?
|
||||
assert_true([].empty?)
|
||||
assert_false([1].empty?)
|
||||
end
|
||||
|
||||
assert('Array#first', '15.2.12.5.13') do
|
||||
a = []
|
||||
b = [1,2,3]
|
||||
|
||||
e2 = nil
|
||||
e3 = nil
|
||||
begin
|
||||
assert_raise(ArgumentError) do
|
||||
# this will cause an exception due to the wrong argument
|
||||
[1,2,3].first(-1)
|
||||
rescue => e1
|
||||
e2 = e1
|
||||
end
|
||||
begin
|
||||
assert_raise(ArgumentError) do
|
||||
# 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
|
||||
assert_nil([].first)
|
||||
|
||||
b = [1,2,3]
|
||||
assert_equal(b.first, 1)
|
||||
assert_equal(b.first(0), [])
|
||||
assert_equal(b.first(1), [1])
|
||||
assert_equal(b.first(4), [1,2,3])
|
||||
end
|
||||
|
||||
assert('Array#index', '15.2.12.5.14') do
|
||||
a = [1,2,3]
|
||||
|
||||
a.index(2) == 1
|
||||
assert_equal(a.index(2), 1)
|
||||
end
|
||||
|
||||
assert('Array#initialize', '15.2.12.5.15') do
|
||||
@@ -160,107 +133,117 @@ assert('Array#initialize', '15.2.12.5.15') do
|
||||
c = [].initialize(2, 1)
|
||||
d = [].initialize(2) {|i| i}
|
||||
|
||||
a == [nil] and b == [nil,nil] and c == [1,1] and d == [0,1]
|
||||
assert_equal(a, [nil])
|
||||
assert_equal(b, [nil,nil])
|
||||
assert_equal(c, [1,1])
|
||||
assert_equal(d, [0,1])
|
||||
end
|
||||
|
||||
assert('Array#initialize_copy', '15.2.12.5.16') do
|
||||
a = [1,2,3]
|
||||
b = [].initialize_copy(a)
|
||||
|
||||
b == [1,2,3]
|
||||
assert_equal(b, [1,2,3])
|
||||
end
|
||||
|
||||
assert('Array#join', '15.2.12.5.17') do
|
||||
a = [1,2,3].join
|
||||
b = [1,2,3].join(',')
|
||||
|
||||
a == '123' and b == '1,2,3'
|
||||
assert_equal(a, '123')
|
||||
assert_equal(b, '1,2,3')
|
||||
end
|
||||
|
||||
assert('Array#last', '15.2.12.5.18') do
|
||||
a = [1,2,3]
|
||||
|
||||
e2 = nil
|
||||
begin
|
||||
assert_raise(ArgumentError) do
|
||||
# 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
|
||||
a = [1,2,3]
|
||||
assert_equal(a.last, 3)
|
||||
assert_nil([].last)
|
||||
end
|
||||
|
||||
assert('Array#length', '15.2.12.5.19') do
|
||||
a = [1,2,3]
|
||||
|
||||
a.length == 3
|
||||
assert_equal(a.length, 3)
|
||||
end
|
||||
|
||||
assert('Array#map!', '15.2.12.5.20') do
|
||||
a = [1,2,3]
|
||||
a.map! { |i| i + i }
|
||||
a == [2,4,6]
|
||||
assert_equal(a, [2,4,6])
|
||||
end
|
||||
|
||||
assert('Array#pop', '15.2.12.5.21') do
|
||||
a = [1,2,3]
|
||||
b = a.pop
|
||||
|
||||
[].pop == nil and a == [1,2] and b = 3
|
||||
assert_nil([].pop)
|
||||
assert_equal(a, [1,2])
|
||||
assert_equal(b, 3)
|
||||
end
|
||||
|
||||
assert('Array#push', '15.2.12.5.22') do
|
||||
a = [1,2,3]
|
||||
b = a.push(4)
|
||||
|
||||
a == [1,2,3,4] and b = [1,2,3,4]
|
||||
assert_equal(a, [1,2,3,4])
|
||||
assert_equal(b, [1,2,3,4])
|
||||
end
|
||||
|
||||
assert('Array#replace', '15.2.12.5.23') do
|
||||
a = [1,2,3]
|
||||
b = [].replace(a)
|
||||
|
||||
b == [1,2,3]
|
||||
assert_equal(b, [1,2,3])
|
||||
end
|
||||
|
||||
assert('Array#reverse', '15.2.12.5.24') do
|
||||
a = [1,2,3]
|
||||
b = a.reverse
|
||||
|
||||
a == [1,2,3] and b == [3,2,1]
|
||||
assert_equal(a, [1,2,3])
|
||||
assert_equal(b, [3,2,1])
|
||||
end
|
||||
|
||||
assert('Array#reverse!', '15.2.12.5.25') do
|
||||
a = [1,2,3]
|
||||
b = a.reverse!
|
||||
|
||||
a == [3,2,1] and b == [3,2,1]
|
||||
assert_equal(a, [3,2,1])
|
||||
assert_equal(b, [3,2,1])
|
||||
end
|
||||
|
||||
assert('Array#rindex', '15.2.12.5.26') do
|
||||
a = [1,2,3]
|
||||
|
||||
a.rindex(2) == 1
|
||||
assert_equal(a.rindex(2), 1)
|
||||
end
|
||||
|
||||
assert('Array#shift', '15.2.12.5.27') do
|
||||
a = [1,2,3]
|
||||
b = a.shift
|
||||
|
||||
[].shift == nil and a == [2,3] and b == 1
|
||||
assert_nil([].shift)
|
||||
assert_equal(a, [2,3])
|
||||
assert_equal(b, 1)
|
||||
end
|
||||
|
||||
assert('Array#size', '15.2.12.5.28') do
|
||||
a = [1,2,3]
|
||||
|
||||
a.size == 3
|
||||
assert_equal(a.size, 3)
|
||||
end
|
||||
|
||||
assert('Array#slice', '15.2.12.5.29') do
|
||||
a = "12345".slice(1, 3)
|
||||
b = a.slice(0)
|
||||
"#{b}:" == "2:" and [1,2,3].[](1) == 2
|
||||
|
||||
assert_equal("#{b}:", "2:")
|
||||
assert_equal([1,2,3].[](1), 2)
|
||||
end
|
||||
|
||||
assert('Array#unshift', '15.2.12.5.30') do
|
||||
@@ -269,7 +252,10 @@ assert('Array#unshift', '15.2.12.5.30') do
|
||||
c = [2,3]
|
||||
d = c.unshift(0, 1)
|
||||
|
||||
a == [1,2,3] and b == [1,2,3] and c == [0,1,2,3] and d == [0,1,2,3]
|
||||
assert_equal(a, [1,2,3])
|
||||
assert_equal(b, [1,2,3])
|
||||
assert_equal(c, [0,1,2,3])
|
||||
assert_equal(d, [0,1,2,3])
|
||||
end
|
||||
|
||||
assert('Array#to_s', '15.2.12.5.31 / 15.2.12.5.32') do
|
||||
@@ -277,15 +263,14 @@ assert('Array#to_s', '15.2.12.5.31 / 15.2.12.5.32') do
|
||||
r1 = a.to_s
|
||||
r2 = a.inspect
|
||||
|
||||
r1 == r2 and r1 == "[2, 3, 4, 5]"
|
||||
assert_equal(r1, r2)
|
||||
assert_equal(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
|
||||
assert_false(["a", "c"] == ["a", "c", 7])
|
||||
assert_true(["a", "c", 7] == ["a", "c", 7])
|
||||
assert_false(["a", "c", 7] == ["a", "d", "f"])
|
||||
end
|
||||
|
||||
assert('Array#eql?', '15.2.12.5.34') do
|
||||
@@ -293,13 +278,14 @@ assert('Array#eql?', '15.2.12.5.34') do
|
||||
a2 = [ 1, 2, 3 ]
|
||||
a3 = [ 1.0, 2.0, 3.0 ]
|
||||
|
||||
(a1.eql? a2) and (not a1.eql? a3)
|
||||
assert_true(a1.eql? a2)
|
||||
assert_false(a1.eql? a3)
|
||||
end
|
||||
|
||||
assert('Array#hash', '15.2.12.5.35') do
|
||||
a = [ 1, 2, 3 ]
|
||||
|
||||
a.hash.is_a? Integer
|
||||
assert_true(a.hash.is_a? Integer)
|
||||
end
|
||||
|
||||
assert('Array#<=>', '15.2.12.5.36') do
|
||||
@@ -307,7 +293,9 @@ assert('Array#<=>', '15.2.12.5.36') do
|
||||
r2 = [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1
|
||||
r3 = [ "a", "b", "c" ] <=> [ "a", "b", "c" ] #=> 0
|
||||
|
||||
r1 == -1 and r2 == +1 and r3 == 0
|
||||
assert_equal(r1, -1)
|
||||
assert_equal(r2, +1)
|
||||
assert_equal(r3, 0)
|
||||
end
|
||||
|
||||
# Not ISO specified
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
# BasicObject
|
||||
|
||||
assert('BasicObject') do
|
||||
BasicObject.class == Class
|
||||
assert_equal(BasicObject.class, Class)
|
||||
end
|
||||
|
||||
assert('BasicObject superclass') do
|
||||
BasicObject.superclass == nil
|
||||
assert_nil(BasicObject.superclass)
|
||||
end
|
||||
|
||||
|
||||
+157
-108
@@ -2,17 +2,19 @@
|
||||
# Bootstrap tests for blocks
|
||||
|
||||
assert('BS Block 1') do
|
||||
1.times{
|
||||
begin
|
||||
a = 1
|
||||
ensure
|
||||
foo = nil
|
||||
end
|
||||
} == 1
|
||||
assert_equal(1) do
|
||||
1.times{
|
||||
begin
|
||||
a = 1
|
||||
ensure
|
||||
foo = nil
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 2') do
|
||||
[1,2,3].find{|x| x == 2} == 2
|
||||
assert_equal [1,2,3].find{|x| x == 2}, 2
|
||||
end
|
||||
|
||||
assert('BS Block 3') do
|
||||
@@ -22,7 +24,7 @@ assert('BS Block 3') do
|
||||
[1, 2, 3].each(&block)
|
||||
end
|
||||
end
|
||||
E.new.find {|x| x == 2 } == 2
|
||||
assert_equal E.new.find {|x| x == 2 }, 2
|
||||
end
|
||||
|
||||
assert('BS Block 3') do
|
||||
@@ -30,7 +32,7 @@ assert('BS Block 3') do
|
||||
for x in [1, 2, 3]
|
||||
sum += x
|
||||
end
|
||||
sum == 6
|
||||
assert_equal sum, 6
|
||||
end
|
||||
|
||||
assert('BS Block 4') do
|
||||
@@ -38,7 +40,7 @@ assert('BS Block 4') do
|
||||
for x in (1..5)
|
||||
sum += x
|
||||
end
|
||||
sum == 15
|
||||
assert_equal sum, 15
|
||||
end
|
||||
|
||||
assert('BS Block 5') do
|
||||
@@ -46,37 +48,43 @@ assert('BS Block 5') do
|
||||
for x in []
|
||||
sum += x
|
||||
end
|
||||
sum == 0
|
||||
assert_equal sum, 0
|
||||
end
|
||||
|
||||
assert('BS Block 6') do
|
||||
ans = []
|
||||
1.times{
|
||||
for n in 1..3
|
||||
a = n
|
||||
ans << a
|
||||
end
|
||||
} == 1
|
||||
assert_equal(1) do
|
||||
1.times{
|
||||
for n in 1..3
|
||||
a = n
|
||||
ans << a
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 7') do
|
||||
ans = []
|
||||
for m in 1..3
|
||||
for n in 2..4
|
||||
a = [m, n]
|
||||
ans << a
|
||||
assert_equal((1..3)) do
|
||||
for m in 1..3
|
||||
for n in 2..4
|
||||
a = [m, n]
|
||||
ans << a
|
||||
end
|
||||
end
|
||||
end == (1..3)
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 8') do
|
||||
(1..3).to_a == [1, 2, 3]
|
||||
assert_equal (1..3).to_a, [1, 2, 3]
|
||||
end
|
||||
|
||||
assert('BS Block 9') do
|
||||
(1..3).map{|e|
|
||||
e * 4
|
||||
} == [4, 8, 12]
|
||||
assert_equal([4, 8, 12]) do
|
||||
(1..3).map{|e|
|
||||
e * 4
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 10') do
|
||||
@@ -87,11 +95,13 @@ assert('BS Block 10') do
|
||||
yield
|
||||
end
|
||||
|
||||
m{
|
||||
n{
|
||||
100
|
||||
assert_equal(100) do
|
||||
m{
|
||||
n{
|
||||
100
|
||||
}
|
||||
}
|
||||
} == 100
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 11') do
|
||||
@@ -99,11 +109,13 @@ assert('BS Block 11') do
|
||||
yield 1
|
||||
end
|
||||
|
||||
m{|ib|
|
||||
m{|jb|
|
||||
i = 20
|
||||
assert_equal(20) do
|
||||
m{|ib|
|
||||
m{|jb|
|
||||
i = 20
|
||||
}
|
||||
}
|
||||
} == 20
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 12') do
|
||||
@@ -111,12 +123,14 @@ assert('BS Block 12') do
|
||||
yield 1
|
||||
end
|
||||
|
||||
m{|ib|
|
||||
m{|jb|
|
||||
ib = 20
|
||||
kb = 2
|
||||
assert_equal(2) do
|
||||
m{|ib|
|
||||
m{|jb|
|
||||
ib = 20
|
||||
kb = 2
|
||||
}
|
||||
}
|
||||
} == 2
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 13') do
|
||||
@@ -130,13 +144,15 @@ assert('BS Block 13') do
|
||||
yield
|
||||
end
|
||||
|
||||
iter1{
|
||||
jb = 2
|
||||
assert_equal(3) do
|
||||
iter1{
|
||||
jb = 3
|
||||
jb = 2
|
||||
iter1{
|
||||
jb = 3
|
||||
}
|
||||
jb
|
||||
}
|
||||
jb
|
||||
} == 3
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 14') do
|
||||
@@ -150,31 +166,37 @@ assert('BS Block 14') do
|
||||
yield
|
||||
end
|
||||
|
||||
iter1{
|
||||
jb = 2
|
||||
assert_equal(2) do
|
||||
iter1{
|
||||
jb = 2
|
||||
iter1{
|
||||
jb
|
||||
}
|
||||
jb
|
||||
}
|
||||
jb
|
||||
} == 2
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 15') do
|
||||
def m
|
||||
yield 1
|
||||
end
|
||||
m{|ib|
|
||||
ib*2
|
||||
} == 2
|
||||
assert_equal(2) do
|
||||
m{|ib|
|
||||
ib*2
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 16') do
|
||||
def m
|
||||
yield 12345, 67890
|
||||
end
|
||||
m{|ib,jb|
|
||||
ib*2+jb
|
||||
} == 92580
|
||||
assert_equal(92580) do
|
||||
m{|ib,jb|
|
||||
ib*2+jb
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 17') do
|
||||
@@ -183,9 +205,11 @@ assert('BS Block 17') do
|
||||
end
|
||||
|
||||
a = nil
|
||||
[iter{|a|
|
||||
a
|
||||
}, a] == [10, nil]
|
||||
assert_equal [10, nil] do
|
||||
[iter{|a|
|
||||
a
|
||||
}, a]
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 18') do
|
||||
@@ -193,11 +217,13 @@ assert('BS Block 18') do
|
||||
yield 10
|
||||
end
|
||||
|
||||
iter{|a|
|
||||
assert_equal(21) do
|
||||
iter{|a|
|
||||
a + 1
|
||||
} + a
|
||||
} == 21
|
||||
iter{|a|
|
||||
a + 1
|
||||
} + a
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 19') do
|
||||
@@ -206,9 +232,11 @@ assert('BS Block 19') do
|
||||
end
|
||||
|
||||
a = b = c = d = nil
|
||||
iter{|a, b, c, d|
|
||||
[a, b, c, d]
|
||||
} + [a, b, c, d] == [10, 20, 30, 40, nil, nil, nil, nil]
|
||||
assert_equal([10, 20, 30, 40, nil, nil, nil, nil]) do
|
||||
iter{|a, b, c, d|
|
||||
[a, b, c, d]
|
||||
} + [a, b, c, d]
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 20') do
|
||||
@@ -217,9 +245,11 @@ assert('BS Block 20') do
|
||||
end
|
||||
|
||||
a = b = nil
|
||||
iter{|a, b, c, d|
|
||||
[a, b, c, d]
|
||||
} + [a, b] == [10, 20, 30, 40, nil, nil]
|
||||
assert_equal([10, 20, 30, 40, nil, nil]) do
|
||||
iter{|a, b, c, d|
|
||||
[a, b, c, d]
|
||||
} + [a, b]
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 21') do
|
||||
@@ -227,9 +257,11 @@ assert('BS Block 21') do
|
||||
yield 1, 2
|
||||
end
|
||||
|
||||
iter{|a, *b|
|
||||
[a, b]
|
||||
} == [1, [2]]
|
||||
assert_equal([1, [2]]) do
|
||||
iter{|a, *b|
|
||||
[a, b]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 22') do
|
||||
@@ -237,9 +269,11 @@ assert('BS Block 22') do
|
||||
yield 1, 2
|
||||
end
|
||||
|
||||
iter{|*a|
|
||||
[a]
|
||||
} == [[1, 2]]
|
||||
assert_equal([[1, 2]]) do
|
||||
iter{|*a|
|
||||
[a]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 23') do
|
||||
@@ -247,40 +281,48 @@ assert('BS Block 23') do
|
||||
yield 1, 2
|
||||
end
|
||||
|
||||
iter{|a, b, *c|
|
||||
[a, b, c]
|
||||
} == [1, 2, []]
|
||||
assert_equal([1, 2, []]) do
|
||||
iter{|a, b, *c|
|
||||
[a, b, c]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 24') do
|
||||
def m
|
||||
yield
|
||||
end
|
||||
m{
|
||||
1
|
||||
} == 1
|
||||
assert_equal(1) do
|
||||
m{
|
||||
1
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 25') do
|
||||
def m
|
||||
yield 123
|
||||
end
|
||||
m{|ib|
|
||||
m{|jb|
|
||||
ib*jb
|
||||
assert_equal(15129) do
|
||||
m{|ib|
|
||||
m{|jb|
|
||||
ib*jb
|
||||
}
|
||||
}
|
||||
} == 15129
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 26') do
|
||||
def m a
|
||||
yield a
|
||||
end
|
||||
m(1){|ib|
|
||||
m(2){|jb|
|
||||
ib*jb
|
||||
assert_equal(2) do
|
||||
m(1){|ib|
|
||||
m(2){|jb|
|
||||
ib*jb
|
||||
}
|
||||
}
|
||||
} == 2
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 27') do
|
||||
@@ -289,13 +331,15 @@ assert('BS Block 27') do
|
||||
2.times{|jb|
|
||||
sum += ib + jb
|
||||
}}
|
||||
sum == 9
|
||||
assert_equal sum, 9
|
||||
end
|
||||
|
||||
assert('BS Block 28') do
|
||||
3.times{|bl|
|
||||
break 10
|
||||
} == 10
|
||||
assert_equal(10) do
|
||||
3.times{|bl|
|
||||
break 10
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 29') do
|
||||
@@ -303,9 +347,11 @@ assert('BS Block 29') do
|
||||
yield 1,2,3
|
||||
end
|
||||
|
||||
iter{|i, j|
|
||||
[i, j]
|
||||
} == [1, 2]
|
||||
assert_equal([1, 2]) do
|
||||
iter{|i, j|
|
||||
[i, j]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block 30') do
|
||||
@@ -313,23 +359,25 @@ assert('BS Block 30') do
|
||||
yield 1
|
||||
end
|
||||
|
||||
iter{|i, j|
|
||||
[i, j]
|
||||
} == [1, nil]
|
||||
assert_equal([1, nil]) do
|
||||
iter{|i, j|
|
||||
[i, j]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
assert('BS Block [ruby-dev:31147]') do
|
||||
def m
|
||||
yield
|
||||
end
|
||||
m{|&b| b} == nil
|
||||
assert_nil m{|&b| b}
|
||||
end
|
||||
|
||||
assert('BS Block [ruby-dev:31160]') do
|
||||
def m()
|
||||
yield
|
||||
end
|
||||
m {|(v,(*))|} == nil
|
||||
assert_nil m {|(v,(*))|}
|
||||
end
|
||||
|
||||
assert('BS Block [issue #750]') do
|
||||
@@ -337,25 +385,26 @@ assert('BS Block [issue #750]') do
|
||||
yield
|
||||
end
|
||||
args = [1, 2, 3]
|
||||
m(*args){ 1 } == 1
|
||||
assert_equal m(*args){ 1 }, 1
|
||||
end
|
||||
|
||||
assert('BS Block 31') do
|
||||
def m()
|
||||
yield
|
||||
end
|
||||
m {|((*))|} == nil
|
||||
assert_nil m {|((*))|}
|
||||
end
|
||||
|
||||
assert('BS Block [ruby-dev:31440]') do
|
||||
def m
|
||||
yield [0]
|
||||
end
|
||||
m{|v, &b| v} == [0]
|
||||
assert_equal m{|v, &b| v}, [0]
|
||||
end
|
||||
|
||||
assert('BS Block 32') do
|
||||
r = false; 1.times{|&b| r = b}; r.class == NilClass
|
||||
r = false; 1.times{|&b| r = b}
|
||||
assert_equal r.class, NilClass
|
||||
end
|
||||
|
||||
assert('BS Block [ruby-core:14395]') do
|
||||
@@ -394,7 +443,7 @@ assert('BS Block [ruby-core:14395]') do
|
||||
end
|
||||
end
|
||||
t = Controller.new
|
||||
t.test_for_bug
|
||||
assert_true t.test_for_bug
|
||||
end
|
||||
|
||||
assert("BS Block 33") do
|
||||
@@ -408,7 +457,7 @@ assert("BS Block 33") do
|
||||
:bad
|
||||
end
|
||||
end
|
||||
TestReturnFromNestedBlock.test == :ok
|
||||
assert_equal TestReturnFromNestedBlock.test, :ok
|
||||
end
|
||||
|
||||
assert("BS Block 34") do
|
||||
@@ -422,7 +471,7 @@ assert("BS Block 34") do
|
||||
:bad
|
||||
end
|
||||
end
|
||||
TestReturnFromNestedBlock_BSBlock34.test == :ok
|
||||
assert_equal TestReturnFromNestedBlock_BSBlock34.test, :ok
|
||||
end
|
||||
|
||||
assert("BS Block 35") do
|
||||
@@ -436,5 +485,5 @@ assert("BS Block 35") do
|
||||
:bad
|
||||
end
|
||||
end
|
||||
TestReturnFromNestedBlock_BSBlock35.test == :ok
|
||||
assert_equal TestReturnFromNestedBlock_BSBlock35.test, :ok
|
||||
end
|
||||
|
||||
@@ -2,37 +2,37 @@
|
||||
# Bootstrap test for literals
|
||||
|
||||
assert('BS Literal 1') do
|
||||
true == true
|
||||
assert_true true
|
||||
end
|
||||
|
||||
assert('BS Literal 2') do
|
||||
TrueClass == true.class
|
||||
assert_equal TrueClass, true.class
|
||||
end
|
||||
|
||||
assert('BS Literal 3') do
|
||||
false == false
|
||||
assert_false false
|
||||
end
|
||||
|
||||
assert('BS Literal 4') do
|
||||
FalseClass == false.class
|
||||
assert_equal FalseClass, false.class
|
||||
end
|
||||
|
||||
assert('BS Literal 5') do
|
||||
'nil' == nil.inspect
|
||||
assert_equal 'nil', nil.inspect
|
||||
end
|
||||
|
||||
assert('BS Literal 6') do
|
||||
NilClass == nil.class
|
||||
assert_equal NilClass, nil.class
|
||||
end
|
||||
|
||||
assert('BS Literal 7') do
|
||||
Symbol == :sym.class
|
||||
assert_equal Symbol, :sym.class
|
||||
end
|
||||
|
||||
assert('BS Literal 8') do
|
||||
1234 == 1234
|
||||
assert_equal 1234, 1234
|
||||
end
|
||||
|
||||
assert('BS Literal 9') do
|
||||
Fixnum == 1234.class
|
||||
assert_equal Fixnum, 1234.class
|
||||
end
|
||||
|
||||
+36
-126
@@ -2,11 +2,11 @@
|
||||
# Class ISO Test
|
||||
|
||||
assert('Class', '15.2.3') do
|
||||
Class.class == Class
|
||||
assert_equal(Class.class, Class)
|
||||
end
|
||||
|
||||
assert('Class superclass', '15.2.3.2') do
|
||||
Class.superclass == Module
|
||||
assert_equal(Class.superclass, Module)
|
||||
end
|
||||
|
||||
# Class#initialize '15.2.3.3.1' is tested in Class#new
|
||||
@@ -26,7 +26,8 @@ assert('Class#initialize_copy', '15.2.3.3.2') do
|
||||
c2 = c1.dup
|
||||
c3 = TestClass.new('Bar')
|
||||
|
||||
c1.n == c2.n and c1.n != c3.n
|
||||
assert_equal(c1.n, c2.n)
|
||||
assert_not_equal(c1.n, c3.n)
|
||||
end
|
||||
|
||||
assert('Class#new', '15.2.3.3.3') do
|
||||
@@ -51,48 +52,48 @@ assert('Class#new', '15.2.3.3.3') do
|
||||
def result; @result; end
|
||||
end
|
||||
|
||||
TestClass.new(:arg).result == :only_args
|
||||
assert_equal(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
|
||||
assert_equal(SubClass.superclass, String)
|
||||
end
|
||||
|
||||
# Not ISO specified
|
||||
|
||||
assert('Class 1') do
|
||||
class C1; end
|
||||
C1.class == Class
|
||||
assert_equal(C1.class, Class)
|
||||
end
|
||||
|
||||
assert('Class 2') do
|
||||
class C2; end
|
||||
C2.new.class == C2
|
||||
assert_equal(C2.new.class, C2)
|
||||
end
|
||||
|
||||
assert('Class 3') do
|
||||
class C3; end
|
||||
C3.new.class.class == Class
|
||||
assert_equal(C3.new.class.class, Class)
|
||||
end
|
||||
|
||||
assert('Class 4') do
|
||||
class C4_A; end
|
||||
class C4 < C4_A; end
|
||||
C4.class == Class
|
||||
assert_equal(C4.class, Class)
|
||||
end
|
||||
|
||||
assert('Class 5') do
|
||||
class C5_A; end
|
||||
class C5 < C5_A; end
|
||||
C5.new.class == C5
|
||||
assert_equal(C5.new.class, C5)
|
||||
end
|
||||
|
||||
assert('Class 6') do
|
||||
class C6_A; end
|
||||
class C6 < C6_A; end
|
||||
C6.new.class.class == Class
|
||||
assert_equal(C6.new.class.class, Class)
|
||||
end
|
||||
|
||||
assert('Class 7') do
|
||||
@@ -101,15 +102,10 @@ assert('Class 7') do
|
||||
|
||||
class C7 < C7_A; end
|
||||
|
||||
error = false
|
||||
begin
|
||||
assert_raise(TypeError) do
|
||||
# Different superclass.
|
||||
class C7 < C7_B; end
|
||||
rescue TypeError
|
||||
error = true
|
||||
end
|
||||
|
||||
error
|
||||
end
|
||||
|
||||
assert('Class 8') do
|
||||
@@ -117,193 +113,107 @@ assert('Class 8') do
|
||||
|
||||
class C8; end # superclass is Object
|
||||
|
||||
error = false
|
||||
begin
|
||||
assert_raise(TypeError) do
|
||||
# Different superclass.
|
||||
class C8 < C8_A; end
|
||||
rescue TypeError
|
||||
error = true
|
||||
end
|
||||
|
||||
error
|
||||
end
|
||||
|
||||
assert('Class 9') do
|
||||
Class9Const = "a"
|
||||
|
||||
error = false
|
||||
begin
|
||||
assert_raise(TypeError) do
|
||||
class Class9Const; end
|
||||
rescue TypeError
|
||||
error = true
|
||||
end
|
||||
|
||||
error
|
||||
end
|
||||
|
||||
assert('Class Module 1') do
|
||||
module M; end
|
||||
M.class == Module
|
||||
assert_equal(M.class, Module)
|
||||
end
|
||||
|
||||
assert('Class Module 2') do
|
||||
module M; end
|
||||
class C; include M; end
|
||||
C.new.class == C
|
||||
assert_equal(C.new.class, C)
|
||||
end
|
||||
|
||||
# nested class
|
||||
assert('Class Nested 1') do
|
||||
class A; end
|
||||
class A::B; end
|
||||
A::B == A::B
|
||||
assert_equal(A::B, A::B)
|
||||
end
|
||||
|
||||
assert('Class Nested 2') do
|
||||
class A; end
|
||||
class A::B; end
|
||||
A::B.new.class == A::B
|
||||
assert_equal(A::B.new.class, A::B)
|
||||
end
|
||||
|
||||
assert('Class Nested 3') do
|
||||
class A; end
|
||||
class A::B; end
|
||||
A::B.new.class.class == Class
|
||||
assert_equal(A::B.new.class.class, Class)
|
||||
end
|
||||
|
||||
assert('Class Nested 4') do
|
||||
class A; end
|
||||
class A::B; end
|
||||
class A::B::C; end
|
||||
A::B::C == A::B::C
|
||||
assert_equal(A::B::C, A::B::C)
|
||||
end
|
||||
|
||||
assert('Class Nested 5') do
|
||||
class A; end
|
||||
class A::B; end
|
||||
class A::B::C; end
|
||||
A::B::C.class == Class
|
||||
assert_equal(A::B::C.class, Class)
|
||||
end
|
||||
|
||||
assert('Class Nested 6') do
|
||||
class A; end
|
||||
class A::B; end
|
||||
class A::B::C; end
|
||||
A::B::C.new.class == A::B::C
|
||||
assert_equal(A::B::C.new.class, A::B::C)
|
||||
end
|
||||
|
||||
assert('Class Nested 7') do
|
||||
class A; end
|
||||
class A::B; end
|
||||
class A::B2 < A::B; end
|
||||
A::B2 == A::B2
|
||||
assert_equal(A::B2, A::B2)
|
||||
end
|
||||
|
||||
assert('Class Nested 8') do
|
||||
class A; end
|
||||
class A::B; end
|
||||
class A::B2 < A::B; end
|
||||
A::B2.class == Class
|
||||
assert_equal(A::B2.class, Class)
|
||||
end
|
||||
|
||||
assert('Class Colon 1') do
|
||||
class A; end; A::C = 1; A::C == 1
|
||||
class A; end
|
||||
A::C = 1
|
||||
assert_equal(A::C, 1)
|
||||
end
|
||||
|
||||
assert('Class Colon 2') do
|
||||
class A; class ::C; end end; C == C
|
||||
class A; class ::C; end end
|
||||
assert_equal(C, C)
|
||||
end
|
||||
|
||||
assert('Class Colon 3') do
|
||||
class A; class ::C; end end; C.class == Class
|
||||
class A; class ::C; end end
|
||||
assert_equal(C.class, Class)
|
||||
end
|
||||
|
||||
assert('Class Dup 1') do
|
||||
class C; end; C.dup.class == Class
|
||||
class C; end
|
||||
assert_equal(C.dup.class, Class)
|
||||
end
|
||||
|
||||
assert('Class Dup 2') do
|
||||
module M; end; M.dup.class == Module
|
||||
module M; end
|
||||
assert_equal(M.dup.class, Module)
|
||||
end
|
||||
|
||||
assert('Class Alias 1') do
|
||||
class A
|
||||
def test; 1; end
|
||||
|
||||
alias test2 test
|
||||
alias :test3 :test
|
||||
end
|
||||
|
||||
A.new.test2 == 1 and A.new.test3 == 1
|
||||
end
|
||||
|
||||
assert('Class Alias 2') do
|
||||
class A
|
||||
def test; 1; end
|
||||
|
||||
alias test2 test
|
||||
|
||||
def test; 2; end
|
||||
end
|
||||
|
||||
A.new.test == 2 and A.new.test2 == 1
|
||||
end
|
||||
|
||||
assert('Class Undef 1') do
|
||||
class A
|
||||
def test1; 1; end
|
||||
def test2; 2; end
|
||||
|
||||
undef test1
|
||||
undef :test2
|
||||
end
|
||||
|
||||
result1 = false
|
||||
begin
|
||||
A.new.test1
|
||||
rescue NoMethodError
|
||||
result1 = true
|
||||
end
|
||||
|
||||
result2 = false
|
||||
begin
|
||||
A.new.test2
|
||||
rescue NoMethodError
|
||||
result2 = true
|
||||
end
|
||||
|
||||
result1 == true and result2 == true
|
||||
end
|
||||
|
||||
assert('Class Undef 2') do
|
||||
class A
|
||||
def test1; 1; end
|
||||
def test2; 2; end
|
||||
|
||||
undef test1, test2
|
||||
end
|
||||
|
||||
result1 = false
|
||||
begin
|
||||
A.new.test1
|
||||
rescue NoMethodError
|
||||
result1 = true
|
||||
end
|
||||
|
||||
result2 = false
|
||||
begin
|
||||
A.new.test2
|
||||
rescue NoMethodError
|
||||
result2 = true
|
||||
end
|
||||
|
||||
result1 == true and result2 == true
|
||||
end
|
||||
|
||||
assert('Var undef') do
|
||||
assert_raise(NameError) do
|
||||
a=1
|
||||
undef a
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+11
-10
@@ -7,7 +7,7 @@ assert('Comparable#<', '15.3.3.2.1') do
|
||||
end
|
||||
end
|
||||
|
||||
(Foo.new < Foo.new) == false
|
||||
assert_false(Foo.new < Foo.new)
|
||||
end
|
||||
|
||||
assert('Comparable#<=', '15.3.3.2.2') do
|
||||
@@ -18,7 +18,7 @@ assert('Comparable#<=', '15.3.3.2.2') do
|
||||
end
|
||||
end
|
||||
|
||||
(Foo.new <= Foo.new) == true
|
||||
assert_true(Foo.new <= Foo.new)
|
||||
end
|
||||
|
||||
assert('Comparable#==', '15.3.3.2.3') do
|
||||
@@ -29,7 +29,7 @@ assert('Comparable#==', '15.3.3.2.3') do
|
||||
end
|
||||
end
|
||||
|
||||
(Foo.new == Foo.new) == true
|
||||
assert_true(Foo.new == Foo.new)
|
||||
end
|
||||
|
||||
assert('Comparable#>', '15.3.3.2.4') do
|
||||
@@ -40,7 +40,7 @@ assert('Comparable#>', '15.3.3.2.4') do
|
||||
end
|
||||
end
|
||||
|
||||
(Foo.new > Foo.new) == false
|
||||
assert_false(Foo.new > Foo.new)
|
||||
end
|
||||
|
||||
assert('Comparable#>=', '15.3.3.2.5') do
|
||||
@@ -51,7 +51,7 @@ assert('Comparable#>=', '15.3.3.2.5') do
|
||||
end
|
||||
end
|
||||
|
||||
(Foo.new >= Foo.new) == true
|
||||
assert_true(Foo.new >= Foo.new)
|
||||
end
|
||||
|
||||
assert('Comparable#between?', '15.3.3.2.6') do
|
||||
@@ -63,9 +63,10 @@ assert('Comparable#between?', '15.3.3.2.6') do
|
||||
end
|
||||
|
||||
c = Foo.new
|
||||
c.between?(-1, 1) == false &&
|
||||
c.between?(-1, -1) == false &&
|
||||
c.between?( 1, 1) == false &&
|
||||
c.between?( 1, -1) == true &&
|
||||
c.between?(0, 0) == true
|
||||
|
||||
assert_false(c.between?(-1, 1))
|
||||
assert_false(c.between?(-1, -1))
|
||||
assert_false(c.between?( 1, 1))
|
||||
assert_true(c.between?( 1, -1))
|
||||
assert_true(c.between?(0, 0))
|
||||
end
|
||||
|
||||
+30
-25
@@ -2,23 +2,26 @@
|
||||
# Enumerable ISO Test
|
||||
|
||||
assert('Enumerable', '15.3.2') do
|
||||
Enumerable.class == Module
|
||||
assert_equal(Enumerable.class, Module)
|
||||
end
|
||||
|
||||
assert('Enumerable#all?', '15.3.2.2.1') do
|
||||
[1,2,3].all? and not [1,false,3].all?
|
||||
assert_true([1,2,3].all?)
|
||||
assert_false([1,false,3].all?)
|
||||
end
|
||||
|
||||
assert('Enumerable#any?', '15.3.2.2.2') do
|
||||
[false,true,false].any? and not [false,false,false].any?
|
||||
assert_true([false,true,false].any?)
|
||||
assert_false([false,false,false].any?)
|
||||
end
|
||||
|
||||
assert('Enumerable#collect', '15.3.2.2.3') do
|
||||
[1,2,3].collect { |i| i + i } == [2,4,6]
|
||||
assert_true [1,2,3].collect { |i| i + i } == [2,4,6]
|
||||
end
|
||||
|
||||
assert('Enumerable#detect', '15.3.2.2.4') do
|
||||
[1,2,3].detect() { true } and [1,2,3].detect("a") { false } == 'a'
|
||||
assert_true [1,2,3].detect() { true }
|
||||
assert_equal [1,2,3].detect("a") { false }, 'a'
|
||||
end
|
||||
|
||||
assert('Array#each_with_index', '15.3.2.2.5') do
|
||||
@@ -27,54 +30,56 @@ assert('Array#each_with_index', '15.3.2.2.5') do
|
||||
|
||||
[1].each_with_index {|e,i| a = e; b = i}
|
||||
|
||||
a == 1 and b == 0
|
||||
assert_equal(a, 1)
|
||||
assert_equal(b, 0)
|
||||
end
|
||||
|
||||
assert('Enumerable#entries', '15.3.2.2.6') do
|
||||
[1].entries == [1]
|
||||
assert_equal([1].entries, [1])
|
||||
end
|
||||
|
||||
assert('Enumerable#find', '15.3.2.2.7') do
|
||||
[1,2,3].find() { true } and [1,2,3].find("a") { false } == 'a'
|
||||
assert_true [1,2,3].find() { true }
|
||||
assert_equal [1,2,3].find("a") { false }, 'a'
|
||||
end
|
||||
|
||||
assert('Enumerable#find_all', '15.3.2.2.8') do
|
||||
[1,2,3,4,5,6,7,8,9].find_all() {|i| i%2 == 0} == [2,4,6,8]
|
||||
assert_true [1,2,3,4,5,6,7,8,9].find_all() {|i| i%2 == 0}, [2,4,6,8]
|
||||
end
|
||||
|
||||
assert('Enumerable#grep', '15.3.2.2.9') do
|
||||
[1,2,3,4,5,6,7,8,9].grep(4..6) == [4,5,6]
|
||||
assert_equal [1,2,3,4,5,6,7,8,9].grep(4..6), [4,5,6]
|
||||
end
|
||||
|
||||
assert('Enumerable#include?', '15.3.2.2.10') do
|
||||
[1,2,3,4,5,6,7,8,9].include?(5) and
|
||||
not [1,2,3,4,5,6,7,8,9].include?(0)
|
||||
assert_true [1,2,3,4,5,6,7,8,9].include?(5)
|
||||
assert_false [1,2,3,4,5,6,7,8,9].include?(0)
|
||||
end
|
||||
|
||||
assert('Enumerable#inject', '15.3.2.2.11') do
|
||||
[1,2,3,4,5,6].inject() {|s, n| s + n} == 21 and
|
||||
[1,2,3,4,5,6].inject(1) {|s, n| s + n} == 22
|
||||
assert_equal [1,2,3,4,5,6].inject() {|s, n| s + n}, 21
|
||||
assert_equal [1,2,3,4,5,6].inject(1) {|s, n| s + n}, 22
|
||||
end
|
||||
|
||||
assert('Enumerable#map', '15.3.2.2.12') do
|
||||
[1,2,3].map { |i| i + i } == [2,4,6]
|
||||
assert_equal [1,2,3].map { |i| i + i }, [2,4,6]
|
||||
end
|
||||
|
||||
assert('Enumerable#max', '15.3.2.2.13') do
|
||||
a = ['aaa', 'bb', 'c']
|
||||
a.max == 'c' and
|
||||
a.max {|i1,i2| i1.length <=> i2.length} == 'aaa'
|
||||
assert_equal a.max, 'c'
|
||||
assert_equal a.max {|i1,i2| i1.length <=> i2.length}, 'aaa'
|
||||
end
|
||||
|
||||
assert('Enumerable#min', '15.3.2.2.14') do
|
||||
a = ['aaa', 'bb', 'c']
|
||||
a.min == 'aaa' and
|
||||
a.min {|i1,i2| i1.length <=> i2.length} == 'c'
|
||||
assert_equal a.min, 'aaa'
|
||||
assert_equal a.min {|i1,i2| i1.length <=> i2.length}, 'c'
|
||||
end
|
||||
|
||||
assert('Enumerable#member?', '15.3.2.2.15') do
|
||||
[1,2,3,4,5,6,7,8,9].member?(5) and
|
||||
not [1,2,3,4,5,6,7,8,9].member?(0)
|
||||
assert_true [1,2,3,4,5,6,7,8,9].member?(5)
|
||||
assert_false [1,2,3,4,5,6,7,8,9].member?(0)
|
||||
end
|
||||
|
||||
assert('Enumerable#partion', '15.3.2.2.16') do
|
||||
@@ -90,14 +95,14 @@ assert('Enumerable#reject', '15.3.2.2.17') do
|
||||
end
|
||||
|
||||
assert('Enumerable#select', '15.3.2.2.18') do
|
||||
[1,2,3,4,5,6,7,8,9].select() {|i| i%2 == 0} == [2,4,6,8]
|
||||
assert_equal [1,2,3,4,5,6,7,8,9].select() {|i| i%2 == 0}, [2,4,6,8]
|
||||
end
|
||||
|
||||
assert('Enumerable#sort', '15.3.2.2.19') do
|
||||
[7,3,1,2,6,4].sort == [1,2,3,4,6,7] and
|
||||
[7,3,1,2,6,4].sort {|e1,e2| e2<=>e1} == [7,6,4,3,2,1]
|
||||
assert_equal [7,3,1,2,6,4].sort, [1,2,3,4,6,7]
|
||||
assert_equal [7,3,1,2,6,4].sort {|e1,e2|e2<=>e1}, [7,6,4,3,2,1]
|
||||
end
|
||||
|
||||
assert('Enumerable#to_a', '15.3.2.2.20') do
|
||||
[1].to_a == [1]
|
||||
assert_equal [1].to_a, [1]
|
||||
end
|
||||
|
||||
+22
-32
@@ -2,62 +2,55 @@
|
||||
# Exception ISO Test
|
||||
|
||||
assert('Exception', '15.2.22') do
|
||||
Exception.class == Class
|
||||
assert_equal Exception.class, Class
|
||||
end
|
||||
|
||||
assert('Exception superclass', '15.2.22.2') do
|
||||
Exception.superclass == Object
|
||||
assert_equal Exception.superclass, Object
|
||||
end
|
||||
|
||||
assert('Exception.exception', '15.2.22.4.1') do
|
||||
e = Exception.exception('a')
|
||||
|
||||
e.class == Exception
|
||||
assert_equal e.class, Exception
|
||||
end
|
||||
|
||||
assert('Exception#exception', '15.2.22.5.1') do
|
||||
e1 = Exception.exception()
|
||||
e2 = Exception.exception('b')
|
||||
|
||||
e1.class == Exception and e2.class == Exception
|
||||
assert_equal e1.class, Exception
|
||||
assert_equal e2.class, Exception
|
||||
end
|
||||
|
||||
assert('Exception#message', '15.2.22.5.2') do
|
||||
e = Exception.exception('a')
|
||||
|
||||
e.message == 'a'
|
||||
assert_equal e.message, 'a'
|
||||
end
|
||||
|
||||
assert('Exception#to_s', '15.2.22.5.3') do
|
||||
e = Exception.exception('a')
|
||||
|
||||
e.to_s == 'a'
|
||||
assert_equal e.to_s, 'a'
|
||||
end
|
||||
|
||||
assert('Exception.exception', '15.2.22.4.1') do
|
||||
e = Exception.exception()
|
||||
e.initialize('a')
|
||||
|
||||
e.message == 'a'
|
||||
assert_equal e.message, 'a'
|
||||
end
|
||||
|
||||
assert('ScriptError', '15.2.37') do
|
||||
begin
|
||||
assert_raise(ScriptError) do
|
||||
raise ScriptError.new
|
||||
rescue ScriptError
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
assert('SyntaxError', '15.2.38') do
|
||||
begin
|
||||
assert_raise(SyntaxError) do
|
||||
raise SyntaxError.new
|
||||
rescue SyntaxError
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -110,7 +103,7 @@ assert('Exception 4') do
|
||||
end
|
||||
a = err.class
|
||||
}
|
||||
a == NilClass
|
||||
assert_equal a, NilClass
|
||||
end
|
||||
|
||||
assert('Exception 5') do
|
||||
@@ -128,7 +121,7 @@ assert('Exception 5') do
|
||||
}
|
||||
end
|
||||
m2
|
||||
$ans == [nil]
|
||||
assert_equal $ans, [nil]
|
||||
end
|
||||
|
||||
assert('Exception 6') do
|
||||
@@ -154,7 +147,7 @@ assert('Exception 6') do
|
||||
yield
|
||||
end
|
||||
m
|
||||
$i == 7
|
||||
assert_equal $i, 7
|
||||
end
|
||||
|
||||
assert('Exception 7') do
|
||||
@@ -174,7 +167,7 @@ assert('Exception 7') do
|
||||
p :end
|
||||
end
|
||||
m
|
||||
$i == 10
|
||||
assert_equal $i, 10
|
||||
end
|
||||
|
||||
assert('Exception 8') do
|
||||
@@ -228,7 +221,7 @@ assert('Exception 11') do
|
||||
end
|
||||
rescue Exception
|
||||
end
|
||||
a == :ok
|
||||
assert_equal a, :ok
|
||||
end
|
||||
|
||||
assert('Exception 12') do
|
||||
@@ -237,7 +230,7 @@ assert('Exception 12') do
|
||||
raise Exception rescue a = :ng
|
||||
rescue Exception
|
||||
end
|
||||
a == :ok
|
||||
assert_equal a, :ok
|
||||
end
|
||||
|
||||
assert('Exception 13') do
|
||||
@@ -251,14 +244,11 @@ assert('Exception 13') do
|
||||
else
|
||||
a = :ng
|
||||
end
|
||||
a == :ok
|
||||
end
|
||||
|
||||
def exception_test14
|
||||
UnknownConstant
|
||||
assert_equal a, :ok
|
||||
end
|
||||
|
||||
assert('Exception 14') do
|
||||
def exception_test14; UnknownConstant; end
|
||||
a = :ng
|
||||
begin
|
||||
send(:exception_test14)
|
||||
@@ -266,16 +256,16 @@ assert('Exception 14') do
|
||||
a = :ok
|
||||
end
|
||||
|
||||
a == :ok
|
||||
assert_equal a, :ok
|
||||
end
|
||||
|
||||
assert('Exception 15') do
|
||||
a = begin
|
||||
:ok
|
||||
rescue
|
||||
:ng
|
||||
:ko
|
||||
end
|
||||
a == :ok
|
||||
assert_equal a, :ok
|
||||
end
|
||||
|
||||
assert('Exception 16') do
|
||||
@@ -339,7 +329,7 @@ assert('Exception 19') do
|
||||
true
|
||||
end
|
||||
end
|
||||
Class4Exception19.new.a == [true, true]
|
||||
assert_equal Class4Exception19.new.a, [true, true]
|
||||
end
|
||||
|
||||
assert('Exception#inspect without message') do
|
||||
|
||||
+10
-7
@@ -2,29 +2,32 @@
|
||||
# FalseClass ISO Test
|
||||
|
||||
assert('FalseClass', '15.2.6') do
|
||||
FalseClass.class == Class
|
||||
assert_equal FalseClass.class, Class
|
||||
end
|
||||
|
||||
assert('FalseClass superclass', '15.2.6.2') do
|
||||
FalseClass.superclass == Object
|
||||
assert_equal FalseClass.superclass, Object
|
||||
end
|
||||
|
||||
assert('FalseClass false', '15.2.6.1') do
|
||||
not false
|
||||
assert_false false
|
||||
end
|
||||
|
||||
assert('FalseClass#&', '15.2.6.3.1') do
|
||||
not false.&(true) and not false.&(false)
|
||||
assert_false false.&(true)
|
||||
assert_false false.&(false)
|
||||
end
|
||||
|
||||
assert('FalseClass#^', '15.2.6.3.2') do
|
||||
false.^(true) and not false.^(false)
|
||||
assert_true false.^(true)
|
||||
assert_false false.^(false)
|
||||
end
|
||||
|
||||
assert('FalseClass#to_s', '15.2.6.3.3') do
|
||||
false.to_s == 'false'
|
||||
assert_equal false.to_s, 'false'
|
||||
end
|
||||
|
||||
assert('FalseClass#|', '15.2.6.3.4') do
|
||||
false.|(true) and not false.|(false)
|
||||
assert_true false.|(true)
|
||||
assert_false false.|(false)
|
||||
end
|
||||
|
||||
+47
-25
@@ -2,51 +2,51 @@
|
||||
# Float ISO Test
|
||||
|
||||
assert('Float', '15.2.9') do
|
||||
Float.class == Class
|
||||
assert_equal Float.class, Class
|
||||
end
|
||||
|
||||
assert('Float superclass', '15.2.9.2') do
|
||||
Float.superclass == Numeric
|
||||
assert_equal Float.superclass, Numeric
|
||||
end
|
||||
|
||||
assert('Float#+', '15.2.9.3.1') do
|
||||
a = 3.123456788 + 0.000000001
|
||||
b = 3.123456789 + 1
|
||||
|
||||
check_float(a, 3.123456789) and
|
||||
check_float(b, 4.123456789)
|
||||
assert_float(a, 3.123456789)
|
||||
assert_float(b, 4.123456789)
|
||||
end
|
||||
|
||||
assert('Float#-', '15.2.9.3.2') do
|
||||
a = 3.123456790 - 0.000000001
|
||||
b = 5.123456789 - 1
|
||||
|
||||
check_float(a, 3.123456789) and
|
||||
check_float(b, 4.123456789)
|
||||
assert_float(a, 3.123456789)
|
||||
assert_float(b, 4.123456789)
|
||||
end
|
||||
|
||||
assert('Float#*', '15.2.9.3.3') do
|
||||
a = 3.125 * 3.125
|
||||
b = 3.125 * 1
|
||||
|
||||
check_float(a, 9.765625) and
|
||||
check_float(b, 3.125)
|
||||
assert_float(a, 9.765625)
|
||||
assert_float(b, 3.125)
|
||||
end
|
||||
|
||||
assert('Float#/', '15.2.9.3.4') do
|
||||
a = 3.123456789 / 3.123456789
|
||||
b = 3.123456789 / 1
|
||||
|
||||
check_float(a, 1.0) and
|
||||
check_float(b, 3.123456789)
|
||||
assert_float(a, 1.0)
|
||||
assert_float(b, 3.123456789)
|
||||
end
|
||||
|
||||
assert('Float#%', '15.2.9.3.5') do
|
||||
a = 3.125 % 3.125
|
||||
b = 3.125 % 1
|
||||
|
||||
check_float(a, 0.0) and
|
||||
check_float(b, 0.125)
|
||||
assert_float(a, 0.0)
|
||||
assert_float(b, 0.125)
|
||||
end
|
||||
|
||||
assert('Float#<=>', '15.2.9.3.6') do
|
||||
@@ -56,12 +56,16 @@ assert('Float#<=>', '15.2.9.3.6') do
|
||||
a2 = 3.125 <=> 3
|
||||
c2 = 3.125 <=> 4
|
||||
|
||||
a == 1 and b == 0 and c == -1 and
|
||||
a2 == 1 and c2 == -1
|
||||
assert_equal a, 1
|
||||
assert_equal b, 0
|
||||
assert_equal c, -1
|
||||
assert_equal a2, 1
|
||||
assert_equal c2, -1
|
||||
end
|
||||
|
||||
assert('Float#==', '15.2.9.3.7') do
|
||||
3.1 == 3.1 and not 3.1 == 3.2
|
||||
assert_true 3.1 == 3.1
|
||||
assert_false 3.1 == 3.2
|
||||
end
|
||||
|
||||
assert('Float#ceil', '15.2.9.3.8') do
|
||||
@@ -69,12 +73,16 @@ assert('Float#ceil', '15.2.9.3.8') do
|
||||
b = 3.0.ceil
|
||||
c = -3.123456789.ceil
|
||||
d = -3.0.ceil
|
||||
a == 4 and b == 3 and c == -3 and d == -3
|
||||
|
||||
assert_equal a, 4
|
||||
assert_equal b, 3
|
||||
assert_equal c, -3
|
||||
assert_equal d, -3
|
||||
end
|
||||
|
||||
assert('Float#finite?', '15.2.9.3.9') do
|
||||
3.123456789.finite? and
|
||||
not (1.0 / 0.0).finite?
|
||||
assert_true 3.123456789.finite?
|
||||
assert_false (1.0 / 0.0).finite?
|
||||
end
|
||||
|
||||
assert('Float#floor', '15.2.9.3.10') do
|
||||
@@ -82,7 +90,11 @@ assert('Float#floor', '15.2.9.3.10') do
|
||||
b = 3.0.floor
|
||||
c = -3.123456789.floor
|
||||
d = -3.0.floor
|
||||
a == 3 and b == 3 and c == -4 and d == -3
|
||||
|
||||
assert_equal a, 3
|
||||
assert_equal b, 3
|
||||
assert_equal c, -4
|
||||
assert_equal d, -3
|
||||
end
|
||||
|
||||
assert('Float#infinite?', '15.2.9.3.11') do
|
||||
@@ -90,7 +102,9 @@ assert('Float#infinite?', '15.2.9.3.11') do
|
||||
b = (1.0 / 0.0).infinite?
|
||||
c = (-1.0 / 0.0).infinite?
|
||||
|
||||
a == nil and b == 1 and c == -1
|
||||
assert_nil a
|
||||
assert_equal b, 1
|
||||
assert_equal c, -1
|
||||
end
|
||||
|
||||
assert('Float#round', '15.2.9.3.12') do
|
||||
@@ -104,20 +118,28 @@ assert('Float#round', '15.2.9.3.12') do
|
||||
h = 3.423456789.round(1)
|
||||
i = 3.423456789.round(3)
|
||||
|
||||
a == 3 and b == 4 and c == 3 and d == -3 and e == -4 and
|
||||
f == 12350 and g == 3 and check_float(h, 3.4) and check_float(i, 3.423)
|
||||
assert_equal a, 3
|
||||
assert_equal b, 4
|
||||
assert_equal c, 3
|
||||
assert_equal d, -3
|
||||
assert_equal e, -4
|
||||
assert_equal f, 12350
|
||||
assert_equal g, 3
|
||||
assert_float(h, 3.4)
|
||||
assert_float(i, 3.423)
|
||||
end
|
||||
|
||||
assert('Float#to_f', '15.2.9.3.13') do
|
||||
a = 3.123456789
|
||||
|
||||
check_float(a.to_f, a)
|
||||
assert_float(a.to_f, a)
|
||||
end
|
||||
|
||||
assert('Float#to_i', '15.2.9.3.14') do
|
||||
3.123456789.to_i == 3
|
||||
assert_equal 3.123456789.to_i, 3
|
||||
end
|
||||
|
||||
assert('Float#truncate', '15.2.9.3.15') do
|
||||
3.123456789.truncate == 3 and -3.1.truncate == -3
|
||||
assert_equal 3.123456789.truncate, 3
|
||||
assert_equal(-3.1.truncate, -3)
|
||||
end
|
||||
|
||||
+10
-10
@@ -1,15 +1,15 @@
|
||||
# Not ISO specified
|
||||
|
||||
assert('GC.enable') do
|
||||
GC.disable == false
|
||||
GC.enable == true
|
||||
GC.enable == false
|
||||
assert_equal GC.disable, false
|
||||
assert_equal GC.enable, true
|
||||
assert_equal GC.enable, false
|
||||
end
|
||||
|
||||
assert('GC.disable') do
|
||||
begin
|
||||
GC.disable == false
|
||||
GC.disable == true
|
||||
assert_equal GC.disable, false
|
||||
assert_equal GC.disable, true
|
||||
ensure
|
||||
GC.enable
|
||||
end
|
||||
@@ -18,7 +18,7 @@ end
|
||||
assert('GC.interval_ratio=') do
|
||||
origin = GC.interval_ratio
|
||||
begin
|
||||
(GC.interval_ratio = 150) == 150
|
||||
assert_equal (GC.interval_ratio = 150), 150
|
||||
ensure
|
||||
GC.interval_ratio = origin
|
||||
end
|
||||
@@ -27,7 +27,7 @@ end
|
||||
assert('GC.step_ratio=') do
|
||||
origin = GC.step_ratio
|
||||
begin
|
||||
(GC.step_ratio = 150) == 150
|
||||
assert_equal (GC.step_ratio = 150), 150
|
||||
ensure
|
||||
GC.step_ratio = origin
|
||||
end
|
||||
@@ -36,9 +36,9 @@ end
|
||||
assert('GC.generational_mode=') do
|
||||
origin = GC.generational_mode
|
||||
begin
|
||||
(GC.generational_mode = false) == false
|
||||
(GC.generational_mode = true) == true
|
||||
(GC.generational_mode = true) == true
|
||||
assert_equal (GC.generational_mode = false), false
|
||||
assert_equal (GC.generational_mode = true), true
|
||||
assert_equal (GC.generational_mode = true), true
|
||||
ensure
|
||||
GC.generational_mode = origin
|
||||
end
|
||||
|
||||
+68
-49
@@ -2,36 +2,36 @@
|
||||
# Hash ISO Test
|
||||
|
||||
assert('Hash', '15.2.13') do
|
||||
Hash.class == Class
|
||||
assert_equal Hash.class, Class
|
||||
end
|
||||
|
||||
assert('Hash superclass', '15.2.13.2') do
|
||||
Hash.superclass == Object
|
||||
assert_equal Hash.superclass, Object
|
||||
end
|
||||
|
||||
assert('Hash#==', '15.2.13.4.1') do
|
||||
({ 'abc' => 'abc' } == { 'abc' => 'abc' }) and
|
||||
not ({ 'abc' => 'abc' } == { 'cba' => 'cba' })
|
||||
assert_true({ 'abc' => 'abc' } == { 'abc' => 'abc' })
|
||||
assert_false({ 'abc' => 'abc' } == { 'cba' => 'cba' })
|
||||
end
|
||||
|
||||
assert('Hash#[]', '15.2.13.4.2') do
|
||||
a = { 'abc' => 'abc' }
|
||||
|
||||
a['abc'] == 'abc'
|
||||
assert_equal a['abc'], 'abc'
|
||||
end
|
||||
|
||||
assert('Hash#[]=', '15.2.13.4.3') do
|
||||
a = Hash.new
|
||||
a['abc'] = 'abc'
|
||||
|
||||
a['abc'] == 'abc'
|
||||
assert_equal a['abc'], 'abc'
|
||||
end
|
||||
|
||||
assert('Hash#clear', '15.2.13.4.4') do
|
||||
a = { 'abc' => 'abc' }
|
||||
a.clear
|
||||
|
||||
a == { }
|
||||
assert_equal a, { }
|
||||
end
|
||||
|
||||
assert('Hash#default', '15.2.13.4.5') do
|
||||
@@ -39,15 +39,18 @@ assert('Hash#default', '15.2.13.4.5') do
|
||||
b = Hash.new('abc')
|
||||
c = Hash.new {|s,k| s[k] = k}
|
||||
|
||||
a.default == nil and b.default == 'abc' and
|
||||
c.default == nil and c.default('abc') == 'abc'
|
||||
assert_nil a.default
|
||||
assert_equal b.default, 'abc'
|
||||
assert_nil c.default
|
||||
assert_equal c.default('abc'), 'abc'
|
||||
end
|
||||
|
||||
assert('Hash#default=', '15.2.13.4.6') do
|
||||
a = { 'abc' => 'abc' }
|
||||
a.default = 'cba'
|
||||
|
||||
a['abc'] == 'abc' and a['notexist'] == 'cba'
|
||||
assert_equal a['abc'], 'abc'
|
||||
assert_equal a['notexist'], 'cba'
|
||||
end
|
||||
|
||||
assert('Hash#default_proc', '15.2.13.4.7') do
|
||||
@@ -56,8 +59,10 @@ assert('Hash#default_proc', '15.2.13.4.7') do
|
||||
c = b[2]
|
||||
d = b['cat']
|
||||
|
||||
a.default_proc == nil and b.default_proc.class == Proc and
|
||||
c = 4 and d = 'catcat'
|
||||
assert_nil a.default_proc
|
||||
assert_equal b.default_proc.class, Proc
|
||||
assert_equal c, 4
|
||||
assert_equal d, 'catcat'
|
||||
end
|
||||
|
||||
assert('Hash#delete', '15.2.13.4.8') do
|
||||
@@ -74,8 +79,10 @@ assert('Hash#delete', '15.2.13.4.8') do
|
||||
b_tmp_2 = true
|
||||
end
|
||||
|
||||
a.delete('cba') == nil and not a.has_key?('abc') and
|
||||
not b_tmp_1 and b_tmp_2
|
||||
assert_nil a.delete('cba')
|
||||
assert_false a.has_key?('abc')
|
||||
assert_false b_tmp_1
|
||||
assert_true b_tmp_2
|
||||
end
|
||||
|
||||
assert('Hash#each', '15.2.13.4.9') do
|
||||
@@ -88,7 +95,8 @@ assert('Hash#each', '15.2.13.4.9') do
|
||||
value = v
|
||||
end
|
||||
|
||||
key == 'abc_key' and value == 'abc_value'
|
||||
assert_equal key, 'abc_key'
|
||||
assert_equal value, 'abc_value'
|
||||
end
|
||||
|
||||
assert('Hash#each_key', '15.2.13.4.10') do
|
||||
@@ -99,7 +107,7 @@ assert('Hash#each_key', '15.2.13.4.10') do
|
||||
key = k
|
||||
end
|
||||
|
||||
key == 'abc_key'
|
||||
assert_equal key, 'abc_key'
|
||||
end
|
||||
|
||||
assert('Hash#each_value', '15.2.13.4.11') do
|
||||
@@ -110,35 +118,39 @@ assert('Hash#each_value', '15.2.13.4.11') do
|
||||
value = v
|
||||
end
|
||||
|
||||
value == 'abc_value'
|
||||
assert_equal value, 'abc_value'
|
||||
end
|
||||
|
||||
assert('Hash#empty?', '15.2.13.4.12') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
not a.empty? and b.empty?
|
||||
assert_false a.empty?
|
||||
assert_true b.empty?
|
||||
end
|
||||
|
||||
assert('Hash#has_key?', '15.2.13.4.13') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
a.has_key?('abc_key') and not b.has_key?('cba')
|
||||
assert_true a.has_key?('abc_key')
|
||||
assert_false b.has_key?('cba')
|
||||
end
|
||||
|
||||
assert('Hash#has_value?', '15.2.13.4.14') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
a.has_value?('abc_value') and not b.has_value?('cba')
|
||||
assert_true a.has_value?('abc_value')
|
||||
assert_false b.has_value?('cba')
|
||||
end
|
||||
|
||||
assert('Hash#include?', '15.2.13.4.15') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
a.include?('abc_key') and not b.include?('cba')
|
||||
assert_true a.include?('abc_key')
|
||||
assert_false b.include?('cba')
|
||||
end
|
||||
|
||||
assert('Hash#initialize', '15.2.13.4.16') do
|
||||
@@ -146,44 +158,47 @@ assert('Hash#initialize', '15.2.13.4.16') do
|
||||
h = Hash.new
|
||||
h2 = Hash.new(:not_found)
|
||||
|
||||
h.is_a? Hash and
|
||||
h == { } and
|
||||
h["hello"] == nil and
|
||||
h2["hello"] == :not_found
|
||||
assert_true h.is_a? Hash
|
||||
assert_equal h, { }
|
||||
assert_nil h["hello"]
|
||||
assert_equal h2["hello"], :not_found
|
||||
end
|
||||
|
||||
assert('Hash#initialize_copy', '15.2.13.4.17') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new.initialize_copy(a)
|
||||
|
||||
b == { 'abc_key' => 'abc_value' }
|
||||
assert_equal b, { 'abc_key' => 'abc_value' }
|
||||
end
|
||||
|
||||
assert('Hash#key?', '15.2.13.4.18') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
a.key?('abc_key') and not b.key?('cba')
|
||||
assert_true a.key?('abc_key')
|
||||
assert_false b.key?('cba')
|
||||
end
|
||||
|
||||
assert('Hash#keys', '15.2.13.4.19') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
|
||||
a.keys == ['abc_key']
|
||||
assert_equal a.keys, ['abc_key']
|
||||
end
|
||||
|
||||
assert('Hash#length', '15.2.13.4.20') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
a.length == 1 and b.length == 0
|
||||
assert_equal a.length, 1
|
||||
assert_equal b.length, 0
|
||||
end
|
||||
|
||||
assert('Hash#member?', '15.2.13.4.21') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
a.member?('abc_key') and not b.member?('cba')
|
||||
assert_true a.member?('abc_key')
|
||||
assert_false b.member?('cba')
|
||||
end
|
||||
|
||||
assert('Hash#merge', '15.2.13.4.22') do
|
||||
@@ -195,9 +210,9 @@ assert('Hash#merge', '15.2.13.4.22') do
|
||||
original
|
||||
end
|
||||
|
||||
result_1 == {'abc_key' => 'abc_value', 'cba_key' => 'XXX',
|
||||
'xyz_key' => 'xyz_value' } and
|
||||
result_2 == {'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
|
||||
assert_equal result_1, {'abc_key' => 'abc_value', 'cba_key' => 'XXX',
|
||||
'xyz_key' => 'xyz_value' }
|
||||
assert_equal result_2, {'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
|
||||
'xyz_key' => 'xyz_value' }
|
||||
end
|
||||
|
||||
@@ -205,42 +220,44 @@ assert('Hash#replace', '15.2.13.4.23') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new.replace(a)
|
||||
|
||||
b == { 'abc_key' => 'abc_value' }
|
||||
assert_equal b, { 'abc_key' => 'abc_value' }
|
||||
end
|
||||
|
||||
assert('Hash#shift', '15.2.13.4.24') do
|
||||
a = { 'abc_key' => 'abc_value', 'cba_key' => 'cba_value' }
|
||||
b = a.shift
|
||||
|
||||
a == { 'abc_key' => 'abc_value' } and
|
||||
b == [ 'cba_key', 'cba_value' ]
|
||||
assert_equal a, { 'abc_key' => 'abc_value' }
|
||||
assert_equal b, [ 'cba_key', 'cba_value' ]
|
||||
end
|
||||
|
||||
assert('Hash#size', '15.2.13.4.25') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
a.size == 1 and b.size == 0
|
||||
assert_equal a.size, 1
|
||||
assert_equal b.size, 0
|
||||
end
|
||||
|
||||
assert('Hash#store', '15.2.13.4.26') do
|
||||
a = Hash.new
|
||||
a.store('abc', 'abc')
|
||||
|
||||
a['abc'] == 'abc'
|
||||
assert_equal a['abc'], 'abc'
|
||||
end
|
||||
|
||||
assert('Hash#value?', '15.2.13.4.27') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
b = Hash.new
|
||||
|
||||
a.value?('abc_value') and not b.value?('cba')
|
||||
assert_true a.value?('abc_value')
|
||||
assert_false b.value?('cba')
|
||||
end
|
||||
|
||||
assert('Hash#values', '15.2.13.4.28') do
|
||||
a = { 'abc_key' => 'abc_value' }
|
||||
|
||||
a.values == ['abc_value']
|
||||
assert_equal a.values, ['abc_value']
|
||||
end
|
||||
|
||||
# Not ISO specified
|
||||
@@ -250,8 +267,8 @@ assert('Hash#reject') do
|
||||
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}
|
||||
assert_equal ret, {:one => 1, :three => 3}
|
||||
assert_equal h, {:one => 1, :two => 2, :three => 3, :four => 4}
|
||||
end
|
||||
|
||||
assert('Hash#reject!') do
|
||||
@@ -259,8 +276,8 @@ assert('Hash#reject!') do
|
||||
ret = h.reject! do |k,v|
|
||||
v % 2 == 0
|
||||
end
|
||||
ret == {:one => 1, :three => 3} and
|
||||
h == {:one => 1, :three => 3}
|
||||
assert_equal ret, {:one => 1, :three => 3}
|
||||
assert_equal h, {:one => 1, :three => 3}
|
||||
end
|
||||
|
||||
assert('Hash#select') do
|
||||
@@ -268,8 +285,8 @@ assert('Hash#select') do
|
||||
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}
|
||||
assert_equal ret, {:two => 2, :four => 4}
|
||||
assert_equal h, {:one => 1, :two => 2, :three => 3, :four => 4}
|
||||
end
|
||||
|
||||
assert('Hash#select!') do
|
||||
@@ -277,8 +294,8 @@ assert('Hash#select!') do
|
||||
ret = h.select! do |k,v|
|
||||
v % 2 == 0
|
||||
end
|
||||
ret == {:two => 2, :four => 4} and
|
||||
h == {:two => 2, :four => 4}
|
||||
assert_equal ret, {:two => 2, :four => 4}
|
||||
assert_equal h, {:two => 2, :four => 4}
|
||||
end
|
||||
|
||||
# Not ISO specified
|
||||
@@ -287,5 +304,7 @@ assert('Hash#inspect') do
|
||||
h = { "c" => 300, "a" => 100, "d" => 400, "c" => 300 }
|
||||
ret = h.to_s
|
||||
|
||||
ret = "{\"c\"=>300, \"a\"=>100, \"d\"=>400}"
|
||||
assert_include ret, '"c"=>300'
|
||||
assert_include ret, '"a"=>100'
|
||||
assert_include ret, '"d"=>400'
|
||||
end
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
# IndexError ISO Test
|
||||
|
||||
assert('IndexError', '15.2.33') do
|
||||
IndexError.class == Class
|
||||
assert_equal IndexError.class, Class
|
||||
end
|
||||
|
||||
assert('IndexError superclass', '15.2.33.2') do
|
||||
IndexError.superclass == StandardError
|
||||
assert_equal IndexError.superclass, StandardError
|
||||
end
|
||||
|
||||
|
||||
+43
-30
@@ -2,39 +2,43 @@
|
||||
# Integer ISO Test
|
||||
|
||||
assert('Integer', '15.2.8') do
|
||||
Integer.class == Class
|
||||
assert_equal Integer.class, Class
|
||||
end
|
||||
|
||||
assert('Integer superclass', '15.2.8.2') do
|
||||
Integer.superclass == Numeric
|
||||
assert_equal Integer.superclass, Numeric
|
||||
end
|
||||
|
||||
assert('Integer#+', '15.2.8.3.1') do
|
||||
a = 1+1
|
||||
b = 1+1.0
|
||||
|
||||
a == 2 and b == 2.0
|
||||
assert_equal a, 2
|
||||
assert_equal b, 2.0
|
||||
end
|
||||
|
||||
assert('Integer#-', '15.2.8.3.2') do
|
||||
a = 2-1
|
||||
b = 2-1.0
|
||||
|
||||
a == 1 and b == 1.0
|
||||
assert_equal a, 1
|
||||
assert_equal b, 1.0
|
||||
end
|
||||
|
||||
assert('Integer#*', '15.2.8.3.3') do
|
||||
a = 1*1
|
||||
b = 1*1.0
|
||||
|
||||
a == 1 and b == 1.0
|
||||
assert_equal a, 1
|
||||
assert_equal b, 1.0
|
||||
end
|
||||
|
||||
assert('Integer#/', '15.2.8.3.4') do
|
||||
a = 2/1
|
||||
b = 2/1.0
|
||||
|
||||
a == 2 and b == 2.0
|
||||
assert_equal a, 2
|
||||
assert_equal b, 2.0
|
||||
end
|
||||
|
||||
assert('Integer#%', '15.2.8.3.5') do
|
||||
@@ -42,7 +46,9 @@ assert('Integer#%', '15.2.8.3.5') do
|
||||
b = 1%1.0
|
||||
c = 2%4
|
||||
|
||||
a == 0 and b == 0.0 and c == 2
|
||||
assert_equal a, 0
|
||||
assert_equal b, 0.0
|
||||
assert_equal c, 2
|
||||
end
|
||||
|
||||
assert('Integer#<=>', '15.2.8.3.6') do
|
||||
@@ -50,19 +56,23 @@ assert('Integer#<=>', '15.2.8.3.6') do
|
||||
b = 1<=>1
|
||||
c = 1<=>2
|
||||
|
||||
a == 1 and b == 0 and c == -1
|
||||
assert_equal a, 1
|
||||
assert_equal b, 0
|
||||
assert_equal c, -1
|
||||
end
|
||||
|
||||
assert('Integer#==', '15.2.8.3.7') do
|
||||
a = 1==0
|
||||
b = 1==1
|
||||
|
||||
a == false and b == true
|
||||
assert_false a
|
||||
assert_true b
|
||||
end
|
||||
|
||||
assert('Integer#~', '15.2.8.3.8') do
|
||||
# Complement
|
||||
~0 == -1 and ~2 == -3
|
||||
assert_equal ~0, -1
|
||||
assert_equal ~2, -3
|
||||
end
|
||||
|
||||
assert('Integer#&', '15.2.8.3.9') do
|
||||
@@ -70,7 +80,7 @@ assert('Integer#&', '15.2.8.3.9') do
|
||||
# 0101 (5)
|
||||
# & 0011 (3)
|
||||
# = 0001 (1)
|
||||
5 & 3 == 1
|
||||
assert_equal 5 & 3, 1
|
||||
end
|
||||
|
||||
assert('Integer#|', '15.2.8.3.10') do
|
||||
@@ -78,7 +88,7 @@ assert('Integer#|', '15.2.8.3.10') do
|
||||
# 0101 (5)
|
||||
# | 0011 (3)
|
||||
# = 0111 (7)
|
||||
5 | 3 == 7
|
||||
assert_equal 5 | 3, 7
|
||||
end
|
||||
|
||||
assert('Integer#^', '15.2.8.3.11') do
|
||||
@@ -86,25 +96,25 @@ assert('Integer#^', '15.2.8.3.11') do
|
||||
# 0101 (5)
|
||||
# ^ 0011 (3)
|
||||
# = 0110 (6)
|
||||
5 ^ 3 == 6
|
||||
assert_equal 5 ^ 3, 6
|
||||
end
|
||||
|
||||
assert('Integer#<<', '15.2.8.3.12') do
|
||||
# Left Shift by one
|
||||
# 00010111 (23)
|
||||
# = 00101110 (46)
|
||||
23 << 1 == 46
|
||||
assert_equal 23 << 1, 46
|
||||
end
|
||||
|
||||
assert('Integer#>>', '15.2.8.3.13') do
|
||||
# Right Shift by one
|
||||
# 00101110 (46)
|
||||
# = 00010111 (23)
|
||||
46 >> 1 == 23
|
||||
assert_equal 46 >> 1, 23
|
||||
end
|
||||
|
||||
assert('Integer#ceil', '15.2.8.3.14') do
|
||||
10.ceil == 10
|
||||
assert_equal 10.ceil, 10
|
||||
end
|
||||
|
||||
assert('Integer#downto', '15.2.8.3.15') do
|
||||
@@ -112,7 +122,7 @@ assert('Integer#downto', '15.2.8.3.15') do
|
||||
3.downto(1) do |i|
|
||||
a += i
|
||||
end
|
||||
a == 6
|
||||
assert_equal a, 6
|
||||
end
|
||||
|
||||
assert('Integer#eql?', '15.2.8.3.16') do
|
||||
@@ -120,25 +130,27 @@ assert('Integer#eql?', '15.2.8.3.16') do
|
||||
b = 1.eql?(2)
|
||||
c = 1.eql?(nil)
|
||||
|
||||
a == true and b == false and c == false
|
||||
assert_true a
|
||||
assert_false b
|
||||
assert_false c
|
||||
end
|
||||
|
||||
assert('Integer#floor', '15.2.8.3.17') do
|
||||
a = 1.floor
|
||||
|
||||
a == 1
|
||||
assert_equal a, 1
|
||||
end
|
||||
|
||||
assert('Integer#next', '15.2.8.3.19') do
|
||||
1.next == 2
|
||||
assert_equal 1.next, 2
|
||||
end
|
||||
|
||||
assert('Integer#round', '15.2.8.3.20') do
|
||||
1.round == 1
|
||||
assert_equal 1.round, 1
|
||||
end
|
||||
|
||||
assert('Integer#succ', '15.2.8.3.21') do
|
||||
1.succ == 2
|
||||
assert_equal 1.succ, 2
|
||||
end
|
||||
|
||||
assert('Integer#times', '15.2.8.3.22') do
|
||||
@@ -146,23 +158,24 @@ assert('Integer#times', '15.2.8.3.22') do
|
||||
3.times do
|
||||
a += 1
|
||||
end
|
||||
a == 3
|
||||
assert_equal a, 3
|
||||
end
|
||||
|
||||
assert('Integer#to_f', '15.2.8.3.23') do
|
||||
1.to_f == 1.0
|
||||
assert_equal 1.to_f, 1.0
|
||||
end
|
||||
|
||||
assert('Integer#to_i', '15.2.8.3.24') do
|
||||
1.to_i == 1
|
||||
assert_equal 1.to_i, 1
|
||||
end
|
||||
|
||||
assert('Integer#to_s', '15.2.8.3.25') do
|
||||
1.to_s == '1' and -1.to_s == "-1"
|
||||
assert_equal 1.to_s, '1'
|
||||
assert_equal(-1.to_s, "-1")
|
||||
end
|
||||
|
||||
assert('Integer#truncate', '15.2.8.3.26') do
|
||||
1.truncate == 1
|
||||
assert_equal 1.truncate, 1
|
||||
end
|
||||
|
||||
assert('Integer#upto', '15.2.8.3.27') do
|
||||
@@ -170,7 +183,7 @@ assert('Integer#upto', '15.2.8.3.27') do
|
||||
1.upto(3) do |i|
|
||||
a += i
|
||||
end
|
||||
a == 6
|
||||
assert_equal a, 6
|
||||
end
|
||||
|
||||
# Not ISO specified
|
||||
@@ -185,6 +198,6 @@ assert('Integer#step') do
|
||||
b << i
|
||||
end
|
||||
|
||||
a == [1, 2, 3] and
|
||||
b == [1, 3, 5]
|
||||
assert_equal a, [1, 2, 3]
|
||||
assert_equal b, [1, 3, 5]
|
||||
end
|
||||
|
||||
+106
-102
@@ -2,7 +2,7 @@
|
||||
# Kernel ISO Test
|
||||
|
||||
assert('Kernel', '15.3.1') do
|
||||
Kernel.class == Module
|
||||
assert_equal Kernel.class, Module
|
||||
end
|
||||
|
||||
assert('Kernel.block_given?', '15.3.1.2.2') do
|
||||
@@ -14,23 +14,29 @@ assert('Kernel.block_given?', '15.3.1.2.2') do
|
||||
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")
|
||||
assert_false Kernel.block_given?
|
||||
# test without block
|
||||
assert_equal bg_try, "no block"
|
||||
# test with block
|
||||
assert_equal "block" do
|
||||
bg_try { "block" }
|
||||
end
|
||||
# test with block
|
||||
assert_equal "block" do
|
||||
bg_try do
|
||||
"block"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Kernel.eval is provided by the mruby-gem mrbgem. '15.3.1.2.3'
|
||||
|
||||
assert('Kernel.global_variables', '15.3.1.2.4') do
|
||||
Kernel.global_variables.class == Array
|
||||
assert_equal Kernel.global_variables.class, Array
|
||||
end
|
||||
|
||||
assert('Kernel.iterator?', '15.3.1.2.5') do
|
||||
Kernel.iterator? == false
|
||||
assert_false Kernel.iterator?
|
||||
end
|
||||
|
||||
assert('Kernel.lambda', '15.3.1.2.6') do
|
||||
@@ -40,7 +46,10 @@ assert('Kernel.lambda', '15.3.1.2.6') do
|
||||
|
||||
m = Kernel.lambda(&l)
|
||||
|
||||
l.call and l.class == Proc and m.call and m.class == Proc
|
||||
assert_true l.call
|
||||
assert_equal l.class, Proc
|
||||
assert_true m.call
|
||||
assert_equal m.class, Proc
|
||||
end
|
||||
|
||||
# Not implemented at the moment
|
||||
@@ -56,47 +65,36 @@ assert('Kernel.loop', '15.3.1.2.8') do
|
||||
break if i == 100
|
||||
end
|
||||
|
||||
i == 100
|
||||
assert_equal i, 100
|
||||
end
|
||||
|
||||
assert('Kernel.p', '15.3.1.2.9') do
|
||||
# TODO search for a way to test p to stdio
|
||||
true
|
||||
assert_true true
|
||||
end
|
||||
|
||||
assert('Kernel.print', '15.3.1.2.10') do
|
||||
# TODO search for a way to test print to stdio
|
||||
true
|
||||
assert_true true
|
||||
end
|
||||
|
||||
assert('Kernel.puts', '15.3.1.2.11') do
|
||||
# TODO search for a way to test puts to stdio
|
||||
true
|
||||
assert_true true
|
||||
end
|
||||
|
||||
assert('Kernel.raise', '15.3.1.2.12') do
|
||||
e_list = []
|
||||
|
||||
begin
|
||||
assert_raise RuntimeError do
|
||||
Kernel.raise
|
||||
rescue => e
|
||||
e_list << e
|
||||
end
|
||||
|
||||
begin
|
||||
assert_raise RuntimeError do
|
||||
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
|
||||
assert_equal __id__.class, Fixnum
|
||||
end
|
||||
|
||||
assert('Kernel#__send__', '15.3.1.3.4') do
|
||||
@@ -105,11 +103,12 @@ assert('Kernel#__send__', '15.3.1.3.4') 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
|
||||
assert_true l.call
|
||||
assert_equal l.class, Proc
|
||||
# test with argument
|
||||
assert_true __send__(:respond_to?, :nil?)
|
||||
# test without argument and without block
|
||||
assert_equal __send__(:public_methods).class, Array
|
||||
end
|
||||
|
||||
assert('Kernel#block_given?', '15.3.1.3.6') do
|
||||
@@ -121,14 +120,20 @@ assert('Kernel#block_given?', '15.3.1.3.6') do
|
||||
end
|
||||
end
|
||||
|
||||
(block_given? == false) and
|
||||
(bg_try == "no block") and
|
||||
((bg_try { "block" }) == "block") and
|
||||
((bg_try do "block" end) == "block")
|
||||
assert_false block_given?
|
||||
assert_equal bg_try, "no block"
|
||||
assert_equal "block" do
|
||||
bg_try { "block" }
|
||||
end
|
||||
assert_equal "block" do
|
||||
bg_try do
|
||||
"block"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert('Kernel#class', '15.3.1.3.7') do
|
||||
Kernel.class == Module
|
||||
assert_equal Kernel.class, Module
|
||||
end
|
||||
|
||||
assert('Kernel#clone', '15.3.1.3.8') do
|
||||
@@ -165,10 +170,12 @@ assert('Kernel#clone', '15.3.1.3.8') do
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
assert_equal a.get, 2
|
||||
assert_equal b.get, 1
|
||||
assert_equal c.get, 2
|
||||
assert_true a.respond_to?(:test)
|
||||
assert_false b.respond_to?(:test)
|
||||
assert_true c.respond_to?(:test)
|
||||
end
|
||||
|
||||
assert('Kernel#dup', '15.3.1.3.9') do
|
||||
@@ -205,11 +212,13 @@ assert('Kernel#dup', '15.3.1.3.9') do
|
||||
end
|
||||
end
|
||||
|
||||
error_count == immutables.size and
|
||||
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
|
||||
assert_equal error_count, immutables.size
|
||||
assert_equal a.get, 2
|
||||
assert_equal b.get, 1
|
||||
assert_equal c.get, 2
|
||||
assert_true a.respond_to?(:test)
|
||||
assert_false b.respond_to?(:test)
|
||||
assert_false c.respond_to?(:test)
|
||||
end
|
||||
|
||||
# Kernel#eval is provided by mruby-eval mrbgem '15.3.1.3.12'
|
||||
@@ -226,7 +235,8 @@ assert('Kernel#extend', '15.3.1.3.13') do
|
||||
a.extend(Test4ExtendModule)
|
||||
b = Test4ExtendClass.new
|
||||
|
||||
a.respond_to?(:test_method) == true && b.respond_to?(:test_method) == false
|
||||
assert_true a.respond_to?(:test_method)
|
||||
assert_false b.respond_to?(:test_method)
|
||||
end
|
||||
|
||||
assert('Kernel#extend works on toplevel', '15.3.1.3.13') do
|
||||
@@ -236,20 +246,22 @@ assert('Kernel#extend works on toplevel', '15.3.1.3.13') do
|
||||
# This would crash...
|
||||
extend(Test4ExtendModule)
|
||||
|
||||
respond_to?(:test_method) == true
|
||||
assert_true respond_to?(:test_method)
|
||||
end
|
||||
|
||||
assert('Kernel#global_variables', '15.3.1.3.14') do
|
||||
global_variables.class == Array
|
||||
assert_equal global_variables.class, Array
|
||||
end
|
||||
|
||||
assert('Kernel#hash', '15.3.1.3.15') do
|
||||
hash == hash
|
||||
assert_equal hash, hash
|
||||
end
|
||||
|
||||
assert('Kernel#inspect', '15.3.1.3.17') do
|
||||
s = inspect
|
||||
s.class == String and s == "main"
|
||||
|
||||
assert_equal s.class, String
|
||||
assert_equal s, "main"
|
||||
end
|
||||
|
||||
assert('Kernel#instance_variables', '15.3.1.3.23') do
|
||||
@@ -259,19 +271,25 @@ assert('Kernel#instance_variables', '15.3.1.3.23') do
|
||||
@b = 12
|
||||
end
|
||||
ivars = o.instance_variables
|
||||
ivars.class == Array and ivars.size == 2 and ivars.include?(:@a) and ivars.include?(:@b)
|
||||
|
||||
assert_equal ivars.class, Array
|
||||
assert_equal ivars.size, 2
|
||||
assert_true ivars.include?(:@a)
|
||||
assert_true ivars.include?(:@b)
|
||||
end
|
||||
|
||||
assert('Kernel#is_a?', '15.3.1.3.24') do
|
||||
is_a?(Kernel) and not is_a?(Array)
|
||||
assert_true is_a?(Kernel)
|
||||
assert_false is_a?(Array)
|
||||
end
|
||||
|
||||
assert('Kernel#iterator?', '15.3.1.3.25') do
|
||||
iterator? == false
|
||||
assert_false iterator?
|
||||
end
|
||||
|
||||
assert('Kernel#kind_of?', '15.3.1.3.26') do
|
||||
kind_of?(Kernel) and not kind_of?(Array)
|
||||
assert_true kind_of?(Kernel)
|
||||
assert_false kind_of?(Array)
|
||||
end
|
||||
|
||||
assert('Kernel#lambda', '15.3.1.3.27') do
|
||||
@@ -281,7 +299,10 @@ assert('Kernel#lambda', '15.3.1.3.27') do
|
||||
|
||||
m = lambda(&l)
|
||||
|
||||
l.call and l.class == Proc and m.call and m.class == Proc
|
||||
assert_true l.call
|
||||
assert_equal l.class, Proc
|
||||
assert_true m.call
|
||||
assert_equal m.class, Proc
|
||||
end
|
||||
|
||||
# Not implemented yet
|
||||
@@ -297,19 +318,19 @@ assert('Kernel#loop', '15.3.1.3.29') do
|
||||
break if i == 100
|
||||
end
|
||||
|
||||
i == 100
|
||||
assert_equal i, 100
|
||||
end
|
||||
|
||||
assert('Kernel#methods', '15.3.1.3.31') do
|
||||
methods.class == Array
|
||||
assert_equal methods.class, Array
|
||||
end
|
||||
|
||||
assert('Kernel#nil?', '15.3.1.3.32') do
|
||||
nil? == false
|
||||
assert_false nil?
|
||||
end
|
||||
|
||||
assert('Kernel#object_id', '15.3.1.3.33') do
|
||||
object_id.class == Fixnum
|
||||
assert_equal object_id.class, Fixnum
|
||||
end
|
||||
|
||||
# Kernel#p is defined in mruby-print mrbgem. '15.3.1.3.34'
|
||||
@@ -317,45 +338,32 @@ end
|
||||
# Kernel#print is defined in mruby-print mrbgem. '15.3.1.3.35'
|
||||
|
||||
assert('Kernel#private_methods', '15.3.1.3.36') do
|
||||
private_methods.class == Array
|
||||
assert_equal private_methods.class, Array
|
||||
end
|
||||
|
||||
assert('Kernel#protected_methods', '15.3.1.3.37') do
|
||||
protected_methods.class == Array
|
||||
assert_equal protected_methods.class, Array
|
||||
end
|
||||
|
||||
assert('Kernel#public_methods', '15.3.1.3.38') do
|
||||
public_methods.class == Array
|
||||
assert_equal public_methods.class, Array
|
||||
end
|
||||
|
||||
# Kernel#puts is defined in mruby-print mrbgem. '15.3.1.3.39'
|
||||
|
||||
assert('Kernel#raise', '15.3.1.3.40') do
|
||||
e_list = []
|
||||
|
||||
begin
|
||||
assert_raise RuntimeError do
|
||||
raise
|
||||
rescue => e
|
||||
e_list << e
|
||||
end
|
||||
|
||||
begin
|
||||
assert_raise RuntimeError do
|
||||
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
|
||||
|
||||
# Kernel#require is defined in mruby-require. '15.3.1.3.42'
|
||||
|
||||
assert('Kernel#respond_to?', '15.3.1.3.43') do
|
||||
e_list = []
|
||||
|
||||
class Test4RespondTo
|
||||
def valid_method; end
|
||||
|
||||
@@ -363,17 +371,14 @@ assert('Kernel#respond_to?', '15.3.1.3.43') do
|
||||
undef test_method
|
||||
end
|
||||
|
||||
begin
|
||||
assert_raise TypeError do
|
||||
Test4RespondTo.new.respond_to?(1)
|
||||
rescue => e
|
||||
e_list << e.class
|
||||
end
|
||||
|
||||
e_list[0] == TypeError and
|
||||
respond_to?(:nil?) and
|
||||
Test4RespondTo.new.respond_to?(:valid_method) == true and
|
||||
Test4RespondTo.new.respond_to?('valid_method') == true and
|
||||
Test4RespondTo.new.respond_to?(:test_method) == false
|
||||
assert_true respond_to?(:nil?)
|
||||
assert_true Test4RespondTo.new.respond_to?(:valid_method)
|
||||
assert_true Test4RespondTo.new.respond_to?('valid_method')
|
||||
assert_false Test4RespondTo.new.respond_to?(:test_method)
|
||||
end
|
||||
|
||||
assert('Kernel#send', '15.3.1.3.44') do
|
||||
@@ -382,19 +387,20 @@ assert('Kernel#send', '15.3.1.3.44') 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
|
||||
assert_true l.call
|
||||
assert_equal l.class, Proc
|
||||
# test with argument
|
||||
assert_true send(:respond_to?, :nil?)
|
||||
# test without argument and without block
|
||||
assert_equal send(:public_methods).class, Array
|
||||
end
|
||||
|
||||
assert('Kernel#singleton_methods', '15.3.1.3.45') do
|
||||
singleton_methods.class == Array
|
||||
assert_equal singleton_methods.class, Array
|
||||
end
|
||||
|
||||
assert('Kernel#to_s', '15.3.1.3.46') do
|
||||
to_s.class == String
|
||||
assert_equal to_s.class, String
|
||||
end
|
||||
|
||||
assert('Kernel#!=') do
|
||||
@@ -402,20 +408,18 @@ assert('Kernel#!=') do
|
||||
str2 = str1
|
||||
str3 = "world"
|
||||
|
||||
(str1[1] != 'e') == false and
|
||||
(str1 != str3) == true and
|
||||
(str2 != str1) == false
|
||||
assert_false (str1[1] != 'e')
|
||||
assert_true (str1 != str3)
|
||||
assert_false (str2 != str1)
|
||||
end
|
||||
|
||||
assert('Kernel#respond_to_missing?') do
|
||||
|
||||
class Test4RespondToMissing
|
||||
def respond_to_missing?(method_name, include_private = false)
|
||||
method_name == :a_method
|
||||
end
|
||||
end
|
||||
|
||||
Test4RespondToMissing.new.respond_to?(:a_method) == true and
|
||||
Test4RespondToMissing.new.respond_to?(:no_method) == false
|
||||
|
||||
assert_true Test4RespondToMissing.new.respond_to?(:a_method)
|
||||
assert_false Test4RespondToMissing.new.respond_to?(:no_method)
|
||||
end
|
||||
|
||||
+101
-78
@@ -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
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
##
|
||||
# LocalJumpError ISO Test
|
||||
|
||||
assert('LocalJumoError', '15.2.25') do
|
||||
begin
|
||||
assert('LocalJumpError', '15.2.25') do
|
||||
assert_equal LocalJumpError.class, Class
|
||||
assert_raise LocalJumpError do
|
||||
# this will cause an exception due to the wrong location
|
||||
retry
|
||||
rescue => e1
|
||||
end
|
||||
LocalJumpError.class == Class and e1.class == LocalJumpError
|
||||
end
|
||||
|
||||
# TODO 15.2.25.2.1 LocalJumpError#exit_value
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
##
|
||||
# Chapter 13.3 "Methods" ISO Test
|
||||
|
||||
assert('The alias statement', '13.3.6 a) 4)') do
|
||||
# check aliasing in all possible ways
|
||||
|
||||
def alias_test_method_original; true; end
|
||||
|
||||
alias alias_test_method_a alias_test_method_original
|
||||
alias :alias_test_method_b :alias_test_method_original
|
||||
|
||||
assert_true(alias_test_method_original)
|
||||
assert_true(alias_test_method_a)
|
||||
assert_true(alias_test_method_b)
|
||||
end
|
||||
|
||||
assert('The alias statement (overwrite original)', '13.3.6 a) 4)') do
|
||||
# check that an aliased method can be overwritten
|
||||
# without side effect
|
||||
|
||||
def alias_test_method_original; true; end
|
||||
|
||||
alias alias_test_method_a alias_test_method_original
|
||||
alias :alias_test_method_b :alias_test_method_original
|
||||
|
||||
assert_true(alias_test_method_original)
|
||||
|
||||
def alias_test_method_original; false; end
|
||||
|
||||
assert_false(alias_test_method_original)
|
||||
assert_true(alias_test_method_a)
|
||||
assert_true(alias_test_method_b)
|
||||
end
|
||||
|
||||
assert('The alias statement', '13.3.6 a) 5)') do
|
||||
# check that alias is raising NameError if
|
||||
# non-existing method should be undefined
|
||||
|
||||
assert_raise(NameError) do
|
||||
alias new_name_a non_existing_method
|
||||
end
|
||||
|
||||
assert_raise(NameError) do
|
||||
alias :new_name_b :non_existing_method
|
||||
end
|
||||
end
|
||||
|
||||
assert('The undef statement', '13.3.7 a) 4)') do
|
||||
# check that undef is undefining method
|
||||
# based on the method name
|
||||
|
||||
def existing_method_a; true; end
|
||||
def existing_method_b; true; end
|
||||
def existing_method_c; true; end
|
||||
def existing_method_d; true; end
|
||||
def existing_method_e; true; end
|
||||
def existing_method_f; true; end
|
||||
|
||||
# check that methods are defined
|
||||
|
||||
assert_true(existing_method_a, 'Method should be defined')
|
||||
assert_true(existing_method_b, 'Method should be defined')
|
||||
assert_true(existing_method_c, 'Method should be defined')
|
||||
assert_true(existing_method_d, 'Method should be defined')
|
||||
assert_true(existing_method_e, 'Method should be defined')
|
||||
assert_true(existing_method_f, 'Method should be defined')
|
||||
|
||||
# undefine in all possible ways and check that method
|
||||
# is undefined
|
||||
|
||||
undef existing_method_a
|
||||
assert_raise(NoMethodError) do
|
||||
existing_method_a
|
||||
end
|
||||
|
||||
undef :existing_method_b
|
||||
assert_raise(NoMethodError) do
|
||||
existing_method_b
|
||||
end
|
||||
|
||||
undef existing_method_c, existing_method_d
|
||||
assert_raise(NoMethodError) do
|
||||
existing_method_c
|
||||
end
|
||||
assert_raise(NoMethodError) do
|
||||
existing_method_d
|
||||
end
|
||||
|
||||
undef :existing_method_e, :existing_method_f
|
||||
assert_raise(NoMethodError) do
|
||||
existing_method_e
|
||||
end
|
||||
assert_raise(NoMethodError) do
|
||||
existing_method_f
|
||||
end
|
||||
end
|
||||
|
||||
assert('The undef statement (method undefined)', '13.3.7 a) 5)') do
|
||||
# check that undef is raising NameError if
|
||||
# non-existing method should be undefined
|
||||
|
||||
assert_raise(NameError) do
|
||||
undef non_existing_method
|
||||
end
|
||||
|
||||
assert_raise(NameError) do
|
||||
undef :non_existing_method
|
||||
end
|
||||
end
|
||||
+85
-80
@@ -2,11 +2,11 @@
|
||||
# Module ISO Test
|
||||
|
||||
assert('Module', '15.2.2') do
|
||||
Module.class == Class
|
||||
assert_equal Module.class, Class
|
||||
end
|
||||
|
||||
assert('Module superclass', '15.2.2.2') do
|
||||
Module.superclass == Object
|
||||
assert_equal Module.superclass, Object
|
||||
end
|
||||
|
||||
# TODO not implemented ATM assert('Module.constants', '15.2.2.3.1') do
|
||||
@@ -18,7 +18,10 @@ assert('Module#ancestors', '15.2.2.4.9') do
|
||||
end
|
||||
sc = Test4ModuleAncestors.singleton_class
|
||||
r = String.ancestors
|
||||
r.class == Array and r.include?(String) and r.include?(Object)
|
||||
|
||||
assert_equal r.class, Array
|
||||
assert_true r.include?(String)
|
||||
assert_true r.include?(Object)
|
||||
end
|
||||
|
||||
assert('Module#append_features', '15.2.2.4.10') do
|
||||
@@ -31,7 +34,7 @@ assert('Module#append_features', '15.2.2.4.10') do
|
||||
include Test4AppendFeatures
|
||||
end
|
||||
|
||||
Test4AppendFeatures2.const_get(:Const4AppendFeatures2) == Test4AppendFeatures2
|
||||
assert_equal Test4AppendFeatures2.const_get(:Const4AppendFeatures2), Test4AppendFeatures2
|
||||
end
|
||||
|
||||
assert('Module#class_eval', '15.2.2.4.15') do
|
||||
@@ -44,9 +47,11 @@ assert('Module#class_eval', '15.2.2.4.15') do
|
||||
end
|
||||
end
|
||||
r = Test4ClassEval.instance_methods
|
||||
Test4ClassEval.class_eval{ @a } == 11 and
|
||||
Test4ClassEval.class_eval{ @b } == 12 and
|
||||
r.class == Array and r.include?(:method1)
|
||||
|
||||
assert_equal Test4ClassEval.class_eval{ @a }, 11
|
||||
assert_equal Test4ClassEval.class_eval{ @b }, 12
|
||||
assert_equal r.class, Array
|
||||
assert_true r.include?(:method1)
|
||||
end
|
||||
|
||||
assert('Module#class_variable_defined?', '15.2.2.4.16') do
|
||||
@@ -54,8 +59,8 @@ assert('Module#class_variable_defined?', '15.2.2.4.16') do
|
||||
@@cv = 99
|
||||
end
|
||||
|
||||
Test4ClassVariableDefined.class_variable_defined?(:@@cv) and
|
||||
not Test4ClassVariableDefined.class_variable_defined?(:@@noexisting)
|
||||
assert_true Test4ClassVariableDefined.class_variable_defined?(:@@cv)
|
||||
assert_false Test4ClassVariableDefined.class_variable_defined?(:@@noexisting)
|
||||
end
|
||||
|
||||
assert('Module#class_variable_get', '15.2.2.4.17') do
|
||||
@@ -63,7 +68,7 @@ assert('Module#class_variable_get', '15.2.2.4.17') do
|
||||
@@cv = 99
|
||||
end
|
||||
|
||||
Test4ClassVariableGet.class_variable_get(:@@cv) == 99
|
||||
assert_equal Test4ClassVariableGet.class_variable_get(:@@cv), 99
|
||||
end
|
||||
|
||||
assert('Module#class_variable_set', '15.2.2.4.18') do
|
||||
@@ -74,12 +79,11 @@ assert('Module#class_variable_set', '15.2.2.4.18') do
|
||||
end
|
||||
end
|
||||
|
||||
Test4ClassVariableSet.class_variable_set(:@@cv, 99)
|
||||
Test4ClassVariableSet.class_variable_set(:@@foo, 101)
|
||||
|
||||
Test4ClassVariableSet.class_variables.include? :@@cv and
|
||||
Test4ClassVariableSet.class_variable_get(:@@cv) == 99 and
|
||||
Test4ClassVariableSet.new.foo == 101
|
||||
assert_true Test4ClassVariableSet.class_variable_set(:@@cv, 99)
|
||||
assert_true Test4ClassVariableSet.class_variable_set(:@@foo, 101)
|
||||
assert_true Test4ClassVariableSet.class_variables.include? :@@cv
|
||||
assert_equal Test4ClassVariableSet.class_variable_get(:@@cv), 99
|
||||
assert_equal Test4ClassVariableSet.new.foo, 101
|
||||
end
|
||||
|
||||
assert('Module#class_variables', '15.2.2.4.19') do
|
||||
@@ -90,8 +94,8 @@ assert('Module#class_variables', '15.2.2.4.19') do
|
||||
@@var2 = 2
|
||||
end
|
||||
|
||||
Test4ClassVariables1.class_variables == [:@@var1] &&
|
||||
Test4ClassVariables2.class_variables == [:@@var2, :@@var1]
|
||||
assert_equal Test4ClassVariables1.class_variables, [:@@var1]
|
||||
assert_equal Test4ClassVariables2.class_variables, [:@@var2, :@@var1]
|
||||
end
|
||||
|
||||
assert('Module#const_defined?', '15.2.2.4.20') do
|
||||
@@ -99,8 +103,8 @@ assert('Module#const_defined?', '15.2.2.4.20') do
|
||||
Const4Test4ConstDefined = true
|
||||
end
|
||||
|
||||
Test4ConstDefined.const_defined?(:Const4Test4ConstDefined) and
|
||||
not Test4ConstDefined.const_defined?(:NotExisting)
|
||||
assert_true Test4ConstDefined.const_defined?(:Const4Test4ConstDefined)
|
||||
assert_false Test4ConstDefined.const_defined?(:NotExisting)
|
||||
end
|
||||
|
||||
assert('Module#const_get', '15.2.2.4.21') do
|
||||
@@ -108,7 +112,7 @@ assert('Module#const_get', '15.2.2.4.21') do
|
||||
Const4Test4ConstGet = 42
|
||||
end
|
||||
|
||||
Test4ConstGet.const_get(:Const4Test4ConstGet) == 42
|
||||
assert_equal Test4ConstGet.const_get(:Const4Test4ConstGet), 42
|
||||
end
|
||||
|
||||
assert('Module.const_missing', '15.2.2.4.22') do
|
||||
@@ -118,7 +122,7 @@ assert('Module.const_missing', '15.2.2.4.22') do
|
||||
end
|
||||
end
|
||||
|
||||
Test4ConstMissing.const_get(:ConstDoesntExist) == 42
|
||||
assert_equal Test4ConstMissing.const_get(:ConstDoesntExist), 42
|
||||
end
|
||||
|
||||
assert('Module#const_get', '15.2.2.4.23') do
|
||||
@@ -126,8 +130,8 @@ assert('Module#const_get', '15.2.2.4.23') do
|
||||
Const4Test4ConstSet = 42
|
||||
end
|
||||
|
||||
Test4ConstSet.const_set(:Const4Test4ConstSet, 23)
|
||||
Test4ConstSet.const_get(:Const4Test4ConstSet) == 23
|
||||
assert_true Test4ConstSet.const_set(:Const4Test4ConstSet, 23)
|
||||
assert_equal Test4ConstSet.const_get(:Const4Test4ConstSet), 23
|
||||
end
|
||||
|
||||
assert('Module.constants', '15.2.2.4.24') do
|
||||
@@ -141,8 +145,8 @@ assert('Module.constants', '15.2.2.4.24') do
|
||||
$n = constants.sort
|
||||
end
|
||||
|
||||
TestA.constants == [ :Const ] and
|
||||
$n == [ :Const, :Const2 ]
|
||||
assert_equal TestA.constants, [ :Const ]
|
||||
assert_equal $n, [ :Const, :Const2 ]
|
||||
end
|
||||
|
||||
assert('Module#include', '15.2.2.4.27') do
|
||||
@@ -153,7 +157,7 @@ assert('Module#include', '15.2.2.4.27') do
|
||||
include Test4Include
|
||||
end
|
||||
|
||||
Test4Include2.const_get(:Const4Include) == 42
|
||||
assert_equal Test4Include2.const_get(:Const4Include), 42
|
||||
end
|
||||
|
||||
assert('Module#include?', '15.2.2.4.28') do
|
||||
@@ -165,9 +169,9 @@ assert('Module#include?', '15.2.2.4.28') do
|
||||
class Test4IncludeP3 < Test4IncludeP2
|
||||
end
|
||||
|
||||
Test4IncludeP2.include?(Test4IncludeP) &&
|
||||
Test4IncludeP3.include?(Test4IncludeP) &&
|
||||
! Test4IncludeP.include?(Test4IncludeP)
|
||||
assert_true Test4IncludeP2.include?(Test4IncludeP)
|
||||
assert_true Test4IncludeP3.include?(Test4IncludeP)
|
||||
assert_false Test4IncludeP.include?(Test4IncludeP)
|
||||
end
|
||||
|
||||
assert('Module#included', '15.2.2.4.29') do
|
||||
@@ -181,8 +185,8 @@ assert('Module#included', '15.2.2.4.29') do
|
||||
include Test4Included
|
||||
end
|
||||
|
||||
Test4Included2.const_get(:Const4Included) == 42 and
|
||||
Test4Included2.const_get(:Const4Included2) == Test4Included2
|
||||
assert_equal Test4Included2.const_get(:Const4Included), 42
|
||||
assert_equal Test4Included2.const_get(:Const4Included2), Test4Included2
|
||||
end
|
||||
|
||||
assert('Module#included_modules', '15.2.2.4.30') do
|
||||
@@ -191,28 +195,31 @@ assert('Module#included_modules', '15.2.2.4.30') do
|
||||
module Test4includedModules2
|
||||
include Test4includedModules
|
||||
end
|
||||
|
||||
r = Test4includedModules2.included_modules
|
||||
r.class == Array and r.include?(Test4includedModules)
|
||||
|
||||
assert_equal r.class, Array
|
||||
assert_true r.include?(Test4includedModules)
|
||||
end
|
||||
|
||||
assert('Module#instance_methods', '15.2.2.4.33') do
|
||||
module Test4InstanceMethodsA
|
||||
def method1() end
|
||||
end
|
||||
class Test4InstanceMethodsB
|
||||
def method2() end
|
||||
end
|
||||
class Test4InstanceMethodsC < Test4InstanceMethodsB
|
||||
def method3() end
|
||||
end
|
||||
module Test4InstanceMethodsA
|
||||
def method1() end
|
||||
end
|
||||
class Test4InstanceMethodsB
|
||||
def method2() end
|
||||
end
|
||||
class Test4InstanceMethodsC < Test4InstanceMethodsB
|
||||
def method3() end
|
||||
end
|
||||
|
||||
r = Test4InstanceMethodsC.instance_methods(true)
|
||||
r = Test4InstanceMethodsC.instance_methods(true)
|
||||
|
||||
Test4InstanceMethodsA.instance_methods == [:method1] and
|
||||
Test4InstanceMethodsB.instance_methods(false) == [:method2] and
|
||||
Test4InstanceMethodsC.instance_methods(false) == [:method3] and
|
||||
r.class == Array and r.include?(:method3) and r.include?(:method2)
|
||||
assert_equal Test4InstanceMethodsA.instance_methods, [:method1]
|
||||
assert_equal Test4InstanceMethodsB.instance_methods(false), [:method2]
|
||||
assert_equal Test4InstanceMethodsC.instance_methods(false), [:method3]
|
||||
assert_equal r.class, Array
|
||||
assert_true r.include?(:method3)
|
||||
assert_true r.include?(:method2)
|
||||
end
|
||||
|
||||
assert('Module#method_defined?', '15.2.2.4.34') do
|
||||
@@ -231,21 +238,22 @@ assert('Module#method_defined?', '15.2.2.4.34') do
|
||||
end
|
||||
end
|
||||
|
||||
Test4MethodDefined::A.method_defined? :method1 and
|
||||
Test4MethodDefined::C.method_defined? :method1 and
|
||||
Test4MethodDefined::C.method_defined? "method2" and
|
||||
Test4MethodDefined::C.method_defined? "method3" and
|
||||
not Test4MethodDefined::C.method_defined? "method4"
|
||||
assert_true Test4MethodDefined::A.method_defined? :method1
|
||||
assert_true Test4MethodDefined::C.method_defined? :method1
|
||||
assert_true Test4MethodDefined::C.method_defined? "method2"
|
||||
assert_true Test4MethodDefined::C.method_defined? "method3"
|
||||
assert_false Test4MethodDefined::C.method_defined? "method4"
|
||||
end
|
||||
|
||||
|
||||
assert('Module#module_eval', '15.2.2.4.35') do
|
||||
module Test4ModuleEval
|
||||
@a = 11
|
||||
@b = 12
|
||||
end
|
||||
Test4ModuleEval.module_eval{ @a } == 11 and
|
||||
Test4ModuleEval.module_eval{ @b } == 12
|
||||
module Test4ModuleEval
|
||||
@a = 11
|
||||
@b = 12
|
||||
end
|
||||
|
||||
assert_equal Test4ModuleEval.module_eval{ @a }, 11
|
||||
assert_equal Test4ModuleEval.module_eval{ @b }, 12
|
||||
end
|
||||
|
||||
assert('Module#remove_class_variable', '15.2.2.4.39') do
|
||||
@@ -253,16 +261,16 @@ assert('Module#remove_class_variable', '15.2.2.4.39') do
|
||||
@@cv = 99
|
||||
end
|
||||
|
||||
Test4RemoveClassVariable.remove_class_variable(:@@cv) == 99 and
|
||||
not Test4RemoveClassVariable.class_variables.include? :@@cv
|
||||
assert_equal Test4RemoveClassVariable.remove_class_variable(:@@cv), 99
|
||||
assert_false Test4RemoveClassVariable.class_variables.include? :@@cv
|
||||
end
|
||||
|
||||
assert('Module#remove_const', '15.2.2.4.40') do
|
||||
module Test4RemoveConst
|
||||
ExistingConst = 23
|
||||
ExistingConst = 23
|
||||
end
|
||||
|
||||
result = Test4RemoveConst.module_eval { remove_const :ExistingConst }
|
||||
result = Test4RemoveConst.module_eval { remove_const :ExistingConst }
|
||||
|
||||
name_error = false
|
||||
begin
|
||||
@@ -272,11 +280,11 @@ assert('Module#remove_const', '15.2.2.4.40') do
|
||||
end
|
||||
|
||||
# Constant removed from Module
|
||||
not Test4RemoveConst.const_defined? :ExistingConst and
|
||||
# Return value of binding
|
||||
result == 23 and
|
||||
# Name Error raised when Constant doesn't exist
|
||||
name_error
|
||||
assert_false Test4RemoveConst.const_defined? :ExistingConst
|
||||
# Return value of binding
|
||||
assert_equal result, 23
|
||||
# Name Error raised when Constant doesn't exist
|
||||
assert_true name_error
|
||||
end
|
||||
|
||||
assert('Module#remove_method', '15.2.2.4.41') do
|
||||
@@ -289,13 +297,12 @@ assert('Module#remove_method', '15.2.2.4.41') do
|
||||
class Child < Parent
|
||||
def hello
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Test4RemoveMethod::Child.class_eval{ remove_method :hello }
|
||||
|
||||
Test4RemoveMethod::Child.instance_methods.include? :hello and
|
||||
not Test4RemoveMethod::Child.instance_methods(false).include? :hello
|
||||
assert_true Test4RemoveMethod::Child.class_eval{ remove_method :hello }
|
||||
assert_true Test4RemoveMethod::Child.instance_methods.include? :hello
|
||||
assert_false Test4RemoveMethod::Child.instance_methods(false).include? :hello
|
||||
end
|
||||
|
||||
assert('Module.undef_method', '15.2.2.4.42') do
|
||||
@@ -313,27 +320,25 @@ assert('Module.undef_method', '15.2.2.4.42') do
|
||||
class GrandChild < Child
|
||||
end
|
||||
end
|
||||
|
||||
Test4UndefMethod::Child.class_eval{ undef_method :hello }
|
||||
|
||||
Test4UndefMethod::Parent.new.respond_to?(:hello) and
|
||||
not Test4UndefMethod::Child.new.respond_to?(:hello) and
|
||||
not Test4UndefMethod::GrandChild.new.respond_to?(:hello)
|
||||
assert_true Test4UndefMethod::Parent.new.respond_to?(:hello)
|
||||
assert_false Test4UndefMethod::Child.new.respond_to?(:hello)
|
||||
assert_false Test4UndefMethod::GrandChild.new.respond_to?(:hello)
|
||||
end
|
||||
|
||||
|
||||
# Not ISO specified
|
||||
|
||||
assert('Module#to_s') do
|
||||
module Test4to_sModules
|
||||
end
|
||||
|
||||
Test4to_sModules.to_s == 'Test4to_sModules'
|
||||
assert_equal Test4to_sModules.to_s, 'Test4to_sModules'
|
||||
end
|
||||
|
||||
assert('Module#inspect') do
|
||||
module Test4to_sModules
|
||||
end
|
||||
|
||||
Test4to_sModules.inspect == 'Test4to_sModules'
|
||||
assert_equal Test4to_sModules.inspect, 'Test4to_sModules'
|
||||
end
|
||||
|
||||
+6
-6
@@ -2,11 +2,11 @@
|
||||
# NameError ISO Test
|
||||
|
||||
assert('NameError', '15.2.31') do
|
||||
NameError.class == Class
|
||||
assert_equal NameError.class, Class
|
||||
end
|
||||
|
||||
assert('NameError superclass', '15.2.31.2') do
|
||||
NameError.superclass == StandardError
|
||||
assert_equal NameError.superclass, StandardError
|
||||
end
|
||||
|
||||
assert('NameError#name', '15.2.31.2.1') do
|
||||
@@ -20,13 +20,13 @@ assert('NameError#name', '15.2.31.2.1') do
|
||||
$test_dummy_result = e.name
|
||||
end
|
||||
|
||||
$test_dummy_result == :bar
|
||||
assert_equal $test_dummy_result, :bar
|
||||
end
|
||||
|
||||
assert('NameError#initialize', '15.2.31.2.2') do
|
||||
e = NameError.new('a', :foo)
|
||||
|
||||
e.class == NameError and
|
||||
e.message == 'a' and
|
||||
e.name == :foo
|
||||
assert_equal e.class, NameError
|
||||
assert_equal e.message, 'a'
|
||||
assert_equal e.name, :foo
|
||||
end
|
||||
|
||||
+10
-6
@@ -2,25 +2,29 @@
|
||||
# NilClass ISO Test
|
||||
|
||||
assert('NilClass', '15.2.4') do
|
||||
NilClass.class == Class
|
||||
assert_equal NilClass.class, Class
|
||||
end
|
||||
|
||||
assert('NilClass#&', '15.2.4.3.1') do
|
||||
not nil.&(true) and not nil.&(nil)
|
||||
assert_false nil.&(true)
|
||||
assert_false nil.&(nil)
|
||||
end
|
||||
|
||||
assert('NilClass#^', '15.2.4.3.2') do
|
||||
nil.^(true) and not nil.^(false)
|
||||
assert_true nil.^(true)
|
||||
assert_false nil.^(false)
|
||||
end
|
||||
|
||||
assert('NilClass#|', '15.2.4.3.3') do
|
||||
nil.|(true) and not nil.|(false)
|
||||
assert_true nil.|(true)
|
||||
assert_false nil.|(false)
|
||||
end
|
||||
|
||||
assert('NilClass#nil?', '15.2.4.3.4') do
|
||||
nil.nil?
|
||||
assert_true nil.nil?
|
||||
end
|
||||
|
||||
assert('NilClass#to_s', '15.2.4.3.5') do
|
||||
nil.to_s == ''
|
||||
assert_equal nil.to_s, ''
|
||||
end
|
||||
|
||||
|
||||
@@ -2,17 +2,12 @@
|
||||
# NoMethodError ISO Test
|
||||
|
||||
assert('NoMethodError', '15.2.32') do
|
||||
e2 = nil
|
||||
begin
|
||||
NoMethodError.class == Class
|
||||
assert_raise NoMethodError do
|
||||
doesNotExistAsAMethodNameForVerySure("")
|
||||
rescue => e1
|
||||
e2 = e1
|
||||
end
|
||||
|
||||
NoMethodError.class == Class and e2.class == NoMethodError
|
||||
end
|
||||
|
||||
assert('NoMethodError superclass', '15.2.32.2') do
|
||||
NoMethodError.superclass == NameError
|
||||
assert_equal NoMethodError.superclass, NameError
|
||||
end
|
||||
|
||||
|
||||
+7
-6
@@ -2,27 +2,28 @@
|
||||
# Numeric ISO Test
|
||||
|
||||
assert('Numeric', '15.2.7') do
|
||||
Numeric.class == Class
|
||||
assert_equal Numeric.class, Class
|
||||
end
|
||||
|
||||
assert('Numeric superclass', '15.2.7.2') do
|
||||
Numeric.superclass == Object
|
||||
assert_equal Numeric.superclass, Object
|
||||
end
|
||||
|
||||
assert('Numeric#+@', '15.2.7.4.1') do
|
||||
+1 == +1
|
||||
assert_equal(+1, +1)
|
||||
end
|
||||
|
||||
assert('Numeric#-@', '15.2.7.4.2') do
|
||||
-1 == -1
|
||||
assert_equal(-1, -1)
|
||||
end
|
||||
|
||||
assert('Numeric#abs', '15.2.7.4.3') do
|
||||
1.abs == 1 and -1.abs == 1.0
|
||||
assert_equal(1.abs, 1)
|
||||
assert_equal(-1.abs, 1.0)
|
||||
end
|
||||
|
||||
# Not ISO specified
|
||||
|
||||
assert('Numeric#**') do
|
||||
2.0**3 == 8.0
|
||||
assert_equal 2.0**3, 8.0
|
||||
end
|
||||
|
||||
+2
-2
@@ -2,10 +2,10 @@
|
||||
# Object ISO Test
|
||||
|
||||
assert('Object', '15.2.1') do
|
||||
Object.class == Class
|
||||
assert_equal Object.class, Class
|
||||
end
|
||||
|
||||
assert('Object superclass', '15.2.1.2') do
|
||||
Object.superclass == BasicObject
|
||||
assert_equal Object.superclass, BasicObject
|
||||
end
|
||||
|
||||
|
||||
+12
-13
@@ -2,25 +2,19 @@
|
||||
# Proc ISO Test
|
||||
|
||||
assert('Proc', '15.2.17') do
|
||||
Proc.class == Class
|
||||
assert_equal Proc.class, Class
|
||||
end
|
||||
|
||||
assert('Proc superclass', '15.2.17.2') do
|
||||
Proc.superclass == Object
|
||||
assert_equal Proc.superclass, Object
|
||||
end
|
||||
|
||||
assert('Proc.new', '15.2.17.3.1') do
|
||||
a = nil
|
||||
|
||||
begin
|
||||
assert_raise ArgumentError do
|
||||
Proc.new
|
||||
rescue => e
|
||||
a = e
|
||||
end
|
||||
|
||||
b = Proc.new {}
|
||||
|
||||
a.class == ArgumentError and b.class == Proc
|
||||
assert_equal (Proc.new {}).class, Proc
|
||||
end
|
||||
|
||||
assert('Proc#[]', '15.2.17.4.1') do
|
||||
@@ -32,7 +26,8 @@ assert('Proc#[]', '15.2.17.4.1') do
|
||||
b2 = Proc.new { |i| a2 += i }
|
||||
b2.[](5)
|
||||
|
||||
a == 1 and a2 == 5
|
||||
assert_equal a, 1
|
||||
assert_equal a2, 5
|
||||
end
|
||||
|
||||
assert('Proc#arity', '15.2.17.4.2') do
|
||||
@@ -41,7 +36,10 @@ assert('Proc#arity', '15.2.17.4.2') do
|
||||
c = Proc.new {|x=0, y|}.arity
|
||||
d = Proc.new {|(x, y), z=0|}.arity
|
||||
|
||||
a == 2 and b == -3 and c == 1 and d == 1
|
||||
assert_equal a, 2
|
||||
assert_equal b, -3
|
||||
assert_equal c, 1
|
||||
assert_equal d, 1
|
||||
end
|
||||
|
||||
assert('Proc#call', '15.2.17.4.3') do
|
||||
@@ -53,5 +51,6 @@ assert('Proc#call', '15.2.17.4.3') do
|
||||
b2 = Proc.new { |i| a2 += i }
|
||||
b2.call(5)
|
||||
|
||||
a == 1 and a2 == 5
|
||||
assert_equal a, 1
|
||||
assert_equal a2, 5
|
||||
end
|
||||
|
||||
+21
-14
@@ -2,66 +2,73 @@
|
||||
# Range ISO Test
|
||||
|
||||
assert('Range', '15.2.14') do
|
||||
Range.class == Class
|
||||
assert_equal Range.class, Class
|
||||
end
|
||||
|
||||
assert('Range superclass', '15.2.14.2') do
|
||||
Range.superclass == Object
|
||||
assert_equal Range.superclass, Object
|
||||
end
|
||||
|
||||
assert('Range#==', '15.2.14.4.1') do
|
||||
(1..10) == (1..10) and not (1..10) == (1..100)
|
||||
assert_true (1..10) == (1..10)
|
||||
assert_false (1..10) == (1..100)
|
||||
end
|
||||
|
||||
assert('Range#===', '15.2.14.4.2') do
|
||||
a = (1..10)
|
||||
|
||||
a === 5 and not a === 20
|
||||
assert_true a === 5
|
||||
assert_false a === 20
|
||||
end
|
||||
|
||||
assert('Range#begin', '15.2.14.4.3') do
|
||||
(1..10).begin == 1
|
||||
assert_equal (1..10).begin, 1
|
||||
end
|
||||
|
||||
assert('Range#each', '15.2.14.4.4') do
|
||||
a = (1..3)
|
||||
b = 0
|
||||
a.each {|i| b += i}
|
||||
b == 6
|
||||
assert_equal b, 6
|
||||
end
|
||||
|
||||
assert('Range#end', '15.2.14.4.5') do
|
||||
(1..10).end == 10
|
||||
assert_equal (1..10).end, 10
|
||||
end
|
||||
|
||||
assert('Range#exclude_end?', '15.2.14.4.6') do
|
||||
(1...10).exclude_end? and not (1..10).exclude_end?
|
||||
assert_true (1...10).exclude_end?
|
||||
assert_false (1..10).exclude_end?
|
||||
end
|
||||
|
||||
assert('Range#first', '15.2.14.4.7') do
|
||||
(1..10).first == 1
|
||||
assert_equal (1..10).first, 1
|
||||
end
|
||||
|
||||
assert('Range#include', '15.2.14.4.8') do
|
||||
a = (1..10)
|
||||
|
||||
a.include?(5) and not a.include?(20)
|
||||
assert_true a.include?(5)
|
||||
assert_false a.include?(20)
|
||||
end
|
||||
|
||||
assert('Range#initialize', '15.2.14.4.9') do
|
||||
a = Range.new(1, 10, true)
|
||||
b = Range.new(1, 10, false)
|
||||
|
||||
a == (1...10) and a.exclude_end? and b == (1..10) and
|
||||
not b.exclude_end?
|
||||
assert_equal a, (1...10)
|
||||
assert_true a.exclude_end?
|
||||
assert_equal b, (1..10)
|
||||
assert_false b.exclude_end?
|
||||
end
|
||||
|
||||
assert('Range#last', '15.2.14.4.10') do
|
||||
(1..10).last == 10
|
||||
assert_equal (1..10).last, 10
|
||||
end
|
||||
|
||||
assert('Range#member?', '15.2.14.4.11') do
|
||||
a = (1..10)
|
||||
|
||||
a.member?(5) and not a.member?(20)
|
||||
assert_true a.member?(5)
|
||||
assert_false a.member?(20)
|
||||
end
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
# RangeError ISO Test
|
||||
|
||||
assert('RangeError', '15.2.26') do
|
||||
RangeError.class == Class
|
||||
assert_equal RangeError.class, Class
|
||||
end
|
||||
|
||||
assert('RangeError superclass', '15.2.26.2') do
|
||||
RangeError.superclass == StandardError
|
||||
assert_equal RangeError.superclass, StandardError
|
||||
end
|
||||
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
# RuntimeError ISO Test
|
||||
|
||||
assert('RuntimeError', '15.2.28') do
|
||||
RuntimeError.class == Class
|
||||
assert_equal RuntimeError.class, Class
|
||||
end
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
# StandardError ISO Test
|
||||
|
||||
assert('StandardError', '15.2.23') do
|
||||
StandardError.class == Class
|
||||
assert_equal StandardError.class, Class
|
||||
end
|
||||
|
||||
assert('StandardError superclass', '15.2.23.2') do
|
||||
StandardError.superclass == Exception
|
||||
assert_equal StandardError.superclass, Exception
|
||||
end
|
||||
|
||||
|
||||
+129
-67
@@ -2,19 +2,19 @@
|
||||
# String ISO Test
|
||||
|
||||
assert('String', '15.2.10') do
|
||||
String.class == Class
|
||||
assert_equal String.class, Class
|
||||
end
|
||||
|
||||
assert('String superclass', '15.2.10.2') do
|
||||
String.superclass == Object
|
||||
assert_equal String.superclass, Object
|
||||
end
|
||||
|
||||
assert('String#*', '15.2.10.5.1') do
|
||||
'a' * 5 == 'aaaaa'
|
||||
assert_equal 'a' * 5, 'aaaaa'
|
||||
end
|
||||
|
||||
assert('String#+', '15.2.10.5.2') do
|
||||
'a' + 'b' == 'ab'
|
||||
assert_equal 'a' + 'b', 'ab'
|
||||
end
|
||||
|
||||
assert('String#<=>', '15.2.10.5.3') do
|
||||
@@ -24,12 +24,16 @@ assert('String#<=>', '15.2.10.5.3') do
|
||||
d = 'abc' <=> 'cba'
|
||||
e = 'cba' <=> 'abc'
|
||||
|
||||
a == 0 and b == -1 and c == 1 and
|
||||
d == -1 and e == 1
|
||||
assert_equal a, 0
|
||||
assert_equal b, -1
|
||||
assert_equal c, 1
|
||||
assert_equal d, -1
|
||||
assert_equal e, 1
|
||||
end
|
||||
|
||||
assert('String#==', '15.2.10.5.4') do
|
||||
'abc' == 'abc' and not 'abc' == 'cba'
|
||||
assert_equal 'abc', 'abc'
|
||||
assert_not_equal 'abc', 'cba'
|
||||
end
|
||||
|
||||
# 'String#=~', '15.2.10.5.5' will be tested in mrbgems.
|
||||
@@ -55,10 +59,17 @@ assert('String#[]', '15.2.10.5.6') do
|
||||
a3 = 'abc'['bc']
|
||||
b3 = 'abc'['XX']
|
||||
|
||||
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
|
||||
a3 == 'bc' and b3 == nil
|
||||
assert_equal a, 'a'
|
||||
assert_equal b, 'c'
|
||||
assert_nil c
|
||||
assert_nil d
|
||||
assert_nil a1
|
||||
assert_nil b1
|
||||
assert_nil c1
|
||||
assert_equal d1, ''
|
||||
assert_equal e1, 'bc'
|
||||
assert_equal a3, 'bc'
|
||||
assert_nil b3
|
||||
end
|
||||
|
||||
assert('String#[] with Range') do
|
||||
@@ -81,24 +92,39 @@ assert('String#[] with Range') do
|
||||
h2 = 'abc'[3...4]
|
||||
i2 = 'abc'[4...5]
|
||||
|
||||
a1 == '' and b1 == 'b' and c1 == 'bc' and d1 == 'bc' and e1 == 'bc' and
|
||||
f1 == 'ab' and g1 == 'bc' and h1 == '' and i2 == nil and
|
||||
a2 == '' and b2 == '' and c2 == 'b' and d2 == 'bc' and e2 == 'bc' and
|
||||
f2 == 'a' and g2 == 'bc' and h2 == '' and i2 == nil
|
||||
assert_equal a1, ''
|
||||
assert_equal b1, 'b'
|
||||
assert_equal c1, 'bc'
|
||||
assert_equal d1, 'bc'
|
||||
assert_equal e1, 'bc'
|
||||
assert_equal f1, 'ab'
|
||||
assert_equal g1, 'bc'
|
||||
assert_equal h1, ''
|
||||
assert_nil i2
|
||||
assert_equal a2, ''
|
||||
assert_equal b2, ''
|
||||
assert_equal c2, 'b'
|
||||
assert_equal d2, 'bc'
|
||||
assert_equal e2, 'bc'
|
||||
assert_equal f2, 'a'
|
||||
assert_equal g2, 'bc'
|
||||
assert_equal h2, ''
|
||||
assert_nil i2
|
||||
end
|
||||
|
||||
assert('String#capitalize', '15.2.10.5.7') do
|
||||
a = 'abc'
|
||||
a.capitalize
|
||||
|
||||
a == 'abc' and 'abc'.capitalize == 'Abc'
|
||||
assert_equal a, 'abc'
|
||||
assert_equal 'abc'.capitalize, 'Abc'
|
||||
end
|
||||
|
||||
assert('String#capitalize!', '15.2.10.5.8') do
|
||||
a = 'abc'
|
||||
a.capitalize!
|
||||
|
||||
a == 'Abc'
|
||||
assert_equal a, 'Abc'
|
||||
end
|
||||
|
||||
assert('String#chomp', '15.2.10.5.9') do
|
||||
@@ -111,8 +137,12 @@ assert('String#chomp', '15.2.10.5.9') do
|
||||
|
||||
f.chomp
|
||||
|
||||
a == 'abc' and b == '' and c == 'abc' and
|
||||
d == "abc\n" and e == 'abc' and f == "abc\n"
|
||||
assert_equal a, 'abc'
|
||||
assert_equal b, ''
|
||||
assert_equal c, 'abc'
|
||||
assert_equal d, "abc\n"
|
||||
assert_equal e, 'abc'
|
||||
assert_equal f, "abc\n"
|
||||
end
|
||||
|
||||
assert('String#chomp!', '15.2.10.5.10') do
|
||||
@@ -128,8 +158,11 @@ assert('String#chomp!', '15.2.10.5.10') do
|
||||
d.chomp!
|
||||
e.chomp!("\t")
|
||||
|
||||
a == 'abc' and b == '' and c == 'abc' and
|
||||
d == "abc\n" and e == 'abc'
|
||||
assert_equal a, 'abc'
|
||||
assert_equal b, ''
|
||||
assert_equal c, 'abc'
|
||||
assert_equal d, "abc\n"
|
||||
assert_equal e, 'abc'
|
||||
end
|
||||
|
||||
assert('String#chop', '15.2.10.5.11') do
|
||||
@@ -139,7 +172,9 @@ assert('String#chop', '15.2.10.5.11') do
|
||||
|
||||
c.chop
|
||||
|
||||
a == '' and b == 'ab' and c == 'abc'
|
||||
assert_equal a, ''
|
||||
assert_equal b, 'ab'
|
||||
assert_equal c, 'abc'
|
||||
end
|
||||
|
||||
assert('String#chop!', '15.2.10.5.12') do
|
||||
@@ -149,7 +184,8 @@ assert('String#chop!', '15.2.10.5.12') do
|
||||
a.chop!
|
||||
b.chop!
|
||||
|
||||
a == '' and b == 'ab'
|
||||
assert_equal a, ''
|
||||
assert_equal b, 'ab'
|
||||
end
|
||||
|
||||
assert('String#downcase', '15.2.10.5.13') do
|
||||
@@ -158,7 +194,8 @@ assert('String#downcase', '15.2.10.5.13') do
|
||||
|
||||
b.downcase
|
||||
|
||||
a == 'abc' and b == 'ABC'
|
||||
assert_equal a, 'abc'
|
||||
assert_equal b, 'ABC'
|
||||
end
|
||||
|
||||
assert('String#downcase!', '15.2.10.5.14') do
|
||||
@@ -166,7 +203,7 @@ assert('String#downcase!', '15.2.10.5.14') do
|
||||
|
||||
a.downcase!
|
||||
|
||||
a == 'abc'
|
||||
assert_equal a, 'abc'
|
||||
end
|
||||
|
||||
assert('String#each_line', '15.2.10.5.15') do
|
||||
@@ -178,18 +215,20 @@ assert('String#each_line', '15.2.10.5.15') do
|
||||
n_list << line
|
||||
end
|
||||
|
||||
list == n_list
|
||||
assert_equal list, n_list
|
||||
end
|
||||
|
||||
assert('String#empty?', '15.2.10.5.16') do
|
||||
a = ''
|
||||
b = 'not empty'
|
||||
|
||||
a.empty? and not b.empty?
|
||||
assert_true a.empty?
|
||||
assert_false b.empty?
|
||||
end
|
||||
|
||||
assert('String#eql?', '15.2.10.5.17') do
|
||||
'abc'.eql?('abc') and not 'abc'.eql?('cba')
|
||||
assert_true 'abc'.eql?('abc')
|
||||
assert_false 'abc'.eql?('cba')
|
||||
end
|
||||
|
||||
assert('String#gsub', '15.2.10.5.18') do
|
||||
@@ -210,45 +249,49 @@ assert('String#gsub!', '15.2.10.5.19') do
|
||||
b = 'abcabc'
|
||||
b.gsub!('b') { |w| w.capitalize }
|
||||
|
||||
a == 'aBcaBc' && b == 'aBcaBc'
|
||||
assert_equal a, 'aBcaBc'
|
||||
assert_equal b, 'aBcaBc'
|
||||
end
|
||||
|
||||
assert('String#hash', '15.2.10.5.20') do
|
||||
a = 'abc'
|
||||
|
||||
a.hash == 'abc'.hash
|
||||
assert_equal a.hash, 'abc'.hash
|
||||
end
|
||||
|
||||
assert('String#include?', '15.2.10.5.21') do
|
||||
'abc'.include?(97) and not 'abc'.include?(100) and
|
||||
'abc'.include?('a') and not 'abc'.include?('d')
|
||||
assert_true 'abc'.include?(97)
|
||||
assert_false 'abc'.include?(100)
|
||||
assert_true 'abc'.include?('a')
|
||||
assert_false 'abc'.include?('d')
|
||||
end
|
||||
|
||||
assert('String#index', '15.2.10.5.22') do
|
||||
'abc'.index('a') == 0 and 'abc'.index('d') == nil and
|
||||
'abcabc'.index('a', 1) == 3
|
||||
assert_equal 'abc'.index('a'), 0
|
||||
assert_nil 'abc'.index('d')
|
||||
assert_equal 'abcabc'.index('a', 1), 3
|
||||
end
|
||||
|
||||
assert('String#initialize', '15.2.10.5.23') do
|
||||
a = ''
|
||||
a.initialize('abc')
|
||||
|
||||
a == 'abc'
|
||||
assert_equal a, 'abc'
|
||||
end
|
||||
|
||||
assert('String#initialize_copy', '15.2.10.5.24') do
|
||||
a = ''
|
||||
a.initialize_copy('abc')
|
||||
|
||||
a == 'abc'
|
||||
assert_equal a, 'abc'
|
||||
end
|
||||
|
||||
assert('String#intern', '15.2.10.5.25') do
|
||||
'abc'.intern == :abc
|
||||
assert_equal 'abc'.intern, :abc
|
||||
end
|
||||
|
||||
assert('String#length', '15.2.10.5.26') do
|
||||
'abc'.length == 3
|
||||
assert_equal 'abc'.length, 3
|
||||
end
|
||||
|
||||
# 'String#match', '15.2.10.5.27' will be tested in mrbgems.
|
||||
@@ -257,32 +300,36 @@ assert('String#replace', '15.2.10.5.28') do
|
||||
a = ''
|
||||
a.replace('abc')
|
||||
|
||||
a == 'abc'
|
||||
assert_equal a, 'abc'
|
||||
end
|
||||
|
||||
assert('String#reverse', '15.2.10.5.29') do
|
||||
a = 'abc'
|
||||
a.reverse
|
||||
|
||||
a == 'abc' and 'abc'.reverse == 'cba'
|
||||
assert_equal a, 'abc'
|
||||
assert_equal 'abc'.reverse, 'cba'
|
||||
end
|
||||
|
||||
assert('String#reverse!', '15.2.10.5.30') do
|
||||
a = 'abc'
|
||||
a.reverse!
|
||||
|
||||
a == 'cba' and 'abc'.reverse! == 'cba'
|
||||
assert_equal a, 'cba'
|
||||
assert_equal 'abc'.reverse!, 'cba'
|
||||
end
|
||||
|
||||
assert('String#rindex', '15.2.10.5.31') do
|
||||
'abc'.rindex('a') == 0 and 'abc'.rindex('d') == nil and
|
||||
'abcabc'.rindex('a', 1) == 0 and 'abcabc'.rindex('a', 4) == 3
|
||||
assert_equal 'abc'.rindex('a'), 0
|
||||
assert_nil 'abc'.rindex('d')
|
||||
assert_equal 'abcabc'.rindex('a', 1), 0
|
||||
assert_equal 'abcabc'.rindex('a', 4), 3
|
||||
end
|
||||
|
||||
# 'String#scan', '15.2.10.5.32' will be tested in mrbgems.
|
||||
|
||||
assert('String#size', '15.2.10.5.33') do
|
||||
'abc'.size == 3
|
||||
assert_equal 'abc'.size, 3
|
||||
end
|
||||
|
||||
assert('String#slice', '15.2.10.5.34') do
|
||||
@@ -309,25 +356,33 @@ assert('String#slice', '15.2.10.5.34') do
|
||||
a3 = 'abc'.slice('bc')
|
||||
b3 = 'abc'.slice('XX')
|
||||
|
||||
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 e11 == 'b' and
|
||||
a3 == 'bc' and b3 == nil
|
||||
assert_equal a, 'a'
|
||||
assert_equal b, 'c'
|
||||
assert_nil c
|
||||
assert_nil d
|
||||
assert_nil a1
|
||||
assert_nil b1
|
||||
assert_nil c1
|
||||
assert_equal d1, ''
|
||||
assert_equal e1, 'bc'
|
||||
assert_equal e11, 'b'
|
||||
assert_equal a3, 'bc'
|
||||
assert_nil b3
|
||||
end
|
||||
|
||||
# TODO Broken ATM
|
||||
assert('String#split', '15.2.10.5.35') do
|
||||
# without RegExp behavior is actually unspecified
|
||||
'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']
|
||||
assert_equal 'abc abc abc'.split, ['abc', 'abc', 'abc']
|
||||
assert_equal 'a,b,c,,d'.split(','), ["a", "b", "c", "", "d"]
|
||||
assert_equal 'abc abc abc'.split(nil), ['abc', 'abc', 'abc']
|
||||
assert_equal 'abc'.split(""), ['a', 'b', 'c']
|
||||
end
|
||||
|
||||
assert('String#sub', '15.2.10.5.36') do
|
||||
'abcabc'.sub('b', 'B') == 'aBcabc' and
|
||||
'abcabc'.sub('b') { |w| w.capitalize } == 'aBcabc' and
|
||||
'aa#'.sub('#', '$') == 'aa$'
|
||||
assert_equal 'abcabc'.sub('b', 'B'), 'aBcabc'
|
||||
assert_equal 'abcabc'.sub('b') { |w| w.capitalize }, 'aBcabc'
|
||||
assert_equal 'aa#'.sub('#', '$'), 'aa$'
|
||||
end
|
||||
|
||||
assert('String#sub!', '15.2.10.5.37') do
|
||||
@@ -337,7 +392,8 @@ assert('String#sub!', '15.2.10.5.37') do
|
||||
b = 'abcabc'
|
||||
b.sub!('b') { |w| w.capitalize }
|
||||
|
||||
a == 'aBcabc' && b == 'aBcabc'
|
||||
assert_equal a, 'aBcabc'
|
||||
assert_equal b, 'aBcabc'
|
||||
end
|
||||
|
||||
|
||||
@@ -347,7 +403,10 @@ assert('String#to_i', '15.2.10.5.38') do
|
||||
c = 'a'.to_i(16)
|
||||
d = '100'.to_i(2)
|
||||
|
||||
a == 0 and b == 123456789 and c == 10 and d == 4
|
||||
assert_equal a, 0
|
||||
assert_equal b, 123456789
|
||||
assert_equal c, 10
|
||||
assert_equal d, 4
|
||||
end
|
||||
|
||||
assert('String#to_f', '15.2.10.5.39') do
|
||||
@@ -355,16 +414,17 @@ assert('String#to_f', '15.2.10.5.39') do
|
||||
b = '123456789'.to_f
|
||||
c = '12345.6789'.to_f
|
||||
|
||||
check_float(a, 0.0) and check_float(b, 123456789.0) and
|
||||
check_float(c, 12345.6789)
|
||||
assert_float(a, 0.0)
|
||||
assert_float(b, 123456789.0)
|
||||
assert_float(c, 12345.6789)
|
||||
end
|
||||
|
||||
assert('String#to_s', '15.2.10.5.40') do
|
||||
'abc'.to_s == 'abc'
|
||||
assert_equal 'abc'.to_s, 'abc'
|
||||
end
|
||||
|
||||
assert('String#to_sym', '15.2.10.5.41') do
|
||||
'abc'.to_sym == :abc
|
||||
assert_equal 'abc'.to_sym, :abc
|
||||
end
|
||||
|
||||
assert('String#upcase', '15.2.10.5.42') do
|
||||
@@ -373,7 +433,8 @@ assert('String#upcase', '15.2.10.5.42') do
|
||||
|
||||
b.upcase
|
||||
|
||||
a == 'ABC' and b == 'abc'
|
||||
assert_equal a, 'ABC'
|
||||
assert_equal b, 'abc'
|
||||
end
|
||||
|
||||
assert('String#upcase!', '15.2.10.5.43') do
|
||||
@@ -381,14 +442,14 @@ assert('String#upcase!', '15.2.10.5.43') do
|
||||
|
||||
a.upcase!
|
||||
|
||||
a == 'ABC'
|
||||
assert_equal a, 'ABC'
|
||||
end
|
||||
|
||||
# Not ISO specified
|
||||
|
||||
assert('String interpolation (mrb_str_concat for shared strings)') do
|
||||
a = "A" * 32
|
||||
"#{a}:" == "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:"
|
||||
assert_equal "#{a}:", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:"
|
||||
end
|
||||
|
||||
assert('Check the usage of a NUL character') do
|
||||
@@ -402,7 +463,8 @@ assert('String#bytes') do
|
||||
str2 = "\xFF"
|
||||
bytes2 = [0xFF]
|
||||
|
||||
str1.bytes == bytes1 and str2.bytes == bytes2
|
||||
assert_equal str1.bytes, bytes1
|
||||
assert_equal str2.bytes, bytes2
|
||||
end
|
||||
|
||||
assert('String#each_byte') do
|
||||
@@ -412,10 +474,10 @@ assert('String#each_byte') do
|
||||
|
||||
str1.each_byte {|b| bytes2 << b }
|
||||
|
||||
bytes1 == bytes2
|
||||
assert_equal bytes1, bytes2
|
||||
end
|
||||
|
||||
assert('String#inspect') do
|
||||
("\1" * 100).inspect # should not raise an exception - regress #1210
|
||||
"\0".inspect == "\"\\000\""
|
||||
assert_equal "\0".inspect, "\"\\000\""
|
||||
end
|
||||
|
||||
+7
-6
@@ -2,25 +2,26 @@
|
||||
# Symbol ISO Test
|
||||
|
||||
assert('Symbol', '15.2.11') do
|
||||
Symbol.class == Class
|
||||
assert_equal Symbol.class, Class
|
||||
end
|
||||
|
||||
assert('Symbol superclass', '15.2.11.2') do
|
||||
Symbol.superclass == Object
|
||||
assert_equal Symbol.superclass, Object
|
||||
end
|
||||
|
||||
assert('Symbol#===', '15.2.11.3.1') do
|
||||
:abc === :abc and not :abc === :cba
|
||||
assert_true :abc == :abc
|
||||
assert_false :abc == :cba
|
||||
end
|
||||
|
||||
assert('Symbol#id2name', '15.2.11.3.2') do
|
||||
:abc.id2name == 'abc'
|
||||
assert_equal :abc.id2name, 'abc'
|
||||
end
|
||||
|
||||
assert('Symbol#to_s', '15.2.11.3.3') do
|
||||
:abc.to_s == 'abc'
|
||||
assert_equal :abc.to_s, 'abc'
|
||||
end
|
||||
|
||||
assert('Symbol#to_sym', '15.2.11.3.4') do
|
||||
:abc.to_sym == :abc
|
||||
assert_equal :abc.to_sym, :abc
|
||||
end
|
||||
|
||||
+12
-16
@@ -1,9 +1,6 @@
|
||||
assert('super', '11.3.4') do
|
||||
test = false
|
||||
begin
|
||||
assert_raise NoMethodError do
|
||||
super
|
||||
rescue NoMethodError
|
||||
test = true
|
||||
end
|
||||
|
||||
class SuperFoo
|
||||
@@ -23,18 +20,14 @@ assert('super', '11.3.4') do
|
||||
end
|
||||
end
|
||||
bar = SuperBar.new
|
||||
test &&= bar.foo
|
||||
test &&= (bar.bar(1,2,3) == [1,2,3])
|
||||
test
|
||||
|
||||
assert_true bar.foo
|
||||
assert_equal bar.bar(1,2,3), [1,2,3]
|
||||
end
|
||||
|
||||
assert('yield', '11.3.5') do
|
||||
begin
|
||||
assert_raise LocalJumpError do
|
||||
yield
|
||||
rescue LocalJumpError
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,7 +36,10 @@ assert('Abbreviated variable assignment', '11.4.2.3.2') do
|
||||
b &&= 1
|
||||
c = 1
|
||||
c += 2
|
||||
a == 1 and b == nil and c == 3
|
||||
|
||||
assert_equal a, 1
|
||||
assert_nil b
|
||||
assert_equal c, 3
|
||||
end
|
||||
|
||||
assert('Nested const reference') do
|
||||
@@ -55,8 +51,8 @@ assert('Nested const reference') do
|
||||
end
|
||||
end
|
||||
end
|
||||
Syntax4Const::CONST1 == "hello world" and
|
||||
Syntax4Const::Const2.new.const1 == "hello world"
|
||||
assert_equal Syntax4Const::CONST1, "hello world"
|
||||
assert_equal Syntax4Const::Const2.new.const1, "hello world"
|
||||
end
|
||||
|
||||
assert('Abbreviated variable assignment as returns') do
|
||||
@@ -67,5 +63,5 @@ assert('Abbreviated variable assignment as returns') do
|
||||
end
|
||||
end
|
||||
end
|
||||
Syntax4AbbrVarAsgnAsReturns::A.new.b == 1
|
||||
assert_equal Syntax4AbbrVarAsgnAsReturns::A.new.b, 1
|
||||
end
|
||||
|
||||
+10
-7
@@ -2,29 +2,32 @@
|
||||
# TrueClass ISO Test
|
||||
|
||||
assert('TrueClass', '15.2.5') do
|
||||
TrueClass.class == Class
|
||||
assert_equal TrueClass.class, Class
|
||||
end
|
||||
|
||||
assert('TrueClass superclass', '15.2.5.2') do
|
||||
TrueClass.superclass == Object
|
||||
assert_equal TrueClass.superclass, Object
|
||||
end
|
||||
|
||||
assert('TrueClass true', '15.2.5.1') do
|
||||
true
|
||||
assert_true true
|
||||
end
|
||||
|
||||
assert('TrueClass#&', '15.2.5.3.1') do
|
||||
true.&(true) and not true.&(false)
|
||||
assert_true true.&(true)
|
||||
assert_false true.&(false)
|
||||
end
|
||||
|
||||
assert('TrueClass#^', '15.2.5.3.2') do
|
||||
not true.^(true) and true.^(false)
|
||||
assert_false true.^(true)
|
||||
assert_true true.^(false)
|
||||
end
|
||||
|
||||
assert('TrueClass#to_s', '15.2.5.3.3') do
|
||||
true.to_s == 'true'
|
||||
assert_equal true.to_s, 'true'
|
||||
end
|
||||
|
||||
assert('TrueClass#|', '15.2.5.3.4') do
|
||||
true.|(true) and true.|(false)
|
||||
assert_true true.|(true)
|
||||
assert_true true.|(false)
|
||||
end
|
||||
|
||||
+2
-2
@@ -2,10 +2,10 @@
|
||||
# TypeError ISO Test
|
||||
|
||||
assert('TypeError', '15.2.29') do
|
||||
TypeError.class == Class
|
||||
assert_equal TypeError.class, Class
|
||||
end
|
||||
|
||||
assert('TypeError superclass', '15.2.29.2') do
|
||||
TypeError.superclass == StandardError
|
||||
assert_equal TypeError.superclass, StandardError
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user