code
stringlengths
1
1.73M
language
stringclasses
1 value
require 'test/unit' class TestMath < Test::Unit::TestCase def assert_infinity(a, *rest) rest = ["not infinity: #{a.inspect}"] if rest.empty? assert(!a.finite?, *rest) end def assert_nan(a, *rest) rest = ["not nan: #{a.inspect}"] if rest.empty? assert(a.nan?, *rest) end def check(a, b) e...
Ruby
require 'test/unit' require 'tmpdir' class TestWhileuntil < Test::Unit::TestCase def test_while Dir.mktmpdir("ruby_while_tmp") {|tmpdir| tmpfilename = "#{tmpdir}/ruby_while_tmp.#{$$}" tmp = open(tmpfilename, "w") tmp.print "tvi925\n"; tmp.print "tvi920\n"; tmp.print "vt100\n"; ...
Ruby
require 'test/unit' require 'tempfile' require_relative 'marshaltestlib' class TestMarshal < Test::Unit::TestCase include MarshalTestLib def setup @verbose = $VERBOSE $VERBOSE = nil end def teardown $VERBOSE = @verbose end def encode(o) Marshal.dump(o) end def decode(s) Marshal....
Ruby
# == sentence library # # = Features # # * syntax based sentences generation # * sentence operations such as substitution. # # = Example # # Some arithmetic expressions using "+", "-", "*" and "/" are generated as follows. # # require 'sentence' # Sentence.each({ # :exp => [["num"], # [:exp, "+", :exp]...
Ruby
require 'test/unit' require 'fiber' require 'continuation' require_relative './envutil' class TestFiber < Test::Unit::TestCase def test_normal f = Fiber.current assert_equal(:ok2, Fiber.new{|e| assert_equal(:ok1, e) Fiber.yield :ok2 }.resume(:ok1) ) assert_equal([:a, :b], ...
Ruby
require 'test/unit' class TestProc < Test::Unit::TestCase def setup @verbose = $VERBOSE $VERBOSE = nil end def teardown $VERBOSE = @verbose end def test_proc p1 = proc{|i| i} assert_equal(2, p1.call(2)) assert_equal(3, p1.call(3)) p1 = proc{|i| i*2} assert_equal(4, p1.call(...
Ruby
require 'test/unit' require 'tempfile' require_relative 'envutil' class TestException < Test::Unit::TestCase def test_exception begin raise "this must be handled" assert(false) rescue assert(true) end $bad = true begin raise "this must be handled no.2" rescue if...
Ruby
require 'test/unit' require 'stringio' class TestParse < Test::Unit::TestCase def setup @verbose = $VERBOSE $VERBOSE = nil end def teardown $VERBOSE = @verbose end def test_else_without_rescue x = eval <<-END begin else 42 end END assert_equal(42, x) end ...
Ruby
require 'test/unit' require 'tmpdir' require_relative 'envutil' class TestSystem < Test::Unit::TestCase def test_system ruby = EnvUtil.rubybin assert_equal("foobar\n", `echo foobar`) assert_equal('foobar', `#{ruby} -e 'print "foobar"'`) Dir.mktmpdir("ruby_script_tmp") {|tmpdir| tmpfilename = "...
Ruby
require 'test/unit' require 'tmpdir' require "fcntl" require 'io/nonblock' require 'socket' require 'stringio' require 'timeout' require 'tempfile' require 'weakref' require_relative 'envutil' class TestIO < Test::Unit::TestCase def have_close_on_exec? begin $stdin.close_on_exec? true rescue NotI...
Ruby
require 'test/unit' class TestCondition < Test::Unit::TestCase # [should] first test to see if we can run the tests. def test_condition $x = '0'; $x == $x && assert(true) $x != $x && assert(false) $x == $x || assert(false) $x != $x || assert(true) end end
Ruby
require 'test/unit' require 'thread' require_relative 'envutil' class TestThread < Test::Unit::TestCase class Thread < ::Thread Threads = [] def self.new(*) th = super th.abort_on_exception = true Threads << th th end end def setup Thread::Threads.clear end def teard...
Ruby
require 'test/unit' class TestAlias < Test::Unit::TestCase class Alias0 def foo "foo" end end class Alias1 < Alias0 alias bar foo def foo "foo+#{super}" end end class Alias2 < Alias1 alias baz foo undef foo end class Alias3 < Alias2 def foo super ...
Ruby
require 'test/unit' class TestRubyOptimization < Test::Unit::TestCase BIGNUM_POS_MIN_32 = 1073741824 # 2 ** 30 if BIGNUM_POS_MIN_32.kind_of?(Fixnum) FIXNUM_MAX = 4611686018427387903 # 2 ** 62 - 1 else FIXNUM_MAX = 1073741823 # 2 ** 30 - 1 end BIGNUM_NEG_MAX_32 = -1073741825 # -2...
Ruby
require 'test/unit' class TestNumeric < Test::Unit::TestCase class DummyNumeric < Numeric end def test_coerce a, b = 1.coerce(2) assert_equal(Fixnum, a.class) assert_equal(Fixnum, b.class) a, b = 1.coerce(2.0) assert_equal(Float, a.class) assert_equal(Float, b.class) assert_raise(T...
Ruby
require 'test/unit' require 'tmpdir' require 'fileutils' require 'pathname' class TestDir < Test::Unit::TestCase def setup @verbose = $VERBOSE $VERBOSE = nil @root = Pathname.new(Dir.mktmpdir('__test_dir__')).realpath.to_s @nodir = File.join(@root, "dummy") for i in ?a..?z if i.ord % 2 ==...
Ruby
require 'test/unit' class TestPath < Test::Unit::TestCase def test_path assert_equal("a", File.basename("a")) assert_equal("b", File.basename("a/b")) assert_equal("b", File.basename("a/b/")) assert_equal("/", File.basename("/")) assert_equal("/", File.basename("//")) assert_equal("/", File.ba...
Ruby
require 'test/unit' class TestTimeTZ < Test::Unit::TestCase def with_tz(tz) if /linux/ =~ RUBY_PLATFORM || ENV["RUBY_FORCE_TIME_TZ_TEST"] == "yes" old = ENV["TZ"] begin ENV["TZ"] = tz yield ensure ENV["TZ"] = old end else if ENV["TZ"] == tz yield ...
Ruby
require 'test/unit' require_relative 'envutil' class TestFloat < Test::Unit::TestCase include EnvUtil def test_float assert_equal(2, 2.6.floor) assert_equal(-3, (-2.6).floor) assert_equal(3, 2.6.ceil) assert_equal(-2, (-2.6).ceil) assert_equal(2, 2.6.truncate) assert_equal(-2, (-2.6).trunc...
Ruby
# -*- coding: utf-8 -*- require 'test/unit' require 'shellwords' class TestShellwords < Test::Unit::TestCase include Shellwords def setup @not_string = Class.new @cmd = "ruby my_prog.rb | less" end def test_string assert_instance_of(Array, shellwords(@cmd)) assert_equal(4, shellwords(@cmd)....
Ruby
# -*- coding: UTF-8 -*- require 'test/unit' require 'erb' class TestERB < Test::Unit::TestCase def test_result_encoding erb = ERB.new("hello") assert_equal __ENCODING__, erb.result.encoding erb = ERB.new("こんにちは".encode("EUC-JP")) assert_equal Encoding::EUC_JP, erb.result.encoding erb = ERB.new(...
Ruby
require 'test/unit' require 'erb' class TestERB < Test::Unit::TestCase class MyError < RuntimeError ; end def test_without_filename erb = ERB.new("<% raise ::TestERB::MyError %>") e = assert_raise(MyError) { erb.result } assert_match(/\A\(erb\):1\b/, e.backtrace[0]) end def test_with_fi...
Ruby
require 'test/unit' require 'thread' require 'mutex_m' class TestMutexM < Test::Unit::TestCase def test_cv_wait o = Object.new o.instance_variable_set(:@foo, nil) o.extend(Mutex_m) c = ConditionVariable.new t = Thread.start { o.synchronize do until foo = o.instance_variable_get(:@fo...
Ruby
require 'test/unit' require 'stringio' require_relative '../ruby/ut_eof' class TestStringIO < Test::Unit::TestCase include TestEOF def open_file(content) f = StringIO.new(content) yield f end alias open_file_rw open_file include TestEOF::Seek def test_truncate io = StringIO.new("") io.put...
Ruby
#!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'test/unit' require File.join(File.dirname(__FILE__), 'setup_variant') class TC_JSONGenerate < Test::Unit::TestCase include JSON def setup @hash = { 'a' => 2, 'b' => 3.141, 'c' => 'c', 'd' => [ 1, "b", 3.14 ], 'e' => { 'foo' =>...
Ruby
#!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'test/unit' require File.join(File.dirname(__FILE__), 'setup_variant') require 'stringio' require 'time' class TestJsonStringMatching < Test::Unit::TestCase include JSON class TestTime < ::Time def self.json_create(string) Time.parse(string) end ...
Ruby
#!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'test/unit' require File.join(File.dirname(__FILE__), 'setup_variant') require 'stringio' unless Array.method_defined?(:permutation) begin require 'enumerator' require 'permutation' class Array def permutation Permutation.for(self).to_enu...
Ruby
#!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'test/unit' require File.join(File.dirname(__FILE__), 'setup_variant') class TC_JSONFixtures < Test::Unit::TestCase def setup fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json') passed, failed = Dir[fixtures].partition { |f| f['pass'] } @pa...
Ruby
case ENV['JSON'] when 'pure' $:.unshift 'lib' require 'json/pure' when 'ext' $:.unshift 'ext', 'lib' require 'json/ext' else $:.unshift 'ext', 'lib' require 'json' end
Ruby
#!/usr/bin/env ruby # -*- coding:utf-8 -*- require 'test/unit' require File.join(File.dirname(__FILE__), 'setup_variant') require 'json/add/core.rb' require 'date' class TC_JSONAddition < Test::Unit::TestCase include JSON class A def initialize(a) @a = a end attr_reader :a def ==(other) ...
Ruby
#!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'test/unit' require File.join(File.dirname(__FILE__), 'setup_variant') class TC_JSONUnicode < Test::Unit::TestCase include JSON def test_unicode assert_equal '""', ''.to_json assert_equal '"\\b"', "\b".to_json assert_equal '"\u0001"', 0x1.chr.to_jso...
Ruby
require 'test/unit' require_relative 'ruby/envutil' # mathn redefines too much. It must be isolated to child processes. class TestMathn < Test::Unit::TestCase def test_power assert_in_out_err ['-r', 'mathn', '-e', 'a=1**2;!a'], "", [], [], '[ruby-core:25740]' assert_in_out_err ['-r', 'mathn', '-e', 'a=(1<<12...
Ruby
#!/usr/bin/env ruby # $RoughId: test.rb,v 1.9 2002/02/25 08:20:14 knu Exp $ # $Id: test_syslog.rb 32887 2011-08-07 15:11:03Z kosaki $ # Please only run this test on machines reasonable for testing. # If in doubt, ask your admin. require 'test/unit' begin require 'syslog' rescue LoadError # suppress error message...
Ruby
require 'prettyprint' require 'test/unit' module PrettyPrintTest class WadlerExample < Test::Unit::TestCase # :nodoc: def setup @tree = Tree.new("aaaa", Tree.new("bbbbb", Tree.new("ccc"), Tree.new("dd")), Tree.new("eee"), ...
Ruby
require 'test/unit' require 'thread' class TestQueue < Test::Unit::TestCase def test_queue grind(5, 1000, 15, Queue) end def test_sized_queue grind(5, 1000, 15, SizedQueue, 1000) end def grind(num_threads, num_objects, num_iterations, klass, *args) from_workers = klass.new(*args) to_workers...
Ruby
require 'pp' require 'delegate' require 'test/unit' module PPTestModule class PPTest < Test::Unit::TestCase def test_list0123_12 assert_equal("[0, 1, 2, 3]\n", PP.pp([0,1,2,3], '', 12)) end def test_list0123_11 assert_equal("[0,\n 1,\n 2,\n 3]\n", PP.pp([0,1,2,3], '', 11)) end OverriddenStruct = S...
Ruby
begin require 'win32ole' rescue LoadError end require "test/unit" if defined?(WIN32OLE_PARAM) class TestWIN32OLE_PARAM < Test::Unit::TestCase def setup ole_type = WIN32OLE_TYPE.new("Microsoft Internet Controls", "WebBrowser") m_navigate = WIN32OLE_METHOD.new(ole_type, "Navigate") m_before_na...
Ruby
begin require 'win32ole' rescue LoadError end require "test/unit" if defined?(WIN32OLE_TYPELIB) class TestWIN32OLE_TYPELIB < Test::Unit::TestCase def test_s_typelibs tlibs = WIN32OLE_TYPELIB.typelibs assert_instance_of(Array, tlibs) assert(tlibs.size > 0) tlib = tlibs.find {|t| t.name =...
Ruby
begin require 'win32ole' rescue LoadError end require 'test/unit' def ado_installed? installed = false if defined?(WIN32OLE) db = nil begin db = WIN32OLE.new('ADODB.Connection') db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;" db.open db.close ...
Ruby
# # This is test for [ruby-talk:196897] # begin require 'win32ole' rescue LoadError end require "test/unit" if defined?(WIN32OLE) class TestWIN32OLE_FOR_PROPERTYPUTREF < Test::Unit::TestCase def setup @obj = WIN32OLE.new('Scripting.Dictionary') end def test_ole_methods x = @obj.ole_method...
Ruby
begin require 'win32ole' rescue LoadError end require "test/unit" if defined?(WIN32OLE_VARIABLE) class TestWIN32OLE_VARIABLE < Test::Unit::TestCase def setup ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants") @var1 = ole_type.variables.find {|v| ...
Ruby
begin require 'win32ole' rescue LoadError end require "test/unit" if defined?(WIN32OLE_TYPE) class TestWIN32OLE_TYPE < Test::Unit::TestCase def test_s_progids progids = WIN32OLE_TYPE.progids assert_instance_of(Array, progids) assert(progids.size > 0) assert_instance_of(String, progids[...
Ruby
begin require 'win32ole' rescue LoadError end require 'test/unit' require 'fileutils' def ado_csv_installed? installed = false if defined?(WIN32OLE) db = nil begin db = WIN32OLE.new('ADODB.Connection') db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;" d...
Ruby
require 'test/unit' begin require 'win32ole' rescue LoadError end if defined?(WIN32OLE) class TestWIN32OLE_PROPERTYPUTREF < Test::Unit::TestCase def setup begin @sapi = WIN32OLE.new('SAPI.SpVoice') @sv = @sapi.voice rescue WIN32OLERuntimeError @sapi = nil end end ...
Ruby
begin require 'win32ole' rescue LoadError end require "test/unit" $MSGS = [] def add_skip_message(msg) $MSGS.push msg end if defined?(WIN32OLE_VARIANT) class TestWIN32OLE_VARIANT < Test::Unit::TestCase def setup @orglocale = WIN32OLE.locale WIN32OLE.locale = 0x0409 # set locale US-Eng end ...
Ruby
# This is test script to check that WIN32OLE should convert nil to VT_EMPTY in second try. # [ruby-talk:137054] begin require 'win32ole' rescue LoadError end require 'test/unit' if defined?(WIN32OLE) class TestNIL2VT_EMPTY < Test::Unit::TestCase def setup fs = WIN32OLE.new('Scripting.FileSystemObject') ...
Ruby
# # This script check that Win32OLE can execute InvokeVerb method of FolderItem2. # begin require 'win32ole' rescue LoadError end require 'test/unit' if defined?(WIN32OLE) class TestInvokeVerb < Test::Unit::TestCase def setup # make dummy file for InvokeVerb test. @fso = WIN32OLE.new('Scripting.Fi...
Ruby
require 'win32ole' db = WIN32OLE.new('ADODB.Connection') db.connectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=.;" ev = WIN32OLE_EVENT.new(db) ev.on_event('WillConnect') {|*args| foo } db.open WIN32OLE_EVENT.message_loop
Ruby
begin require 'win32ole' rescue LoadError end require "test/unit" if defined?(WIN32OLE_METHOD) class TestWIN32OLE_METHOD < Test::Unit::TestCase def setup ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell") @m_open = WIN32OLE_METHOD.new(ole_type, "open") @m_namesp...
Ruby
# # This is test for [ruby-Bugs#3237] # begin require 'win32ole' rescue LoadError end require "test/unit" def word_installed? installed = false w = nil if defined?(WIN32OLE) begin w = WIN32OLE.new('Word.Application') installed = true rescue ensure if w w.quit w = n...
Ruby
# begin require 'win32ole' rescue LoadError end require 'test/unit' if defined?(WIN32OLE) module CONST1 end module CONST2 end module TestCaseForDict def test_convert_bignum @dict1.add("a", 9999999999) @dict1.add("b", 999999999) @dict1.add("c", @dict1.item("b") * 10 + 9) assert...
Ruby
begin require 'win32ole' rescue LoadError end require 'test/unit' if defined?(WIN32OLE) class TestThread < Test::Unit::TestCase # # test for Bug #2618(ruby-core:27634) # def test_creating_win32ole_object_in_thread t = Thread.new do dict = WIN32OLE.new('Scripting.Dictionary') a...
Ruby
begin require 'win32ole' rescue LoadError end require "test/unit" if defined?(WIN32OLE::VARIANT) class TestWin32OLE_VARIANT_MODULE < Test::Unit::TestCase include WIN32OLE::VARIANT def test_variant assert_equal(0, VT_EMPTY) assert_equal(1, VT_NULL) assert_equal(2, VT_I2) assert_equal...
Ruby
# # test Win32OLE avoids cfp consistency error when the exception raised # in WIN32OLE_EVENT handler block. [ruby-dev:35450] # begin require 'win32ole' rescue LoadError end if defined?(WIN32OLE) require 'mkmf' require 'test/unit' class TestErrInCallBack < Test::Unit::TestCase def setup @ruby = nil ...
Ruby
require_relative 'test_base' require 'dl/import' module DL module LIBC extend Importer dlload LIBC_SO, LIBM_SO typealias 'string', 'char*' typealias 'FILE*', 'void*' extern "void *strcpy(char*, char*)" extern "int isdigit(int)" extern "double atof(string)" extern "unsigned long strt...
Ruby
require 'test/unit' require 'dl' require_relative '../ruby/envutil' libc_so = libm_so = nil case RUBY_PLATFORM when /cygwin/ libc_so = "cygwin1.dll" libm_so = "cygwin1.dll" when /x86_64-linux/ libc_so = "/lib64/libc.so.6" libm_so = "/lib64/libm.so.6" when /linux/ libdir = '/lib' case [0].pack('L!').size ...
Ruby
require_relative 'test_base' require_relative '../ruby/envutil' require 'dl/callback' require 'dl/func' module DL class TestCallback < TestBase include DL def test_remove_callback_failed assert_equal(false, remove_callback(0, TYPE_VOIDP)) end def test_remove_callback addr = set_callback...
Ruby
require_relative 'test_base.rb' require 'dl/callback' require 'dl/func' require 'dl/pack' module DL class TestDL < TestBase def ptr2num(*list) list.pack("p*").unpack(PackInfo::PACK_MAP[TYPE_VOIDP] + "*") end # TODO: refactor test repetition def test_free_secure assert_raises(SecurityError) do T...
Ruby
require_relative 'test_base' require 'dl/func' module DL class TestCFunc < TestBase def setup super @name = 'strcpy' @cf = CFunc.new(@libc[@name], TYPE_VOIDP, @name) end def test_ptr= @cf.ptr = @libc['malloc'] assert_equal @cf.ptr, @libc['malloc'] end def test_ptr ...
Ruby
require_relative 'test_base' module DL class TestHandle < TestBase def test_to_i handle = DL::Handle.new(LIBC_SO) assert_kind_of Integer, handle.to_i end def test_static_sym_secure assert_raises(SecurityError) do Thread.new do $SAFE = 2 DL::Handle.sym('callo...
Ruby
require_relative 'test_base' require 'dl/import' require 'dl/types' class DL::TestWin32 < DL::TestBase module Win32API extend DL::Importer dlload "kernel32.dll" include DL::Win32Types OSVERSIONINFO = struct [ "DWORD dwOSVersionInfoSize", "DWORD dwMajorVersion", "DWORD dwMinorVersion", "DWORD...
Ruby
require_relative 'test_base' require 'dl/func' module DL class TestFunc < TestBase def test_name f = Function.new(CFunc.new(@libc['strcpy'], TYPE_VOIDP, 'strcpy'), [TYPE_VOIDP, TYPE_VOIDP]) assert_equal 'strcpy', f.name end def test_to_i cfunc = CFunc.new(@libc['...
Ruby
require_relative 'test_base' require_relative '../ruby/envutil' module DL class TestCPtr < TestBase def test_cptr_to_int null = DL::NULL assert_equal(null.to_i, null.to_int) end def test_malloc_free_func_int free = CFunc.new(DL::RUBY_FREE, TYPE_VOID, 'free') ptr = CPtr.malloc(1...
Ruby
require_relative 'test_base' require 'dl/cparser' module DL class TestCParser < TestBase include DL::CParser def test_uint_ctype assert_equal(-DL::TYPE_INT, parse_ctype('uint')) end end end
Ruby
require 'test/unit' require 'find' require 'tmpdir' class TestFind < Test::Unit::TestCase def test_empty Dir.mktmpdir {|d| a = [] Find.find(d) {|f| a << f } assert_equal([d], a) } end def test_rec Dir.mktmpdir {|d| File.open("#{d}/a", "w"){} Dir.mkdir("#{d}/b") Fi...
Ruby
require 'test/unit' require_relative 'ruby/envutil' require 'shellwords' require 'tmpdir' begin require 'pty' rescue LoadError end class TestPTY < Test::Unit::TestCase RUBY = EnvUtil.rubybin def test_spawn_without_block r, w, pid = PTY.spawn(RUBY, '-e', 'puts "a"') rescue RuntimeError skip $! else ...
Ruby
###################################################################### # This file is imported from the minitest project. # DO NOT make modifications in this repo. They _will_ be reverted! # File a patch instead and assign it to Ryan Davis. ###################################################################### require...
Ruby
###################################################################### # This file is imported from the minitest project. # DO NOT make modifications in this repo. They _will_ be reverted! # File a patch instead and assign it to Ryan Davis. ###################################################################### require...
Ruby
###################################################################### # This file is imported from the minitest project. # DO NOT make modifications in this repo. They _will_ be reverted! # File a patch instead and assign it to Ryan Davis. ###################################################################### require...
Ruby
require 'test/unit' require 'open3' require_relative 'ruby/envutil' class TestOpen3 < Test::Unit::TestCase RUBY = EnvUtil.rubybin def test_exit_status Open3.popen3(RUBY, '-e', 'exit true') {|i,o,e,t| assert_equal(true, t.value.success?) } Open3.popen3(RUBY, '-e', 'exit false') {|i,o,e,t| a...
Ruby
require 'test/unit' require 'stringio' require 'tempfile' begin require 'zlib' rescue LoadError end if defined? Zlib class TestZlibDeflate < Test::Unit::TestCase def test_initialize z = Zlib::Deflate.new s = z.deflate("foo", Zlib::FINISH) assert_equal("foo", Zlib::Inflate.inflate(s)) ...
Ruby
require 'test/unit' require 'uri/ldap' module URI class TestLDAP < Test::Unit::TestCase def setup end def teardown end def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_parse url = 'ldap://ldap.jaist.ac.jp/o=JAIST,c=JP?sn?base?(sn=ttate*)' u = URI.parse(url) ...
Ruby
require 'test/unit' require 'uri/mailto' module URI class TestMailTo < Test::Unit::TestCase def setup @u = URI::MailTo end def teardown end def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_build ok = [] bad = [] # RFC2368, 6. Examples # mailto:c...
Ruby
require 'test/unit' require 'uri' class URI::TestGeneric < Test::Unit::TestCase def setup @url = 'http://a/b/c/d;p?q' @base_url = URI.parse(@url) end def teardown end def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_parse # 0 assert_kind_of(URI::HTTP, ...
Ruby
require 'test/unit' require 'uri' class URI::TestParser < Test::Unit::TestCase def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_compare url = 'http://a/b/c/d;p?q' u0 = URI.parse(url) u1 = URI.parse(url) p = URI::Parser.new u2 = p.parse(url) u3 = p.parse(...
Ruby
require 'test/unit' require 'uri' module URI class TestCommon < Test::Unit::TestCase def setup end def teardown end def test_extract assert_equal(['http://example.com'], URI.extract('http://example.com')) assert_equal(['http://example.com'], URI.extract('(http://example.com)')) assert_e...
Ruby
require 'test/unit' require 'uri/ftp' module URI class TestFTP < Test::Unit::TestCase def setup end def test_parse url = URI.parse('ftp://user:pass@host.com/abc/def') assert_kind_of(URI::FTP, url) exp = [ 'ftp', 'user:pass', 'host.com', URI::FTP.default_port, 'abc/def', nil, ...
Ruby
require 'test/unit' require 'uri/http' module URI class TestHTTP < Test::Unit::TestCase def setup end def teardown end def uri_to_ary(uri) uri.class.component.collect {|c| uri.send(c)} end def test_parse u = URI.parse('http://a') assert_kind_of(URI::HTTP, u) assert_equal(['http', ...
Ruby
require 'time' require 'test/unit' require_relative 'ruby/envutil.rb' class TestTimeExtension < Test::Unit::TestCase # :nodoc: def test_rfc822 assert_equal(Time.utc(1976, 8, 26, 14, 30) + 4 * 3600, Time.rfc2822("26 Aug 76 14:30 EDT")) assert_equal(Time.utc(1976, 8, 27, 9, 32) + 7 * 3600, ...
Ruby
require 'test/unit' require 'optparse' class TestOptionParser < Test::Unit::TestCase end class TestOptionParser::BashCompletion < Test::Unit::TestCase def setup @opt = OptionParser.new @opt.define("-z", "zzz") {} @opt.define("--foo") {} @opt.define("--bar=BAR") {} @opt.define("--for=TYPE", [:hell...
Ruby
require_relative 'test_optparse' module TestOptionParser::NoArg class Def1 < TestOptionParser include NoArg def setup super @opt.def_option("-x") {|x| @flag = x} @opt.def_option("--option") {|x| @flag = x} end end class Def2 < TestOptionParser include NoArg def setup s...
Ruby
require 'test/unit' require 'optparse' class TestOptionParser < Test::Unit::TestCase def setup @opt = OptionParser.new @flag = self.class # cannot set by option end class DummyOutput < String alias write << end def no_error(*args) $stderr, stderr = DummyOutput.new, $stderr assert_nothin...
Ruby
require_relative 'test_optparse' class TestOptionParser::OptArg < TestOptionParser def setup super @opt.def_option("-x[VAL]") {|x| @flag = x} @opt.def_option("--option[=VAL]") {|x| @flag = x} @opt.def_option("--regexp[=REGEXP]", Regexp) {|x| @reopt = x} @reopt = nil end def test_short as...
Ruby
require 'test/unit' require 'optparse' class TestOptionParser < Test::Unit::TestCase end class TestOptionParser::Getopts < Test::Unit::TestCase def setup @opt = OptionParser.new end def test_short_noarg o = @opt.getopts(%w[-a], "ab") assert_equal(true, o['a']) assert_equal(false, o['b']) end ...
Ruby
require_relative 'test_optparse' class TestOptionParser::SummaryTest < TestOptionParser def test_short_clash r = nil o = OptionParser.new do |opts| opts.on("-f", "--first-option", "description 1", "description 2"){r = "first-option"} opts.on("-t", "--test-option"){r = "test-option"} opts.on...
Ruby
require_relative 'test_optparse' module TestOptionParser::ReqArg class Def1 < TestOptionParser include ReqArg def setup super @opt.def_option("-xVAL") {|x| @flag = x} @opt.def_option("--option=VAL") {|x| @flag = x} @opt.def_option("--regexp=REGEXP", Regexp) {|x| @reopt = x} @reo...
Ruby
require_relative 'test_optparse' class TestOptionParser::PlaceArg < TestOptionParser def setup super @opt.def_option("-x [VAL]") {|x| @flag = x} @opt.def_option("--option [VAL]") {|x| @flag = x} @opt.def_option("-T [level]", /^[0-4]$/, Integer) {|x| @topt = x} @topt = nil @opt.def_option("-n"...
Ruby
require 'test/unit' require 'optparse' class TestOptionParser < Test::Unit::TestCase end class TestOptionParser::BashCompletion < Test::Unit::TestCase def setup @opt = OptionParser.new @opt.define("-z", "zzz") {} @opt.define("--foo") {} @opt.define("--bar=BAR") {} @opt.define("--for=TYPE", [:hell...
Ruby
require "test/unit/testcase" require "rexml/document" require 'rexml/streamlistener' require 'stringio' class MyListener include REXML::StreamListener end class StreamTester < Test::Unit::TestCase # Submitted by Han Holl def test_listener data = %Q{<session1 user="han" password="rootWeiler" />\n<session2 u...
Ruby
require 'rexml_test_utils' require 'rexml/parsers/lightparser' class LightParserTester < Test::Unit::TestCase include REXMLTestUtils include REXML def test_parsing f = File.new(fixture_path("documentation.xml")) parser = REXML::Parsers::LightParser.new( f ) root = parser.parse end end
Ruby
#!/usr/bin/env ruby # # Created by Henrik Mårtensson on 2007-02-18. # Copyright (c) 2007. All rights reserved. require "rexml/document" require "test/unit" class TestXmlDeclaration < Test::Unit::TestCase def setup xml = <<-'END_XML' <?xml encoding= 'UTF-8' standalone='yes'?> <root> </root> END...
Ruby
require 'rexml_test_utils' require 'rexml/document' class TestIssuezillaParsing < Test::Unit::TestCase include REXMLTestUtils def test_rexml doc = REXML::Document.new(File.new(fixture_path("ofbiz-issues-full-177.xml"))) ctr = 1 doc.root.each_element('//issue') do |issue| assert_equal( ctr, issue....
Ruby
require "test/unit/testcase" require 'rexml/document' require 'rexml/entity' require 'rexml/source' class EntityTester < Test::Unit::TestCase def test_parse_general_decl simple = "<!ENTITY foo 'bar'>" simple =~ /#{REXML::Entity::GEDECL}/ assert $& assert_equal simple, $& REXML::Entity::ENTITYDE...
Ruby
require "test/unit/testcase" require "rexml/document" require "rexml/validation/relaxng" class RNGValidation < Test::Unit::TestCase include REXML def test_validate rng = %q{ <?xml version="1.0" encoding="UTF-8"?> <element name="A" xmlns="http://relaxng.org/ns/structure/1.0"> <element name="B"> <element...
Ruby
# coding: binary require "rexml_test_utils" require "rexml/document" require "rexml/parseexception" require "rexml/output" require "rexml/source" require "rexml/formatters/pretty" require "rexml/undefinednamespaceexception" require "listener" class Tester < Test::Unit::TestCase include REXMLTestUtils include RE...
Ruby
#!/usr/bin/ruby -Ku # -*- coding: utf-8 -*- require 'rexml/encoding' class ChangingEncodings < Test::Unit::TestCase def initialize a @u = 'テスト ほげ ふが 美しい' @e = @u.encode("EUC-JP") @f = Foo.new super end class Foo include REXML::Encoding end # Note that these tests must be executed in o...
Ruby
require 'rexml_test_utils' require 'rexml/document' require 'zlib' class OrderTester < Test::Unit::TestCase include REXMLTestUtils TESTDOC = <<END <a> <b/> <x id='1'/> <c/> <d> <x id='2'/> </d> <x id='3'/> </a> END def setup @doc = REXML::Document.new(TESTDOC) @items = REXML::XPath.m...
Ruby
require 'rexml/document' require 'test/unit' require 'rexml/functions' class TC_Rexml_Functions_Number < Test::Unit::TestCase def test_functions_number_int telem = REXML::Element.new("elem") telem.text="9" assert_equal(9, REXML::Functions::number(telem)) end def test_functions_number_float telem...
Ruby
require "test/unit/testcase" require "rexml/document" class XPathAxesTester < Test::Unit::TestCase include REXML SOURCE = <<-EOF <a id='1'> <e id='2'> <f id='3'/> <f id='4'/> <f id='5'/> <f id='6'/> </e> </a> EOF def setup @@doc = Document.new(SOURCE) ...
Ruby
#! /usr/local/bin/ruby require 'test/unit' require 'rexml/document' class TestAttributes < Test::Unit::TestCase def setup @ns_a = "urn:x-test:a" @ns_b = "urn:x-test:b" element_string = <<-"XMLEND" <test xmlns:a="#{@ns_a}" xmlns:b="#{@ns_b}" a = "1" b = '2' a:...
Ruby