Last active
August 29, 2015 14:03
-
-
Save k-takata/85cf4de23d8194b2da34 to your computer and use it in GitHub Desktop.
onigmo test script for cclass with ignorecase
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function, unicode_literals | |
import onig | |
import testpy | |
import sys | |
x2 = testpy.x2 | |
x3 = testpy.x3 | |
n = testpy.n | |
def main(): | |
# set encoding of the test target | |
if len(sys.argv) > 1: | |
try: | |
testpy.set_encoding(sys.argv[1]) | |
except KeyError: | |
print("test target encoding error") | |
print("Usage: python testpy.py [test target encoding] [output encoding]") | |
sys.exit() | |
else: | |
testpy.set_encoding("UTF-8") | |
# set encoding of stdout/stderr | |
outenc = None | |
if len(sys.argv) > 2: | |
outenc = sys.argv[2] | |
testpy.set_output_encoding(outenc) | |
x2("(?iu)\\w", "\u017f", 0, 1); | |
x2("(?iu)[\\w]", "\u017f", 0, 1); | |
x2("(?iu)[^\\W]", "\u017f", 0, 1); | |
n("(?iu)\\W", "\u017f"); | |
n("(?iu)[\\W]", "\u017f"); | |
n("(?iu)[^\\w]", "\u017f"); | |
n("(?ia)\\w", "\u017f"); | |
n("(?ia)[\\w]", "\u017f"); | |
n("(?ia)[^\\W]", "\u017f"); | |
x2("(?ia)\\W", "\u017f", 0, 1); | |
x2("(?ia)[\\W]", "\u017f", 0, 1); | |
x2("(?ia)[^\\w]", "\u017f", 0, 1); | |
x2("(?ia)\\w", "s", 0, 1); | |
x2("(?ia)[\\w]", "s", 0, 1); | |
x2("(?ia)[^\\W]", "s", 0, 1); | |
n("(?ia)\\W", "s"); | |
n("(?ia)[\\W]", "s"); | |
n("(?ia)[^\\w]", "s"); | |
print() | |
n("(?ia)\\p{ASCII}", "\u017f"); | |
n("(?ia)[\\p{ASCII}]", "\u017f"); | |
x2("(?ia)\\P{ASCII}", "\u017f", 0, 1); | |
x2("(?ia)[\\P{ASCII}]", "\u017f", 0, 1); | |
x2("(?ia)\\p{ASCII}", "s", 0, 1); | |
x2("(?ia)[\\p{ASCII}]", "s", 0, 1); | |
n("(?ia)\\P{ASCII}", "s"); | |
n("(?ia)[\\P{ASCII}]", "s"); | |
print() | |
x2("(?u)\\p{lower}", "\u017f", 0, 1); | |
x2("(?a)\\p{lower}", "\u017f", 0, 1); | |
x2("(?iu)\\p{lower}", "\u017f", 0, 1); | |
x2("(?ia)\\p{lower}", "\u017f", 0, 1); | |
x2("(?u)\\p{upper}", "\u212a", 0, 1); | |
x2("(?a)\\p{upper}", "\u212a", 0, 1); | |
x2("(?iu)\\p{upper}", "\u212a", 0, 1); | |
x2("(?ia)\\p{upper}", "\u212a", 0, 1); | |
x2("(?u)\\p{lower}", "\u00df", 0, 1); | |
x2("(?a)\\p{lower}", "\u00df", 0, 1); | |
x2("(?iu)\\p{lower}", "\u00df", 0, 1); | |
x2("(?ia)\\p{lower}", "\u00df", 0, 1); | |
x2("(?iu)\\p{lower}\\p{upper}", "Ab", 0, 2); | |
x2("(?ia)\\p{lower}\\p{upper}", "Ab", 0, 2); | |
print() | |
x2("(?u)[[:lower:]]", "\u017f", 0, 1); | |
n("(?a)[[:lower:]]", "\u017f"); | |
x2("(?iu)[[:lower:]]", "\u017f", 0, 1); | |
n("(?ia)[[:lower:]]", "\u017f"); | |
x2("(?u)[[:upper:]]", "\u212a", 0, 1); | |
n("(?a)[[:upper:]]", "\u212a"); | |
x2("(?iu)[[:upper:]]", "\u212a", 0, 1); | |
n("(?ia)[[:upper:]]", "\u212a"); | |
x2("(?u)[[:lower:]]", "\u00df", 0, 1); | |
n("(?a)[[:lower:]]", "\u00df"); | |
x2("(?iu)[[:lower:]]", "\u00df", 0, 1); | |
n("(?ia)[[:lower:]]", "\u00df"); | |
x2("(?iu)[[:lower:]][[:upper:]]", "Ab", 0, 2); | |
x2("(?ia)[[:lower:]][[:upper:]]", "Ab", 0, 2); | |
print() | |
x2("(?iu)ss", "\u00df", 0, 1); | |
x2("(?ia)ss", "\u00df", 0, 1); | |
x2("(?iu)\u00df", "ss", 0, 2); | |
x2("(?ia)\u00df", "ss", 0, 2); | |
x2("(?iu)[\u00df]", "ss", 0, 2); | |
x2("(?ia)[\u00df]", "ss", 0, 2); | |
x2("(?iu)\\x{df}", "ss", 0, 2); | |
x2("(?ia)\\x{df}", "ss", 0, 2); | |
x2("(?iu)[\\x{df}]", "ss", 0, 2); | |
x2("(?ia)[\\x{df}]", "ss", 0, 2); | |
x2("(?iu)K", "\u212a", 0, 1); | |
x2("(?ia)K", "\u212a", 0, 1); | |
x2("(?iu)\u212a", "K", 0, 1); | |
x2("(?ia)\u212a", "K", 0, 1); | |
x2("(?iu)[\u212a]", "K", 0, 1); | |
x2("(?ia)[\u212a]", "K", 0, 1); | |
x2("(?iu)\\x{212a}", "K", 0, 1); | |
x2("(?ia)\\x{212a}", "K", 0, 1); | |
x2("(?iu)[\\x{212a}]", "K", 0, 1); | |
x2("(?ia)[\\x{212a}]", "K", 0, 1); | |
x2("(?iu)s", "\u017f", 0, 1); | |
x2("(?ia)s", "\u017f", 0, 1); | |
x2("(?iu)\u017f", "s", 0, 1); | |
x2("(?ia)\u017f", "s", 0, 1); | |
x2("(?iu)[\u017f]", "s", 0, 1); | |
x2("(?ia)[\u017f]", "s", 0, 1); | |
x2("(?iu)\\x{017f}", "s", 0, 1); | |
x2("(?ia)\\x{017f}", "s", 0, 1); | |
x2("(?iu)[\\x{017f}]", "s", 0, 1); | |
x2("(?ia)[\\x{017f}]", "s", 0, 1); | |
x2("(?iu)[a]+", "Aa ", 0, 2); | |
x2("(?ia)[a]+", "Aa ", 0, 2); | |
x2("(?iu)[A]+", "Aa ", 0, 2); | |
x2("(?ia)[A]+", "Aa ", 0, 2); | |
x2("(?iu)[s]+", "Ss\u017f ", 0, 3); | |
x2("(?ia)[s]+", "Ss\u017f ", 0, 3); | |
x2("(?iu)[S]+", "Ss\u017f ", 0, 3); | |
x2("(?ia)[S]+", "Ss\u017f ", 0, 3); | |
x2("(?iu)[^a]+", "Aa ", 2, 3); | |
x2("(?ia)[^a]+", "Aa ", 2, 3); | |
x2("(?iu)[^A]+", "Aa ", 2, 3); | |
x2("(?ia)[^A]+", "Aa ", 2, 3); | |
x2("(?iu)[^s]+", "Ss\u017f ", 3, 4); | |
x2("(?ia)[^s]+", "Ss\u017f ", 3, 4); | |
x2("(?iu)[^S]+", "Ss\u017f ", 3, 4); | |
x2("(?ia)[^S]+", "Ss\u017f ", 3, 4); | |
print("\nEncoding:", testpy.encoding) | |
print("RESULT SUCC: %d, FAIL: %d, ERROR: %d (by Onigmo %s)" % ( | |
testpy.nsucc, testpy.nfail, testpy.nerror, onig.onig_version())) | |
onig.onig_end() | |
if (testpy.nfail == 0 and testpy.nerror == 0): | |
exit(0) | |
else: | |
exit(-1) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment