Created
February 17, 2012 15:15
-
-
Save kimoto/1853979 to your computer and use it in GitHub Desktop.
俺の名前にマッチするかどうか判断するための正規表現のテストケース
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/env ruby | |
| # encoding: utf-8 | |
| # Author: kimoto | |
| require 'term/ansicolor' | |
| require 'matchdata-highlight' | |
| include Term::ANSIColor | |
| def should_be_true(regexp, string) | |
| if (regexp =~ string) | |
| puts Regexp.last_match.highlight | |
| else | |
| raise "error: #{regexp.inspect} =~ #{string.inspect}".red | |
| end | |
| end | |
| def should_be_false(regexp, string) | |
| if (regexp !~ string) | |
| puts string | |
| else | |
| raise "error: #{regexp.inspect} !~ #{string.inspect}".red | |
| end | |
| end | |
| regexp = /((?<!ma)kimoto|(?<!ま)きもと|(?<!マ)キモト|(?<!六本)木本(?!花音)|キモッさん|きもっさん|キモっ##ん|きもッさん|キモタク)/ | |
| should_be_true regexp, "kimoto" | |
| should_be_false regexp, "makimoto" | |
| should_be_true regexp, "aaaaakimoto" | |
| should_be_true regexp, "kimotozzzz" | |
| should_be_true regexp, "aaaaakimotobbbb" | |
| should_be_false regexp, "aaaaakismotobbbb" | |
| should_be_false regexp, "" | |
| should_be_false regexp, "aiueokakikukeko" | |
| should_be_true regexp, "きもと" | |
| should_be_true regexp, "キモト" | |
| should_be_true regexp, "キモッさん" | |
| should_be_true regexp, "きもっさん" | |
| should_be_true regexp, "木本" | |
| should_be_false regexp, "木本花音" | |
| should_be_true regexp, "キモっさん" | |
| should_be_true regexp, "きもッさん" | |
| should_be_true regexp, "キモタク" | |
| should_be_false regexp, "まきもと" | |
| should_be_false regexp, "マキモト" | |
| should_be_false regexp, "六本木店" | |
| should_be_false regexp, "六本木本店" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment