diff options
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 |