# # bis2tests.py version 0.1 # Copyright (c) Robert D. Cameron, May 25, 2003 # Copies of this software may be made only for the purpose of # research and evaluation of URI processing based on internet # draft document draft-fielding-uri-rfc2396bis-02. # from URIbis2 import * # # The definitions for testbase, normal and abnormal are # copied from draft-fielding-uri-rfc2396bis-02 # testbase = 'http://a/b/c/d;p?q' # #5.4.1 Normal Examples # normal = r''' "g:h" = "g:h" "g" = "http://a/b/c/g" "./g" = "http://a/b/c/g" "g/" = "http://a/b/c/g/" "/g" = "http://a/g" "//g" = "http://g" "?y" = "http://a/b/c/d;p?y" "g?y" = "http://a/b/c/g?y" "#s" = "http://a/b/c/d;p?q#s" "g#s" = "http://a/b/c/g#s" "g?y#s" = "http://a/b/c/g?y#s" ";x" = "http://a/b/c/;x" "g;x" = "http://a/b/c/g;x" "g;x?y#s" = "http://a/b/c/g;x?y#s" "." = "http://a/b/c/" "./" = "http://a/b/c/" ".." = "http://a/b/" "../" = "http://a/b/" "../g" = "http://a/b/g" "../.." = "http://a/" "../../" = "http://a/" "../../g" = "http://a/g" ''' # #5.4.2 Abnormal Examples # abnormal = r''' "" = "http://a/b/c/d;p?q" "../../../g" = "http://a/g" "../../../../g" = "http://a/g" "/./g" = "http://a/g" "/../g" = "http://a/g" "g." = "http://a/b/c/g." ".g" = "http://a/b/c/.g" "g.." = "http://a/b/c/g.." "..g" = "http://a/b/c/..g" "./../g" = "http://a/b/g" "./g/." = "http://a/b/c/g/" "g/./h" = "http://a/b/c/g/h" "g/../h" = "http://a/b/c/h" "g;x=1/./y" = "http://a/b/c/g;x=1/y" "g;x=1/../y" = "http://a/b/c/y" "g?y/./x" = "http://a/b/c/g?y/./x" "g?y/../x" = "http://a/b/c/g?y/../x" "g#s/./x" = "http://a/b/c/g#s/./x" "g#s/../x" = "http://a/b/c/g#s/../x" "http:g" = "http:g" ''' def do_test_case(base, rel, abs): resolved = resolve_relative_URI(base, rel) if resolved == abs: print 'OK: resolve_relative_URI("%s", "%s") = "%s"' % (base, rel, resolved) else: print 'Error: resolve_relative_URI("%s", "%s") = "%s" != "%s"' % (base, rel, resolved, abs) relativized = compute_relative_URI(base, resolved) if relativized == rel: print ' OK: compute_relative_URI(%s, %s) = "%s"' % (base, resolved, relativized) else: print ' Note: compute_relative_URI("%s", "%s") = "%s" != "%s"' %(base, resolved, relativized, rel) reresolved = resolve_relative_URI(base, relativized) if reresolved == resolved: print ' OK: resolve_relative_URI("%s", "%s") = "%s"' %(base, relativized, reresolved) else: print ' Error: resolve_relative_URI("%s", "%s") = "%s" != "%s' %(base, relativized, reresolved, resolved) test_text_re = re.compile('^\s*"([^"]*)"\s*=\s*"([^"]*)"\s*$', re.M) def do_tests(base, testcase_text): for rel, abs in test_text_re.findall(testcase_text): do_test_case(base, rel, abs) do_tests(testbase, normal) do_tests(testbase, abnormal)