Index: EcnlProtoTool/trunk/mrbgems/mruby-onig-regexp/test/mruby_onig_regexp.rb
===================================================================
--- EcnlProtoTool/trunk/mrbgems/mruby-onig-regexp/test/mruby_onig_regexp.rb	(revision 321)
+++ EcnlProtoTool/trunk/mrbgems/mruby-onig-regexp/test/mruby_onig_regexp.rb	(revision 439)
@@ -2,5 +2,7 @@
 # Constant
 assert("OnigRegexp::CONSTANT") do
-  OnigRegexp::IGNORECASE == 1 and OnigRegexp::EXTENDED == 2 and OnigRegexp::MULTILINE == 4
+  assert_equal 1, OnigRegexp::IGNORECASE
+  assert_equal 2, OnigRegexp::EXTENDED
+  assert_equal 4, OnigRegexp::MULTILINE
 end
 
@@ -20,4 +22,7 @@
   OnigRegexp.new('.*') =~ 'ginka'
   assert_equal 'ginka', OnigRegexp.last_match[0]
+
+  OnigRegexp.new('zzz') =~ 'ginka'
+  assert_nil OnigRegexp.last_match
 end
 
@@ -28,5 +33,6 @@
 # Instance method
 assert('OnigRegexp#initialize', '15.2.15.7.1') do
-  OnigRegexp.new(".*") and OnigRegexp.new(".*", OnigRegexp::MULTILINE)
+  assert_equal OnigRegexp, OnigRegexp.new(".*").class
+  assert_equal OnigRegexp, OnigRegexp.new(".*", OnigRegexp::MULTILINE).class
 end
 
@@ -52,4 +58,6 @@
   assert_true reg === "http://example.com"
   assert_false reg === "htt://example.com"
+
+  assert_false /a/ === Object.new
 end
 
@@ -71,4 +79,10 @@
   assert_false reg.match("http://masamitsu-murase.12345/hoge.html").nil?
   assert_nil reg.match("http:///masamitsu-murase.12345/hoge.html")
+
+  reg = OnigRegexp.new('def')
+  assert_equal "def", reg.match('abcdef', 3)[0]
+  assert_nil reg.match('abcdef', -1)
+  assert_nil reg.match('abcdef', 4)
+  assert_nil reg.match(nil, 3)
 end
 
@@ -77,5 +91,5 @@
   reg = OnigRegexp.new(str)
 
-  reg.source == str
+  assert_equal str, reg.source
 end
 
@@ -96,4 +110,5 @@
   assert_equal '/abc\nd\te/mi', OnigRegexp.new("abc\nd\te", OnigRegexp::MULTILINE | OnigRegexp::IGNORECASE).inspect
   assert_equal '/abc/min', OnigRegexp.new("abc", OnigRegexp::MULTILINE | OnigRegexp::IGNORECASE, "none").inspect
+  assert_equal "/\\\\\\+\\//", /\\\+\//.inspect
 end
 
@@ -104,4 +119,5 @@
   assert_equal '(?mi-x:ab+c)', /ab+c/im.to_s
   assert_equal '(?mi-x:ab+c)', /ab+c/imn.to_s
+  assert_equal "(?-mix:\\\\\\+)", /\\\+/.to_s
 end
 
@@ -114,4 +130,8 @@
   re4 = OnigRegexp.new("xy#{re3}z", OnigRegexp::IGNORECASE)
   assert_equal '(?i-mx:xy(?m-ix:ab.+c)z)', re4.to_s
+
+  re5 = /\\\+/
+  re6 = /xy#{re5}z/
+  assert_equal "(?-mix:xy(?-mix:\\\\\\+)z)", re6.to_s
 end
 
@@ -122,9 +142,13 @@
     [ "^a.", "abcd\naefg", "ab" ],
     [ "^a.", "bacd\naefg", "ae" ],
-    [ ".$", "bacd\naefg", "d" ]
+    [ ".$", "bacd\naefg", "d" ],
+    [ "bc", :abc, "bc"],
+    [ "bj", "obj", "bj"],
   ].each do |reg, str, result|
     m = OnigRegexp.new(reg).match(str)
     assert_equal result, m[0] if assert_false m.nil?
   end
