File: test_string_sub.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-- 812 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/unit'

class UnitTest < Test::Unit::TestCase

  def initialize(test_method_name)
    super(test_method_name)
  end

  EOL="\r\n"

  def check buf, e1, e2, e3

    assert_equal e1, buf.size
    head = ''

    #from cgi.rb..
    buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do
      head = $1.dup
      ""
    end
    # ..cgi.rb

    assert_equal e2,  head.size
    assert_equal e3,  buf.size
  end

  def test_unit_method
    check "a"  + EOL + EOL + "a"  , 6, 3, 1  # 1byte + 2byte + 2byte + 1byte
    check "a"  + EOL + EOL + "あ" , 8, 3, 3  # 1byte + 2byte + 2byte + 3byte
    check "あ" + EOL + EOL + "a"  , 8, 5, 1  # 3byte + 2byte + 2byte + 1byte failure!!
    check "あ" + EOL + EOL + "あ" ,10, 5, 3  # 3byte + 2byte + 2byte + 3byte failure!!
  end
end