diff options
author | guy Decoux <ts@moulon.inra.fr> | 2009-02-28 20:04:27 +0100 |
---|---|---|
committer | guy Decoux <ts@moulon.inra.fr> | 2009-02-28 20:04:27 +0100 |
commit | 5ddb005992b57f89ee974c22b89a91f06e7fc2e3 (patch) | |
tree | a43de752a32b5c263bccbcacd66d1d74b0f1918b /b.rb | |
parent | 35a378406bed6a38e4797d7faefafa8c9738073e (diff) | |
download | mmap-ruby-5ddb005992b57f89ee974c22b89a91f06e7fc2e3.zip mmap-ruby-5ddb005992b57f89ee974c22b89a91f06e7fc2e3.tar.gz |
mmap-0.1.1
Diffstat (limited to 'b.rb')
-rwxr-xr-x | b.rb | 31 |
1 files changed, 29 insertions, 2 deletions
@@ -1,5 +1,32 @@ #!/usr/bin/ruby require "mmap" +PAGESIZE = 4096 +f = File.open("aa", "w") +f.write("\0" * PAGESIZE) +f.write("b.rb") +f.write("\0" * PAGESIZE) +f.close +m = Mmap.new("aa", "rw", "offset" => 0) +p m.size == "b.rb".size + 2 * PAGESIZE +p m.scan(/[a-z.]+/) == ["b.rb"] +p m.index("b.rb") == PAGESIZE +p m.rindex("b.rb") == PAGESIZE +p m.sub!(/[a-z.]+/, "toto") == m +p m.scan(/[a-z.]+/) == ["toto"] +begin + m.sub!(/[a-z.]+/, "alpha") + puts "not OK must give an error" +rescue + puts "OK : #$!" +end +m.munmap m = Mmap.new("aa", "rw") -m.gsub!(/(.)/, '(\&)') - +p m.index("toto") == PAGESIZE +p m.sub!(/([a-z.]+)/, "alpha") == m +p $& == "toto" +p $1 == "toto" +p m.index("toto") == nil +p m.index("alpha") == PAGESIZE +p m.size == 5 + 2 * PAGESIZE +m.gsub!(/\0/, "X") +p m.size == 5 + 2 * PAGESIZE |