+
+  assert_raise(TypeError) { /a/.match(Object.new) }
 end
 
@@ -134,5 +158,5 @@
   ]
 
-  patterns.all?{ |reg, str, result| reg.match(str)[0] == result }
+  patterns.each{ |reg, str, result| assert_equal result, reg.match(str)[0] }
 end
 
@@ -152,10 +176,22 @@
 end
 
+assert("OnigRegexp#match (with block)") do
+  reg = OnigRegexp.new("(https?://[^/]+)[-a-zA-Z0-9./]+")
+  reg.match("http://masamitsu-murase.12345/hoge.html") do |m|
+    assert_true m.is_a?(OnigMatchData)
+    assert_equal "http://masamitsu-murase.12345/hoge.html", m[0]
+  end
+end
+
 assert('OnigRegexp.version') do
-  OnigRegexp.version.kind_of? String
+  assert_kind_of String, OnigRegexp.version
 end
 
 def onig_match_data_example
   OnigRegexp.new('(\w+)(\w)').match('+aaabb-')
+end
+
+def onig_mismatch_data_example
+  OnigRegexp.new('abc').match('z')
 end
 
@@ -248,5 +284,11 @@
 
 assert('Invalid regexp') do
-  assert_raise(ArgumentError) { OnigRegexp.new '[aio' }
+  assert_raise(RegexpError) { OnigRegexp.new '[aio' }
+end
+
+assert('Invalid argument') do
+  assert_raise(ArgumentError) { "".sub(//) }
+  assert_raise(ArgumentError) { "".onig_regexp_sub(OnigRegexp.new('')) }
+  assert_raise(ArgumentError) { "\xf0".gsub(/[^a]/,"X") }
 end
 
@@ -257,5 +299,17 @@
   assert_equal 'h e l l o  m r u b y ', test_str.onig_regexp_gsub(OnigRegexp.new('\w')) { |v| v + ' ' }
   assert_equal 'h{e}ll{o} mr{u}by', test_str.onig_regexp_gsub(OnigRegexp.new('(?<hoge>[aeiou])'), '{\k<hoge>}')
-  assert_raise(IndexError) { test_str.onig_regexp_gsub(OnigRegexp.new('(mruby)'), '<\2>') }
+  assert_equal '.h.e.l.l.o. .m.r.u.b.y.', test_str.onig_regexp_gsub(OnigRegexp.new(''), '.')
+  assert_equal " hello\n mruby", "hello\nmruby".onig_regexp_gsub(OnigRegexp.new('^'), ' ')
+  assert_equal "he<l><><l><>o mruby", test_str.onig_regexp_gsub(OnigRegexp.new('(l)'), '<\1><\2>')
+end
+
+assert('String#onig_regexp_gsub with hash') do
+  assert_equal('azc', 'abc'.gsub(/b/, "b" => "z"))
+  assert_equal('ac', 'abc'.gsub(/b/, {}))
+  assert_equal('a1c', 'abc'.gsub(/b/, "b" => 1))
+  assert_equal('aBc', 'abc'.gsub(/b/, Hash.new {|h, k| k.upcase }))
+  assert_equal('a[\&]c', 'abc'.gsub(/b/, "b" => '[\&]'))
+  assert_equal('aBcaBc', 'abcabc'.gsub(/b/, Hash.new {|h, k| h[k] = k.upcase }))
+  assert_equal('aBcDEf', 'abcdef'.gsub(/de|b/, "b" => "B", "de" => "DE"))
 end
 
@@ -274,4 +328,7 @@
   assert_equal test_str, test_str.onig_regexp_scan(OnigRegexp.new('(.)(.)')) { |x, y| result += y; result += x }
   assert_equal 'rmbu yowlr', result
+
+  assert_equal [""] * (test_str.length + 1), test_str.onig_regexp_scan(OnigRegexp.new(''))
+  assert_equal [""], "".onig_regexp_scan(OnigRegexp.new(''))
 end
 
@@ -282,4 +339,15 @@
   assert_equal 'h ello mruby', test_str.onig_regexp_sub(OnigRegexp.new('\w')) { |v| v + ' ' }
   assert_equal 'h{e}llo mruby', test_str.onig_regexp_sub(OnigRegexp.new('(?<hoge>[aeiou])'), '{\k<hoge>}')
+  assert_equal "heOlo mruby", test_str.onig_regexp_sub(OnigRegexp.new("l"), "O") { "X" }
+end
+
+assert('String#onig_regexp_sub with hash') do
+  assert_equal('azc', 'abc'.sub(/b/, "b" => "z"))
+  assert_equal('ac', 'abc'.sub(/b/, {}))
+  assert_equal('a1c', 'abc'.sub(/b/, "b" => 1))
+  assert_equal('aBc', 'abc'.sub(/b/, Hash.new {|h, k| k.upcase }))
+  assert_equal('a[\&]c', 'abc'.sub(/b/, "b" => '[\&]'))
+  assert_equal('aBcabc', 'abcabc'.sub(/b/, Hash.new {|h, k| h[k] = k.upcase }))
+  assert_equal('aBcdef', 'abcdef'.sub(/de|b/, "b" => "B", "de" => "DE"))
 end
 
@@ -292,9 +360,35 @@
   $; = OnigRegexp.new ' \w'
   assert_equal ['cute', 'ruby', 'ute'], test_str.onig_regexp_split
+  assert_equal ['cute', 'ruby', 'ute'], test_str.onig_regexp_split(nil)
+  assert_equal ['cute', 'ruby cute'], test_str.onig_regexp_split(nil, 2)
   $; = 't'
   assert_equal ['cu', 'e mruby cu', 'e'], test_str.onig_regexp_split
+  assert_equal ['cu', 'e mruby cu', 'e'], test_str.onig_regexp_split(nil)
+  assert_equal ['cu', 'e mruby cute'], test_str.onig_regexp_split(nil, 2)
+  $; = nil
+  assert_equal ['cute', 'mruby', 'cute'], test_str.onig_regexp_split
+  assert_equal ['cute', 'mruby', 'cute'], test_str.onig_regexp_split(nil)
+  assert_equal ['cute', 'mruby cute'], test_str.onig_regexp_split(nil, 2)
+  $; = 1
+  assert_raise(TypeError) { "".onig_regexp_split }
   $; = prev_splitter
 
   assert_equal ['h', 'e', 'l', 'l', 'o'], 'hello'.onig_regexp_split(OnigRegexp.new(''))
+  assert_equal ["h", "e", "l", "l", "o", ""], 'hello'.onig_regexp_split(OnigRegexp.new(''), -1)
+  assert_equal ["h", "", "i", "", "!", "", ""], "hi!".onig_regexp_split(OnigRegexp.new('()'), -1)
+  assert_equal ["h", "el", "lo"], "hello".onig_regexp_split(OnigRegexp.new('(el)|(xx)'))
+
+  assert_equal ['あ', 'い', 'う', 'え', 'お'], 'あいうえお'.onig_regexp_split('')
+  assert_equal ['あ', 'い', 'う', 'え', 'お', ''], 'あいうえお'.onig_regexp_split('', -1)
+  assert_equal ['あいうえお'], 'あいうえお'.onig_regexp_split('', 1)
+  assert_equal ['あ', 'いうえお'], 'あいうえお'.onig_regexp_split('', 2)
+  assert_equal ['あ', 'い', 'うえお'], 'あいうえお'.onig_regexp_split('', 3)
+
+  assert_equal ['あ', 'い', 'う', 'え', 'お'], 'あいうえお'.onig_regexp_split(OnigRegexp.new(''))
+  assert_equal ['あ', 'い', 'う', 'え', 'お', ''], 'あいうえお'.onig_regexp_split(OnigRegexp.new(''), -1)
+  assert_equal ['あいうえお'], 'あいうえお'.onig_regexp_split(OnigRegexp.new(''), 1)
+  assert_equal ['あ', 'いうえお'], 'あいうえお'.onig_regexp_split(OnigRegexp.new(''), 2)
+  assert_equal ['あ', 'い', 'うえお'], 'あいうえお'.onig_regexp_split(OnigRegexp.new(''), 3)
+
   assert_equal ['h', 'e', 'llo'], 'hello'.onig_regexp_split(OnigRegexp.new(''), 3)
   assert_equal ['h', 'i', 'd', 'a', 'd'], 'hi dad'.onig_regexp_split(OnigRegexp.new('\s*'))
@@ -309,4 +403,18 @@
 
   assert_equal [], ''.onig_regexp_split(OnigRegexp.new(','), -1)
+
+  assert_equal ["こ", "に", "ち", "わ"], "こ,に,ち,わ".onig_regexp_split(",")
+  assert_raise(TypeError) { "".onig_regexp_split(1) }
+end
+
+assert('String#onig_regexp_match') do
+  reg = OnigRegexp.new('d(e)f')
+  assert_equal ['def', 'e'], 'abcdef'.match(reg).to_a
+  assert_nil 'abcdef'.match(reg, 4)
+  match_data = nil
+  'abcdef'.match(reg) do |m|
+    match_data = m
+  end
+  assert_equal ['def', 'e'], match_data.to_a
 end
 
@@ -332,4 +440,7 @@
   m = onig_match_data_example
   assert_equal m[0], $~[0]
+
+  onig_mismatch_data_example
+  assert_nil $~
 end
 
@@ -337,4 +448,7 @@
   m = onig_match_data_example
   assert_equal m[0], $&
+
+  onig_mismatch_data_example
+  assert_nil $&
 end
 
@@ -342,4 +456,7 @@
   m = onig_match_data_example
   assert_equal m.pre_match, $`
+
+  onig_mismatch_data_example
+  assert_nil $`
 end
 
@@ -347,4 +464,7 @@
   m = onig_match_data_example
   assert_equal m.post_match, $'
+
+  onig_mismatch_data_example
+  assert_nil $'
 end
 
@@ -352,4 +472,7 @@
   m = onig_match_data_example
   assert_equal m[-1], $+
+
+  onig_mismatch_data_example
+  assert_nil $+
 end
 
@@ -365,4 +488,15 @@
   assert_nil $8
   assert_nil $9
+
+  onig_mismatch_data_example
+  assert_nil $1
+  assert_nil $2
+  assert_nil $3
+  assert_nil $4
+  assert_nil $5
+  assert_nil $6
+  assert_nil $7
+  assert_nil $8
+  assert_nil $9
 end
 
@@ -387,7 +521,52 @@
 end
 
+assert('OnigRegexp#match?') do
+  assert_false OnigRegexp.new('^[123]+$').match?('abc')
+  assert_false OnigRegexp.new('^[123]+$').match?(:abc)
+  assert_true OnigRegexp.new('^[123]+$').match?('321')
+  assert_true OnigRegexp.new('webp').match?('text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8')
+  assert_true(/webp/.match?('text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'))
+
+  reg = OnigRegexp.new('def')
+  assert_true reg.match?('abcdef', 3)
+  assert_false reg.match?('abcdef', -1)
+  assert_false reg.match?('abcdef', 4)
+  assert_false reg.match?(nil, 3)
+end
+
+assert('String#match?') do
+  assert_equal false, 'abc'.onig_regexp_match?(OnigRegexp.new('^[123]+$'))
+  assert_equal true, '321'.onig_regexp_match?(OnigRegexp.new('^[123]+$'))
+  assert_true 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'.onig_regexp_match?(OnigRegexp.new('webp'))
+end
+
+assert('String#[]=') do
+  string = 'abc'
+  string[OnigRegexp.new('.')] = 'A'
+  assert_equal 'Abc', string
+  string[OnigRegexp.new('.(.)'), 1] = 'B'
+  assert_equal 'ABc', string
+  string[OnigRegexp.new('(?<a>.)(?<b>.)(?<c>.)'), 'c'] = 'C'
+  assert_equal 'ABC', string
+
+  assert_raise(ArgumentError) do
+    string[OnigRegexp.new('.'), 0, :extra] = 'x'
+  end
+end
+
+assert('String#slice!') do
+  string = 'abc'
+  assert_equal 'a', string.slice!(OnigRegexp.new('.'))
+  assert_equal 'bc', string
+end
+
+assert 'raises RegexpError' do
+  assert_raise(RegexpError) { OnigRegexp.new('*') }
+end
+
 Regexp = Object
 
 assert('OnigRegexp not default') do
+  $~ = nil
   onig_match_data_example
   assert_nil $~
