File: testStringGsubStress.rb

package info (click to toggle)
jruby 1.5.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 46,252 kB
  • ctags: 72,039
  • sloc: ruby: 398,155; java: 169,482; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (34 lines) | stat: -rw-r--r-- 834 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'test/minirunit'
test_check "Test string#gsub stress test:"

# this test originally caused out of memory errors on the 0.9.0 release 
mess="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghihklmnopqrstuvwxyz0123456789!+" #64
mess << mess #128
mess << mess #256
mess << mess #512
mess << mess #1024
mess << mess #2048
mess << mess #4096
mess << mess 
mess << mess 




# puts mess.size
result = mess.gsub(/(.)/,'(\1)')
test_equal("+", result[-2].chr)

# this test originally caused out of memory errors on the 0.9.0 release
count = 0
my_arr = []
result = mess.gsub(/./) do |m|
  my_arr << m     # this is what actually causes the OOM error - without this line its just very slow
  count += 1
  # test_equal("E\n", line) if count == 5
  "(#{m})"
  # print "Expecting E got " + c if count == 5
end
test_equal("+", result[-2].chr)
# puts count