code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
require 'test/unit'
require 'tmpdir'
require_relative 'ruby/envutil'
class TestTracer < Test::Unit::TestCase
include EnvUtil
def test_tracer_with_option_r
assert_in_out_err(%w[-rtracer -e 1]) do |(*lines),|
case lines.size
when 2
assert_match(%r{rubygems/custom_require\.rb:\d+:Kernel:<:}, ... | Ruby |
require 'test/unit'
require 'pstore'
require_relative 'ruby/envutil'
class PStoreTest < Test::Unit::TestCase
def setup
@pstore_file = "pstore.tmp.#{Process.pid}"
@pstore = PStore.new(@pstore_file)
end
def teardown
File.unlink(@pstore_file) rescue nil
end
def test_opening_new_file_in_readonly_mo... | Ruby |
require 'test/unit'
require 'tempfile'
require_relative 'ruby/envutil'
class TestTempfile < Test::Unit::TestCase
def initialize(*)
super
@tempfile = nil
end
def tempfile(*args, &block)
t = Tempfile.new(*args, &block)
@tempfile = (t unless block)
end
def teardown
if @tempfile
@temp... | Ruby |
require 'objspace'
#
# purpose:
# Profile memory usage of each tests.
#
# usage:
# RUBY_TEST_ALL_PROFILE=true make test-all
#
# output:
# ./test_all_profile
#
# collected information:
# - ObjectSpace.memsize_of_all
# - GC.stat
# - /proc/self/statm (if it exists)
#
class MiniTest::Unit::TestCase
alias ori... | Ruby |
require 'test/unit'
require 'tempfile'
class TestRubyMode < Test::Unit::TestCase
MISCDIR = File.expand_path("../../../misc", __FILE__)
e = ENV["EMACS"] || "emacs"
emacs = %W"#{e} -q --no-site-file --batch --load #{MISCDIR}/ruby-mode.el"
begin
raise if IO.popen([e, "--version", :err=>[:child, :out]]) {|f| f... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestObject < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
$VERBOSE = nil
end
def teardown
$VERBOSE = @verbose
end
def test_dup
assert_raise(TypeError) { 1.dup }
assert_raise(TypeError) { true.dup }
assert_raise(TypeError) { ... | Ruby |
require 'test/unit'
require 'tmpdir'
require 'timeout'
require_relative 'envutil'
class TestIO_M17N < Test::Unit::TestCase
ENCS = [
Encoding::ASCII_8BIT,
Encoding::EUC_JP,
Encoding::Shift_JIS,
Encoding::UTF_8
]
def with_tmpdir
Dir.mktmpdir {|dir|
Dir.chdir(dir) {
yield dir
... | Ruby |
require 'test/unit'
require 'stringio'
class TestRubyYield < Test::Unit::TestCase
def test_ary_each
ary = [1]
ary.each {|a, b, c, d| assert_equal [1,nil,nil,nil], [a,b,c,d] }
ary.each {|a, b, c| assert_equal [1,nil,nil], [a,b,c] }
ary.each {|a, b| assert_equal [1,nil], [a,b] }
ary.each {|a| asse... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestEval < Test::Unit::TestCase
@ivar = 12
@@cvar = 13
$gvar__eval = 14
Const = 15
def ruby(*args)
args = ['-e', '$>.write($<.read)'] if args.empty?
ruby = EnvUtil.rubybin
f = IO.popen([ruby] + args, 'r+')
yield(f)
ensure
f.close un... | Ruby |
require 'test/unit'
class TestSetTraceFunc < Test::Unit::TestCase
def setup
@original_compile_option = RubyVM::InstructionSequence.compile_option
RubyVM::InstructionSequence.compile_option = {
:trace_instruction => true,
:specialized_instruction => false
}
end
def teardown
set_trace_... | Ruby |
# coding: utf-8
module MarshalTestLib
# include this module to a Test::Unit::TestCase and definde encode(o) and
# decode(s) methods. e.g.
#
# def encode(o)
# SOAPMarshal.dump(o)
# end
#
# def decode(s)
# SOAPMarshal.load(s)
# end
NegativeZero = (-1.0 / (1.0 / 0.0))
module Mod1; end
modu... | Ruby |
# -*- coding: utf-8 -*-
require 'test/unit'
class TestUnicodeEscape < Test::Unit::TestCase
def test_basic
assert_equal('Matz - 松本行弘',
"Matz - \u677E\u672C\u884C\u5F18")
assert_equal('Matz - まつもと ゆきひろ',
"Matz - \u307E\u3064\u3082\u3068 \u3086\u304D\u3072\u308D")
assert_equal('Matz - まつもと ゆきひろ... | Ruby |
require 'test/unit'
class TestSleep < Test::Unit::TestCase
def test_sleep_5sec
GC.disable
start = Time.now
sleep 5
slept = Time.now-start
bottom = /linux/ =~ RUBY_PLATFORM && /Linux ([\d.]+)/ =~ `uname -sr` && ($1.split('.')<=>%w/2 6 18/)<1 ? 4.99 : 5.0
assert_operator(bottom, :<=, slept)
... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestClass < Test::Unit::TestCase
# ------------------
# Various test classes
# ------------------
class ClassOne
attr :num_args
@@subs = []
def initialize(*args)
@num_args = args.size
@args = args
end
def [](n)
@args[n]... | Ruby |
require 'test/unit'
require_relative 'allpairs'
class TestSprintfComb < Test::Unit::TestCase
VS = [
#-0x1000000000000000000000000000000000000000000000002,
#-0x1000000000000000000000000000000000000000000000001,
#-0x1000000000000000000000000000000000000000000000000,
#-0xffffffffffffffffffffffffffffffff... | Ruby |
require 'test/unit'
require 'timeout'
require 'tempfile'
require_relative 'envutil'
class TestSignal < Test::Unit::TestCase
def have_fork?
begin
Process.fork {}
return true
rescue NotImplementedError
return false
end
end
def test_signal
return unless Process.respond_to?(:kill)
... | Ruby |
require 'test/unit'
class TestIntegerComb < Test::Unit::TestCase
VS = [
-0x1000000000000000000000000000000000000000000000002,
-0x1000000000000000000000000000000000000000000000001,
-0x1000000000000000000000000000000000000000000000000,
-0xffffffffffffffffffffffffffffffffffffffffffffffff,
-0x1000000... | Ruby |
require 'test/unit'
class TestCall < Test::Unit::TestCase
def aaa(a, b=100, *rest)
res = [a, b]
res += rest if rest
return res
end
def test_call
assert_raise(ArgumentError) {aaa()}
assert_raise(ArgumentError) {aaa}
assert_equal([1, 100], aaa(1))
assert_equal([1, 2], aaa(1, 2))
a... | Ruby |
require 'test/unit'
require_relative "envutil"
class TestGc < Test::Unit::TestCase
class S
def initialize(a)
@a = a
end
end
def test_gc
prev_stress = GC.stress
GC.stress = false
assert_nothing_raised do
1.upto(10000) {
tmp = [0,1,2,3,4,5,6,7,8,9]
}
tmp = nil... | Ruby |
require 'test/unit'
class TestSuper < Test::Unit::TestCase
class Base
def single(a) a end
def double(a, b) [a,b] end
def array(*a) a end
def optional(a = 0) a end
end
class Single1 < Base
def single(*) super end
end
class Single2 < Base
def single(a,*) super end
end
class Double1 ... | Ruby |
require 'test/unit'
require_relative 'ut_eof'
class TestPipe < Test::Unit::TestCase
include TestEOF
def open_file(content)
r, w = IO.pipe
w << content
w.close
begin
yield r
ensure
r.close
end
end
end
| Ruby |
require 'test/unit'
class TestAssignment < Test::Unit::TestCase
def test_assign
a=[]; a[0] ||= "bar";
assert_equal("bar", a[0])
h={}; h["foo"] ||= "bar";
assert_equal("bar", h["foo"])
aa = 5
aa ||= 25
assert_equal(5, aa)
bb ||= 25
assert_equal(25, bb)
cc &&=33
assert_nil(... | Ruby |
require 'test/unit'
class TestDefined < Test::Unit::TestCase
class Foo
def foo
p :foo
end
protected :foo
def bar(f)
yield(defined?(self.foo))
yield(defined?(f.foo))
end
def baz(f)
end
attr_accessor :attr
def attrasgn_test
yield(defined?(self.attr = 1))
... | Ruby |
require 'test/unit'
require 'tmpdir'
require_relative 'envutil'
class TestDir_M17N < Test::Unit::TestCase
def with_tmpdir
Dir.mktmpdir {|dir|
Dir.chdir(dir) {
yield dir
}
}
end
def create_and_check_raw_file_name(code, encoding)
with_tmpdir { |dir|
create_file_program = %Q[
... | Ruby |
require 'test/unit'
class ComplexRational_Test < Test::Unit::TestCase
def test_rat_srat
skip unless defined?(Rational)
c = SimpleRat(1,3)
cc = Rational(3,2)
assert_kind_of(Numeric, c)
assert_kind_of(Numeric, cc)
assert_instance_of(SimpleRat, c)
assert_instance_of(Rational, cc)
as... | Ruby |
require 'test/unit'
require 'stringio'
class TestM17N < Test::Unit::TestCase
def assert_encoding(encname, actual, message=nil)
assert_equal(Encoding.find(encname), actual, message)
end
module AESU
def ua(str) str.dup.force_encoding("US-ASCII") end
def a(str) str.dup.force_encoding("ASCII-8BIT") end
... | Ruby |
require 'test/unit'
class TestRand < Test::Unit::TestCase
def assert_random_int(ws, m, init = 0)
srand(init)
rnds = [Random.new(init)]
rnds2 = [rnds[0].dup]
rnds3 = [rnds[0].dup]
ws.each_with_index do |w, i|
w = w.to_i
assert_equal(w, rand(m))
rnds.each do |rnd|
assert_e... | Ruby |
require 'test/unit'
class TestBignum < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
$VERBOSE = nil
@fmax = Float::MAX.to_i
@fmax2 = @fmax * 2
@big = (1 << 63) - 1
end
def teardown
$VERBOSE = @verbose
end
def fact(n)
return 1 if n == 0
f = 1
while n>0
f *= n
... | Ruby |
require 'test/unit'
class ComplexSub < Complex; end
class Complex_Test < Test::Unit::TestCase
def setup
@rational = defined?(Rational)
if @rational
@keiju = Rational.instance_variables.include?(:@RCS_ID)
end
seps = [File::SEPARATOR, File::ALT_SEPARATOR].compact.map{|x| Regexp.escape(x)}.join(... | Ruby |
require 'test/unit'
require 'tmpdir'
require 'tempfile'
require 'pathname'
require_relative 'envutil'
class TestRubyOptions < Test::Unit::TestCase
def write_file(filename, content)
File.open(filename, "w") {|f|
f << content
}
end
def with_tmpchdir
Dir.mktmpdir {|d|
d = Pathname.new(d).... | Ruby |
require 'test/unit'
require 'timeout'
class TestStruct < Test::Unit::TestCase
def test_struct
struct_test = Struct.new("Test", :foo, :bar)
assert_equal(Struct::Test, struct_test)
test = struct_test.new(1, 2)
assert_equal(1, test.foo)
assert_equal(2, test.bar)
assert_equal(1, test[0])
ass... | Ruby |
require 'test/unit'
class TestInteger < Test::Unit::TestCase
BDSIZE = 0x4000000000000000.coerce(0)[0].size
def self.bdsize(x)
((x + 1) / 8 + BDSIZE) / BDSIZE * BDSIZE
end
def bdsize(x)
self.class.bdsize(x)
end
def test_aref
# assert_equal(1, (1 << 0x40000000)[0x40000000], "[ruby-dev:31271]")
... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestObjectSpace < Test::Unit::TestCase
def self.deftest_id2ref(obj)
/:(\d+)/ =~ caller[0]
file = $`
line = $1.to_i
code = <<"End"
define_method("test_id2ref_#{line}") {\
o = ObjectSpace._id2ref(obj.object_id);\
assert_same(obj, o, "... | Ruby |
require 'test/unit'
class TestTrace < Test::Unit::TestCase
def test_trace
$x = 1234
$y = 0
trace_var :$x, proc{$y = $x}
$x = 40414
assert_equal($x, $y)
untrace_var :$x
$x = 19660208
assert_not_equal($x, $y)
trace_var :$x, proc{$x *= 2}
$x = 5
assert_equal(10, $x)
un... | Ruby |
module Memory
keys = []
vals = []
case
when File.exist?(procfile = "/proc/self/status")
PROC_FILE = procfile
VM_PAT = /^Vm(\w+):\s+(\d+)/
def self.read_status
IO.foreach(PROC_FILE) do |l|
yield($1.downcase.intern, $2.to_i * 1024) if VM_PAT =~ l
end
end
read_status {|k, ... | Ruby |
require 'test/unit'
class TestConst < Test::Unit::TestCase
TEST1 = 1
TEST2 = 2
module Const
TEST3 = 3
TEST4 = 4
end
module Const2
TEST3 = 6
TEST4 = 8
end
def test_const
assert defined?(TEST1)
assert_equal 1, TEST1
assert defined?(TEST2)
assert_equal 2, TEST2
self.c... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestArray < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
$VERBOSE = nil
@cls = Array
end
def teardown
$VERBOSE = @verbose
end
def test_0_literal
assert_equal([1, 2, 3, 4], [1, 2] + [3, 4])
assert_equal([1, 2, 1, 2], [1, 2] *... | Ruby |
require 'test/unit'
class TestSprintf < Test::Unit::TestCase
def test_positional
assert_equal(" 00001", sprintf("%*1$.*2$3$d", 10, 5, 1))
end
def test_binary
assert_equal("0", sprintf("%b", 0))
assert_equal("1", sprintf("%b", 1))
assert_equal("10", sprintf("%b", 2))
assert_equal("..1", s... | Ruby |
require 'test/unit'
require 'tmpdir'
class TestNotImplement < Test::Unit::TestCase
def test_respond_to_fork
assert_include(Process.methods, :fork)
if /linux/ =~ RUBY_PLATFORM
assert_equal(true, Process.respond_to?(:fork))
end
end
def test_respond_to_lchmod
assert_include(File.methods, :lch... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestAutoload < Test::Unit::TestCase
def test_autoload_so
# Continuation is always available, unless excluded intentionally.
assert_in_out_err([], <<-INPUT, [], [])
autoload :Continuation, "continuation"
begin Continuation; rescue LoadError; end
... | Ruby |
require 'test/unit'
require 'envutil'
class TestEncodingConverter < Test::Unit::TestCase
def check_ec(edst, esrc, eres, dst, src, ec, off, len, opts=nil)
res = ec.primitive_convert(src, dst, off, len, opts)
assert_equal([edst.dup.force_encoding("ASCII-8BIT"),
esrc.dup.force_encoding("ASCII-... | Ruby |
require 'test/unit'
class TestClone < Test::Unit::TestCase
module M001; end
module M002; end
module M003; include M002; end
module M002; include M001; end
module M003; include M002; end
def test_clone
foo = Object.new
def foo.test
"test"
end
bar = foo.clone
def bar.test2
"t... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestEncoding < Test::Unit::TestCase
# Test basic encoding methods: list, find, name
def test_encoding
encodings = Encoding.list
assert_equal(encodings.empty?, false)
encodings.each do |e|
assert_equal(e, Encoding.find(e.name))
assert_eq... | Ruby |
# encoding: ASCII-8BIT # make sure this runs in binary mode
# some of the comments are in UTF-8
require 'test/unit'
class TestTranscode < Test::Unit::TestCase
def test_errors
assert_raise(Encoding::ConverterNotFoundError) { 'abc'.encode('foo', 'bar') }
assert_raise(Encoding::ConverterNotFoundError) { 'abc'... | Ruby |
require 'test/unit'
class TestMetaclass < Test::Unit::TestCase
class Foo; end
class Bar < Foo; end
class Baz; end
def setup
Object.class_eval do
def method_o; end
end
Module.class_eval do
def method_m; end
end
Class.class_eval do
def method_c; end
end
end
def tear... | Ruby |
require 'test/unit'
class TestPack < Test::Unit::TestCase
def test_pack
$format = "c2x5CCxsdils_l_a6";
# Need the expression in here to force ary[5] to be numeric. This avoids
# test2 failing because ary2 goes str->numeric->str and ary does not.
ary = [1,-100,127,128,32767,987.654321098 / 100.0,1234... | Ruby |
require 'test/unit'
class TestStringchar < Test::Unit::TestCase
def test_string
assert_equal("abcd", "abcd")
assert_match(/abcd/, "abcd")
assert("abcd" === "abcd")
# compile time string concatenation
assert_equal("abcd", "ab" "cd")
assert_equal("22aacd44", "#{22}aa" "cd#{44}")
assert_equa... | Ruby |
require 'test/unit'
require 'tempfile'
require_relative 'envutil'
require 'tmpdir'
class TestRequire < Test::Unit::TestCase
def test_require_invalid_shared_object
t = Tempfile.new(["test_ruby_test_require", ".so"])
t.puts "dummy"
t.close
assert_in_out_err([], <<-INPUT, %w(:ok), [])
begin
... | Ruby |
require 'test/unit'
class TestRubyLiteral < Test::Unit::TestCase
def test_special_const
assert_equal 'true', true.inspect
assert_instance_of TrueClass, true
assert_equal 'false', false.inspect
assert_instance_of FalseClass, false
assert_equal 'nil', nil.inspect
assert_instance_of NilClass, n... | Ruby |
require 'test/unit'
class TestSymbol < Test::Unit::TestCase
# [ruby-core:3573]
def assert_eval_inspected(sym, valid = true)
n = sym.inspect
if valid
bug5136 = '[ruby-dev:44314]'
assert_not_match(/\A:"/, n, bug5136)
end
assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(n))}
e... | Ruby |
require 'test/unit'
require_relative 'envutil'
# use of $= is deprecated after 1.7.1
def pre_1_7_1
end
class TestString < Test::Unit::TestCase
def initialize(*args)
@cls = String
@aref_re_nth = true
@aref_re_silent = false
@aref_slicebang_silent = true
super
end
def S(str)
@cls.new(str... | Ruby |
require 'test/unit'
require 'timeout'
require 'fcntl'
class TestReadPartial < Test::Unit::TestCase
def make_pipe
r, w = IO.pipe
r.binmode
w.binmode
begin
yield r, w
ensure
r.close unless r.closed?
w.close unless w.closed?
end
end
def pipe
make_pipe {|r, w|
yie... | Ruby |
require 'test/unit'
class TestFixnum < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
$VERBOSE = nil
end
def teardown
$VERBOSE = @verbose
end
def test_pow
[1, 2, 2**64, 2**63*3, 2**64*3].each do |y|
[-1, 0, 1].each do |x|
z1 = x**y
z2 = (-x)**y
if y % 2 == ... | Ruby |
require 'test/unit'
require 'tmpdir'
require 'pathname'
require 'timeout'
require_relative 'envutil'
require 'rbconfig'
class TestProcess < Test::Unit::TestCase
RUBY = EnvUtil.rubybin
def setup
Process.waitall
end
def teardown
Process.waitall
end
def windows?
return /mswin|mingw|bccwin/ =~ R... | Ruby |
require 'test/unit'
module TestEOF
def test_eof_0
open_file("") {|f|
assert_equal("", f.read(0))
assert_equal("", f.read(0))
assert_equal("", f.read)
assert_equal("", f.read(0))
assert_equal("", f.read(0))
}
open_file("") {|f|
assert_nil(f.read(1))
assert_equal("... | Ruby |
require 'test/unit'
require 'continuation'
class TestEnumerable < Test::Unit::TestCase
def setup
@obj = Object.new
class << @obj
include Enumerable
def each
yield 1
yield 2
yield 3
yield 1
yield 2
end
end
@verbose = $VERBOSE
$VERBOSE = nil... | Ruby |
require 'test/unit'
require 'stringio'
require_relative 'allpairs'
class TestM17NComb < Test::Unit::TestCase
def assert_encoding(encname, actual, message=nil)
assert_equal(Encoding.find(encname), actual, message)
end
module AESU
def a(str) str.dup.force_encoding("ASCII-8BIT") end
def e(str) str.dup.... | Ruby |
require 'test/unit'
class TestEnv < Test::Unit::TestCase
IGNORE_CASE = /bccwin|mswin|mingw/ =~ RUBY_PLATFORM
PATH_ENV = "PATH"
def setup
@verbose = $VERBOSE
$VERBOSE = nil
@backup = ENV.to_hash
ENV.delete('test')
ENV.delete('TEST')
end
def teardown
$VERBOSE = @verbose
ENV.clear
... | Ruby |
require 'test/unit'
class RationalSub < Rational; end
class Rational_Test < Test::Unit::TestCase
def setup
@complex = defined?(Complex)
if @complex
@keiju = Complex.instance_variables.include?(:@RCS_ID)
end
seps = [File::SEPARATOR, File::ALT_SEPARATOR].compact.map{|x| Regexp.escape(x)}.join("... | Ruby |
require 'test/unit'
require 'timeout'
require 'tmpdir'
require 'tempfile'
require_relative 'envutil'
class TestArgf < Test::Unit::TestCase
def setup
@t1 = Tempfile.new("argf-foo")
@t1.binmode
@t1.puts "1"
@t1.puts "2"
@t1.close
@t2 = Tempfile.new("argf-bar")
@t2.binmode
@t2.puts "3"
... | Ruby |
require 'test/unit'
require 'rational'
require 'delegate'
require 'timeout'
require 'delegate'
class TestTime < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
$VERBOSE = nil
end
def teardown
$VERBOSE = @verbose
end
def test_new
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,... | Ruby |
require 'test/unit'
class TestComparable < Test::Unit::TestCase
def setup
@o = Object.new
@o.extend(Comparable)
end
def cmp(b)
class << @o; self; end.class_eval {
undef :<=>
define_method(:<=>, b)
}
end
def test_equal
cmp->(x) do 0; end
assert_equal(true, @o == nil)
c... | Ruby |
require 'test/unit'
class TestIfunless < Test::Unit::TestCase
def test_if_unless
$x = 'test';
assert(if $x == $x then true else false end)
$bad = false
unless $x == $x
$bad = true
end
assert(!$bad)
assert(unless $x != $x then true else false end)
end
end
| Ruby |
require 'test/unit'
class TestRubyPrimitive < Test::Unit::TestCase
def test_not
assert_equal false, !true
assert_equal true, !false
assert_equal true, !nil
assert_equal false, !(1+1)
assert_equal false, !!nil
assert_equal true, !!1
end
def test_lvar
a = 1
assert_equal 1, a
b... | Ruby |
require 'test/unit'
ConstTest = 3
class Class
alias _remove_const remove_const
public :_remove_const
end
class TestBasicInstructions < Test::Unit::TestCase
def test_immediates
assert_equal((1==1), true)
assert_equal((1==2), false)
assert_equal [][0], nil
assert_equal "sym".intern, :sym
asse... | Ruby |
require 'test/unit'
class TestLambdaParameters < Test::Unit::TestCase
def test_exact_parameter
assert_raise(ArgumentError){(1..3).each(&lambda{})}
end
def test_call_simple
assert_equal(1, lambda{|a| a}.call(1))
assert_equal([1,2], lambda{|a, b| [a,b]}.call(1,2))
assert_raise(ArgumentError) { la... | Ruby |
require "test/unit"
class TestEucKr < Test::Unit::TestCase
def s(s)
s.force_encoding("euc-kr")
end
def test_mbc_enc_len
assert_equal(1, s("\xa1\xa1").size)
end
def test_mbc_to_code
assert_equal(0xa1a1, s("\xa1\xa1").ord)
end
def test_code_to_mbc
assert_equal(s("\xa1\xa1"), 0xa1a1.chr("... | Ruby |
require 'test/unit'
class TestUTF16 < Test::Unit::TestCase
def encdump(obj)
case obj
when String
d = obj.dump
if /\.force_encoding\("[A-Za-z0-9.:_+-]*"\)\z/ =~ d
d
else
"#{d}.force_encoding(#{obj.encoding.name.dump})"
end
when Regexp
"Regexp.new(#{encdump(obj... | Ruby |
require "test/unit"
class TestGB18030 < Test::Unit::TestCase
def s(s)
s.force_encoding("gb18030")
end
def test_mbc_enc_len
assert_equal(1, s("\x81\x40").size)
assert_equal(1, s("\x81\x30\x81\x30").size)
end
def test_mbc_to_code
assert_equal(0x8140, s("\x81\x40").ord)
end
def test_code_... | Ruby |
require "test/unit"
class TestGBK < Test::Unit::TestCase
def s(s)
s.force_encoding("gbk")
end
def test_mbc_enc_len
assert_equal(1, s("\x81\x40").size)
end
def test_mbc_to_code
assert_equal(0x8140, s("\x81\x40").ord)
end
def test_code_to_mbc
assert_equal(s("\x81\x40"), 0x8140.chr("gbk")... | Ruby |
require "test/unit"
class TestCP949 < Test::Unit::TestCase
def s(s)
s.force_encoding("cp949")
end
def test_mbc_enc_len
assert_equal(1, s("\xa1\xa1").size)
end
def test_mbc_to_code
assert_equal(0xa1a1, s("\xa1\xa1").ord)
end
def test_code_to_mbc
assert_equal(s("\xa1\xa1"), 0xa1a1.chr("c... | Ruby |
require 'test/unit'
class TestISO8859 < Test::Unit::TestCase
ASSERTS = %q(
assert_match(/^(\xdf)\1$/i, "\xdf\xdf")
assert_match(/^(\xdf)\1$/i, "ssss")
# assert_match(/^(\xdf)\1$/i, "\xdfss") # this must be bug...
assert_match(/^[\xdfz]+$/i, "sszzsszz")
assert_match(/^SS$/i, "\xdf")
assert_mat... | Ruby |
require "test/unit"
class TestEucTw < Test::Unit::TestCase
def s(s)
s.force_encoding("euc-tw")
end
def test_mbc_enc_len
assert_equal(1, s("\xa1\xa1").size)
end
def test_mbc_to_code
assert_equal(0xa1a1, s("\xa1\xa1").ord)
end
def test_code_to_mbc
assert_equal(s("\xa1\xa1"), 0xa1a1.chr("... | Ruby |
# encoding:windows-1251
require "test/unit"
class TestWindows1251 < Test::Unit::TestCase
def test_windows_1251
(0xc0..0xdf).each do |c|
c1 = c.chr("windows-1251")
c2 = (c + 0x20).chr("windows-1251")
assert_match(/^(#{ c1 })\1$/i, c2 + c1)
assert_match(/^(#{ c2 })\1$/i, c1 + c2)
ass... | Ruby |
require 'test/unit'
class TestUTF32 < Test::Unit::TestCase
def encdump(str)
d = str.dump
if /\.force_encoding\("[A-Za-z0-9.:_+-]*"\)\z/ =~ d
d
else
"#{d}.force_encoding(#{str.encoding.name.dump})"
end
end
def assert_str_equal(expected, actual, message=nil)
full_message = build_me... | Ruby |
require "test/unit"
class TestKOI8 < Test::Unit::TestCase
ASSERTS = %q(
(0xc0..0xdf).each do |c|
c1 = c.chr("ENCODING")
c2 = (c + 0x20).chr("ENCODING")
assert_match(/^(#{ c1 })\1$/i, c2 + c1)
assert_match(/^(#{ c2 })\1$/i, c1 + c2)
assert_match(/^[#{ c1 }]+$/i, c2 + c1)
assert... | Ruby |
require "test/unit"
class TestBig5 < Test::Unit::TestCase
def s(s)
s.force_encoding("big5")
end
def test_mbc_enc_len
assert_equal(1, s("\xa1\xa1").size)
end
def test_mbc_to_code
assert_equal(0xa1a1, s("\xa1\xa1").ord)
end
def test_code_to_mbc
assert_equal(s("\xa1\xa1"), 0xa1a1.chr("big... | Ruby |
require 'test/unit'
module Emoji
class TestRenameSJIS < Test::Unit::TestCase
def test_shift_jis
assert_raise(ArgumentError) { "".force_encoding("Shift_JIS-DoCoMo") }
assert_raise(ArgumentError) { "".force_encoding("Shift_JIS-KDDI") }
assert_raise(ArgumentError) { "".force_encoding("Shift_JIS-S... | Ruby |
require 'test/unit'
require 'continuation'
class TestHash < Test::Unit::TestCase
def test_hash
x = {1=>2, 2=>4, 3=>6}
y = {1=>2, 2=>4, 3=>6} # y = {1, 2, 2, 4, 3, 6} # 1.9 doesn't support
assert_equal(2, x[1])
assert(begin
for k,v in y
raise if k*2 != v
end
tr... | Ruby |
require 'test/unit'
require 'continuation'
require 'fiber'
require_relative 'envutil'
class TestContinuation < Test::Unit::TestCase
def test_create
assert_equal(:ok, callcc{:ok})
assert_equal(:ok, callcc{|c| c.call :ok})
end
def test_call
assert_equal(:ok, callcc{|c| c.call :ok})
ary = []
a... | Ruby |
require 'test/unit'
class TestUndef < Test::Unit::TestCase
class Undef0
def foo
"foo"
end
undef foo
end
class Undef1
def bar
"bar"
end
end
class Undef2 < Undef1
undef bar
end
def test_undef
x = Undef0.new
assert_raise(NoMethodError) { x.foo }
y = Undef1.... | Ruby |
require 'test/unit'
class Rational_Test2 < Test::Unit::TestCase
def test_kumi
assert_equal(Rational(1, 1), +Rational(1, 1))
assert_equal(Rational(-1, 1), -Rational(1, 1))
assert_equal(Rational(2, 1),
Rational(1, 1) + Rational(1, 1))
assert_equal(Rational(0, 1),
Rati... | Ruby |
require 'thread'
class LocalBarrier
def initialize(n)
@wait = Queue.new
@done = Queue.new
@keeper = begin_keeper(n)
end
def sync
@done.push(true)
@wait.pop
end
def join
@keeper.join
end
private
def begin_keeper(n)
Thread.start do
n.times do
@done.pop
e... | Ruby |
errout = ARGV.shift
BEGIN {
puts "b1"
local_begin1 = "local_begin1"
$global_begin1 = "global_begin1"
ConstBegin1 = "ConstBegin1"
}
BEGIN {
puts "b2"
BEGIN {
puts "b2-1"
}
}
# for scope check
#raise if defined?(local_begin1)
raise unless defined?($global_begin1)
raise unless defined?(::ConstBegin1)... | Ruby |
# -*- coding: us-ascii -*-
require "test/unit"
require "fileutils"
require "tmpdir"
class TestFileExhaustive < Test::Unit::TestCase
DRIVE = Dir.pwd[%r'\A(?:[a-z]:|//[^/]+/[^/]+)'i]
def assert_incompatible_encoding
d = "\u{3042}\u{3044}".encode("utf-16le")
assert_raise(Encoding::CompatibilityError) {yield ... | Ruby |
require 'test/unit'
require 'pp'
require_relative 'envutil'
$m0 = Module.nesting
class TestModule < Test::Unit::TestCase
def _wrap_assertion
yield
end
def assert_method_defined?(klass, mid, message="")
message = build_message(message, "#{klass}\##{mid} expected to be defined.")
_wrap_assertion do
... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestRegexp < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
$VERBOSE = nil
end
def teardown
$VERBOSE = @verbose
end
def test_has_NOENCODING
assert Regexp::NOENCODING
re = //n
assert_equal Regexp::NOENCODING, re.options
end
... | Ruby |
require 'test/unit'
require 'tempfile'
require_relative 'ut_eof'
class TestFile < Test::Unit::TestCase
# I don't know Ruby's spec about "unlink-before-close" exactly.
# This test asserts current behaviour.
def test_unlink_before_close
Dir.mktmpdir('rubytest-file') {|tmpdir|
filename = tmpdir + '/' + F... | Ruby |
require 'test/unit'
class Array
def iter_test1
collect{|e| [e, yield(e)]}.sort{|a,b|a[1]<=>b[1]}
end
def iter_test2
ary = collect{|e| [e, yield(e)]}
ary.sort{|a,b|a[1]<=>b[1]}
end
end
class TestIterator < Test::Unit::TestCase
def ttt
assert(iterator?)
end
def test_iterator
assert(!i... | Ruby |
module AllPairs
module_function
def make_prime(v)
return 2 if v < 2
ary = [true] * (v*2)
2.upto(Math.sqrt(ary.length).ceil) {|i|
return i if ary[i] && v <= i
(i*2).step(ary.length, i) {|j|
ary[j] = false
}
}
v.upto(ary.length-1) {|i|
return i if ary[i]
}
... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestMethod < Test::Unit::TestCase
def setup
@verbose = $VERBOSE
$VERBOSE = nil
end
def teardown
$VERBOSE = @verbose
end
def m0() end
def m1(a) end
def m2(a, b) end
def mo1(a = nil, &b) end
def mo2(a, b = nil) end
def mo3(*a) end
d... | Ruby |
require 'test/unit'
require_relative 'envutil.rb'
class TestCase < Test::Unit::TestCase
def test_case
case 5
when 1, 2, 3, 4, 6, 7, 8
assert(false)
when 5
assert(true)
end
case 5
when 5
assert(true)
when 1..10
assert(false)
end
case 5
when 1..10
... | Ruby |
require "open3"
require "timeout"
module EnvUtil
def rubybin
unless ENV["RUBYOPT"]
end
if ruby = ENV["RUBY"]
return ruby
end
ruby = "ruby"
rubyexe = ruby+".exe"
3.times do
if File.exist? ruby and File.executable? ruby and !File.directory? ruby
return File.expand_path(... | Ruby |
require 'test/unit'
require_relative 'envutil'
class TestVariable < Test::Unit::TestCase
class Gods
@@rule = "Uranus"
def ruler0
@@rule
end
def self.ruler1 # <= per method definition style
@@rule
end
class << self # <= multiple method definition style
def ruler2
@@rule
... | Ruby |
require 'test/unit'
class TestFnmatch < Test::Unit::TestCase
def bracket_test(s, t) # `s' should start with neither '!' nor '^'
0x21.upto(0x7E) do |i|
assert_equal(t.include?(i.chr), File.fnmatch("[#{s}]", i.chr, File::FNM_DOTMATCH))
assert_equal(t.include?(i.chr), !File.fnmatch("[^#{s}]", i.chr, Fi... | Ruby |
require 'test/unit'
class TestSyntax < Test::Unit::TestCase
def assert_valid_syntax(code, fname, mesg = fname)
code = code.dup.force_encoding("ascii-8bit")
code.sub!(/\A(?:\xef\xbb\xbf)?(\s*\#.*$)*(\n)?/n) {
"#$&#{"\n" if $1 && !$2}BEGIN{throw tag, :ok}\n"
}
code.force_encoding("us-ascii")
... | Ruby |
require 'test/unit'
require 'tempfile'
require 'timeout'
require_relative 'envutil'
class TestBeginEndBlock < Test::Unit::TestCase
DIR = File.dirname(File.expand_path(__FILE__))
def q(content)
"\"#{content}\""
end
def test_beginendblock
ruby = EnvUtil.rubybin
target = File.join(DIR, 'beginmainend... | Ruby |
require 'test/unit'
class TestEnumerator < Test::Unit::TestCase
def setup
@obj = Object.new
class << @obj
include Enumerable
def foo(*a)
a.each {|x| yield x }
end
end
end
def enum_test obj
i = 0
obj.map{|e|
e
}.sort
end
def test_iterators
assert_e... | Ruby |
require 'test/unit'
class Complex_Test2 < Test::Unit::TestCase
def test_kumi
skip unless defined?(Rational)
assert_equal(Complex(1, 0), +Complex(1, 0))
assert_equal(Complex(-1, 0), -Complex(1, 0))
assert_equal(Complex(2, 0),
Complex(1, 0) + Complex(1, 0))
assert_equal(Complex(0... | Ruby |
require 'test/unit'
require 'delegate'
require 'timeout'
class TestRange < Test::Unit::TestCase
def test_range_string
# XXX: Is this really the test of Range?
assert_equal([], ("a" ... "a").to_a)
assert_equal(["a"], ("a" .. "a").to_a)
assert_equal(["a"], ("a" ... "b").to_a)
assert_equal(["a", "b"... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.