From 9bc1a9681b8530dbf6299cebd778fde23999630b Mon Sep 17 00:00:00 2001 From: guy Decoux Date: Sat, 28 Feb 2009 20:04:27 +0100 Subject: mmap-0.1.5 --- tests/mmapt.rb | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/mmapt.rb b/tests/mmapt.rb index 1c515a6..15fe5e4 100644 --- a/tests/mmapt.rb +++ b/tests/mmapt.rb @@ -1,6 +1,7 @@ #!/usr/bin/ruby $LOAD_PATH.unshift *%w{.. . tests} require 'mmap' +require 'ftools' require 'runit/testcase' require 'runit/cui/testrunner' @@ -9,15 +10,10 @@ $mmap, $str = nil, nil class TestMmap < RUNIT::TestCase def internal_init $mmap.unmap if $mmap - mmap = open("tmp/mmap", "w") - $str = <<-EOT - - some randomly generated text - - well, in reality not really, really random - EOT - mmap.print $str - mmap.close + file = "mmap.c" + file = "../mmap.c" unless File.exist? file + File.syscopy file, "tmp/mmap" + $str = File.readlines("tmp/mmap", nil)[0] assert_kind_of(Mmap, $mmap = Mmap.new("tmp/mmap", "rw"), "") end @@ -140,18 +136,18 @@ class TestMmap < RUNIT::TestCase end def test_04_reg - assert_equal($mmap.scan(/random/), $str.scan(/random/), "") - assert_equal($mmap.index("really"), $str.index("really"), "") - assert_equal($mmap.rindex("really"), $str.rindex("really"), "") + assert_equal($mmap.scan(/include/), $str.scan(/include/), "") + assert_equal($mmap.index("rb_raise"), $str.index("rb_raise"), "") + assert_equal($mmap.rindex("rb_raise"), $str.rindex("rb_raise"), "") ('a' .. 'z').each do |i| assert_equal($mmap.index(i), $str.index(i), "") assert_equal($mmap.rindex(i), $str.rindex(i), "") end - assert_equal($mmap.sub!(/real/, 'XXXX'), $str.sub!(/real/, 'XXXX'), "") + $mmap.sub!(/GetMmap/, 'XXXX'); $str.sub!(/GetMmap/, 'XXXX') assert_equal($mmap.to_str, $str, "") - assert_equal($mmap.gsub!(/real/, 'XXXX'), $str.gsub!(/real/, 'XXXX'), "") + $mmap.gsub!(/GetMmap/, 'XXXX'); $str.gsub!(/GetMmap/, 'XXXX') assert_equal($mmap.to_str, $str, "") - assert_equal($mmap.gsub!(/YYYY/, 'XXXX'), $str.gsub!(/YYYY/, 'XXXX'), "") + $mmap.gsub!(/YYYY/, 'XXXX'); $str.gsub!(/YYYY/, 'XXXX') assert_equal($mmap.to_str, $str, "") assert_equal($mmap.split(/\w+/), $str.split(/\w+/), "") assert_equal($mmap.split(/\W+/), $str.split(/\W+/), "") @@ -176,10 +172,21 @@ class TestMmap < RUNIT::TestCase internal_modify(:strip!) internal_modify(:chop!) internal_modify(:chomp!) + internal_modify(:squeeze!) internal_modify(:tr!, 'abcdefghi', '123456789') internal_modify(:tr_s!, 'jklmnopqr', '123456789') + internal_modify(:delete!, 'A-Z') end + def test_06_iterate + internal_init + mmap = []; $mmap.each {|l| mmap << l} + str = []; $str.each {|l| str << l} + assert_equal(mmap, str, "") + mmap = []; $mmap.each_byte {|l| mmap << l} + str = []; $str.each_byte {|l| str << l} + assert_equal(mmap, str, "") + end end -- cgit v1.2.3