summaryrefslogtreecommitdiffstats
path: root/b.rb
diff options
context:
space:
mode:
authorguy Decoux <ts@moulon.inra.fr>2009-02-28 20:04:27 +0100
committerguy Decoux <ts@moulon.inra.fr>2009-02-28 20:04:27 +0100
commit5ddb005992b57f89ee974c22b89a91f06e7fc2e3 (patch)
treea43de752a32b5c263bccbcacd66d1d74b0f1918b /b.rb
parent35a378406bed6a38e4797d7faefafa8c9738073e (diff)
downloadmmap-ruby-5ddb005992b57f89ee974c22b89a91f06e7fc2e3.zip
mmap-ruby-5ddb005992b57f89ee974c22b89a91f06e7fc2e3.tar.gz
mmap-0.1.1
Diffstat (limited to 'b.rb')
-rwxr-xr-xb.rb31
1 files changed, 29 insertions, 2 deletions
diff --git a/b.rb b/b.rb
index 6c685ca..2bc2475 100755
--- a/b.rb
+++ b/b.rb
@@ -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