# This file is encoded in ShiftJIS. die "This file is not encoded in ShiftJIS.\n" if q{あ} ne "\x82\xa0"; use Char::Sjis; print "1..15\n"; my $__FILE__ = __FILE__; $text = 'IO.SYS:225558:95−10−03:−a−sh:optional'; # 7.7 split演算子(リストコンテキスト) @_ = split(/:/, $text); if (join('', map {"($_)"} @_) eq "(IO.SYS)(225558)(95−10−03)(−a−sh)(optional)") { print qq{ok - 1 \@_ = split(/:/, \$text); $^X $__FILE__\n}; } else { print qq{not ok - 1 \@_ = split(/:/, \$text); $^X $__FILE__\n}; } # 特殊なマッチ被演算子 // を使った場合 @_ = split(//, "short test"); if (join('', map {"($_)"} @_) eq "(s)(h)(o)(r)(t)( )(t)(e)(s)(t)") { print qq{ok - 2 \@_ = split(//, "short test") $^X $__FILE__\n}; } else { print qq{not ok - 2 \@_ = split(//, "short test") $^X $__FILE__\n}; } # 特殊なマッチ被演算子 " "(スペース1個分の通常の文字列)を使った場合 @_ = split(" ", " a short test "); if (join('', map {"($_)"} @_) eq "(a)(short)(test)") { print qq{ok - 3 \@_ = split(" ", " a short test ") $^X $__FILE__\n}; } else { print qq{not ok - 3 \@_ = split(" ", " a short test ") $^X $__FILE__\n}; } # 先頭の空白を残したい場合 @_ = split(m/\s+/, " a short test "); if (join('', map {"($_)"} @_) eq "()(a)(short)(test)") { print qq{ok - 4 \@_ = split(m/\\s+/, " a short test ") $^X $__FILE__\n}; } else { print qq{not ok - 4 \@_ = split(m/\\s+/, " a short test ") $^X $__FILE__\n}; } # 末尾の空白を残したい場合 @_ = split(" ", " a short test ", -1); if (join('', map {"($_)"} @_) eq "(a)(short)(test)()") { print qq{ok - 5 \@_ = split(" ", " a short test ", -1) $^X $__FILE__\n}; } else { print qq{not ok - 5 \@_ = split(" ", " a short test ", -1) $^X $__FILE__\n}; } # マッチ被演算子が指定されていない場合 $_ = " a short test "; @_ = split; if (join('', map {"($_)"} @_) eq "(a)(short)(test)") { print qq{ok - 6 \@_ = split $^X $__FILE__\n}; } else { print qq{not ok - 6 \@_ = split $^X $__FILE__\n}; } # 7.7.1.2 ターゲット文字列が指定されていない場合 $_ = $text; @_ = split(/:/); if (join('', map {"($_)"} @_) eq "(IO.SYS)(225558)(95−10−03)(−a−sh)(optional)") { print qq{ok - 7 \@_ = split(/:/) $^X $__FILE__\n}; } else { print qq{not ok - 7 \@_ = split(/:/) $^X $__FILE__\n}; } # 7.7.1.3 個数上限被演算子の基本 @_ = split(/:/, $text, 3); if (join('', map {"($_)"} @_) eq "(IO.SYS)(225558)(95−10−03:−a−sh:optional)") { print qq{ok - 8 \@_ = split(/:/, \$text, 3) $^X $__FILE__\n}; } else { print qq{not ok - 8 \@_ = split(/:/, \$text, 3) $^X $__FILE__\n}; } # 7.7.2 空要素 @_ = split(m/:/, "12:34::78"); if (join('', map {"($_)"} @_) eq "(12)(34)()(78)") { print qq{ok - 9 \@_ = split(m/:/, "12:34::78") $^X $__FILE__\n}; } else { print qq{not ok - 9 \@_ = split(m/:/, "12:34::78") $^X $__FILE__\n}; } # 7.7.2.1 末尾の空要素 @_ = split(m/:/, "12:34::78:::"); if (join('', map {"($_)"} @_) eq "(12)(34)()(78)") { print qq{ok - 10 \@_ = split(m/:/, "12:34::78:::") $^X $__FILE__\n}; } else { print qq{not ok - 10 \@_ = split(m/:/, "12:34::78:::") $^X $__FILE__\n}; } # 7.7.2.3 文字列の両端での特殊なマッチ @_ = split(m/:/, ":12:34::78"); if (join('', map {"($_)"} @_) eq "()(12)(34)()(78)") { print qq{ok - 11 \@_ = split(m/:/, ":12:34::78") $^X $__FILE__\n}; } else { print qq{not ok - 11 \@_ = split(m/:/, ":12:34::78") $^X $__FILE__\n}; } # 「^」という正規表現を使った場合 $_ = "AAA\nBBB\nCCC"; @_ = split(m/^/, $_); if (join('', map {"($_)"} @_) eq "(AAA\n)(BBB\n)(CCC)") { print qq{ok - 12 \@_ = split(m/^/, \$\_) $^X $__FILE__\n}; } else { print qq{not ok - 12 \@_ = split(m/^/, \$\_) $^X $__FILE__\n}; } @_ = split(m/^/m, $_); if (join('', map {"($_)"} @_) eq "(AAA\n)(BBB\n)(CCC)") { print qq{ok - 13 \@_ = split(m/^/m, \$\_) $^X $__FILE__\n}; } else { print qq{not ok - 13 \@_ = split(m/^/m, \$\_) $^X $__FILE__\n}; } # 7.7.4 キャプチャ付き括弧を含む split のマッチ被演算子 @_ = split(/(<[^>]*>)/, " and <B>very <FONT color=red>very much effort"); if (join('', map {"($_)"} @_) eq "( and )(<B>)(very )(<FONT color=red>)(very)()( much)()( effort)") { print qq{ok - 14 \@_ = split(/(<[^>]*>)/, " and <B>very <FONT color=red>very much effort") $^X $__FILE__\n}; } else { print qq{not ok - 14 \@_ = split(/(<[^>]*>)/, " and <B>very <FONT color=red>very much effort") $^X $__FILE__\n}; } # 7.7.3.1 split には副作用がないことの確認 $a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $a =~ m/ABC(DEF)G(HI)/; if (($1 eq "DEF") and ($2 eq "HI")) { $b = "123,45,6,78,,90"; @_ = split(/,/,$b); if (($1 eq "DEF") and ($2 eq "HI")) { print qq{ok - 15 split に副作用がないことの確認 ($1)($2) $^X $__FILE__\n}; } else { print qq{not ok - 15 split に副作用がないことの確認 ($1)($2) $^X $__FILE__\n}; } } else { print qq{not ok - 15 split に副作用がないことの確認 ($1)($2) $^X $__FILE__\n}; } __END__