######################################################################## # $Header: /var/local/cvsroot/4Suite/test/Xml/Xslt/Exslt/test_strings.py,v 1.2 2005/12/28 02:38:18 jkloth Exp $ """Tests for EXSLT Strings""" from Xml.Xslt import test_harness from Ft.Xml.Xslt.Exslt import Strings SOURCE = """ Is this EXSLT? No. no """ TESTS = [] # str:align() def test_Align(tester): sty = """\ """ source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty) expected = "Is this EXSLT? No. no---------" test_harness.XsltTest(tester, source, [sheet], expected, title='str:align() left') sty = """\ """ source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty) expected = "Is" test_harness.XsltTest(tester, source, [sheet], expected, title='str:align() right') sty = """\ """ source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty) expected = "---Is this EXSLT? No. no---" test_harness.XsltTest(tester, source, [sheet], expected, title='str:align() center') return TESTS.append(test_Align) # str:concat() def test_Concat(tester): src = """\ Is this EXSLT? No. no Is this EXSLT? No. no Is this EXSLT? No. no """ sty = """\ """ source = test_harness.FileInfo(string=src) sheet = test_harness.FileInfo(string=sty) expected = "Is this EXSLT? No. no" * 3 test_harness.XsltTest(tester, source, [sheet], expected, title='str:concat()') return TESTS.append(test_Concat) # str:decode-uri() def test_DecodeUri(tester): sty = """ """ expected = "http://www.example.com/my r\xe9sum\xe9.html" source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty) test_harness.XsltTest(tester, source, [sheet], expected, title='str:decode-uri() UTF-8') sty = """ """ expected = "http://www.example.com/my r\xc3\xa9sum\xc3\xa9.html" source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty) test_harness.XsltTest(tester, source, [sheet], expected, title='str:decode-uri() ISO-8859-1') return TESTS.append(test_DecodeUri) # str:endcode-uri() def test_EncodeUri(tester): strings = { 0: u'hello world', 1: u'hello%20world', 2: u'1 & 2 are < 3', 3: u'100% OK?', 4: u'\u00a1Hola!', 5: u'\u4eca\u65e5\u306f', } encodings = { 1: u'utf-8', 2: u'iso-8859-1', 3: u'utf-16le', } escape_res = { 1: u'true()', 0: u'false()', } expected = { #(str, encoding, escape_reserved): expected (0, 1, 0): u'hello%20world', (0, 1, 1): u'hello%20world', (0, 2, 0): u'hello%20world', (0, 2, 1): u'hello%20world', (0, 3, 0): u'hello%20world', (0, 3, 1): u'hello%20world', (1, 1, 0): u'hello%20world', (1, 1, 1): u'hello%20world', (1, 2, 0): u'hello%20world', (1, 2, 1): u'hello%20world', (1, 3, 0): u'hello%20world', (1, 3, 1): u'hello%20world', (2, 1, 0): u'1%20&%202%20are%20%3C%203', (2, 1, 1): u'1%20%26%202%20are%20%3C%203', (2, 2, 0): u'1%20&%202%20are%20%3C%203', (2, 2, 1): u'1%20%26%202%20are%20%3C%203', (2, 3, 0): u'1%20&%202%20are%20%3C%203', (2, 3, 1): u'1%20%26%202%20are%20%3C%203', (3, 1, 0): u'100%25%20OK?', (3, 1, 1): u'100%25%20OK%3F', (3, 2, 0): u'100%25%20OK?', (3, 2, 1): u'100%25%20OK%3F', (3, 3, 0): u'100%25%20OK?', (3, 3, 1): u'100%25%20OK%3F', (4, 1, 0): u'%C2%A1Hola!', (4, 1, 1): u'%C2%A1Hola!', (4, 2, 0): u'%A1Hola!', (4, 2, 1): u'%A1Hola!', (4, 3, 0): u'%A1%00Hola!', (4, 3, 1): u'%A1%00Hola!', (5, 1, 0): u'%E4%BB%8A%E6%97%A5%E3%81%AF', (5, 1, 1): u'%E4%BB%8A%E6%97%A5%E3%81%AF', (5, 2, 0): u'%3F%3F%3F', (5, 2, 1): u'%3F%3F%3F', (5, 3, 0): u'%CA%4E%E5%65%6F%30', (5, 3, 1): u'%CA%4E%E5%65%6F%30', } for s_key in strings.keys(): s = strings[s_key] for enc_key in encodings.keys(): encoding = encodings[enc_key] for esc_key in escape_res.keys(): escape = escape_res[esc_key] test_title = u"str:encode-uri(%r, %s, '%s')" % (s, escape, encoding) tester.startTest(test_title) if expected.has_key((s_key, enc_key, esc_key)): expected_str = expected[(s_key, enc_key, esc_key)] result = Strings.EncodeUri(None, s, esc_key, encoding) tester.compare(expected_str, result) else: tester.warning('Not tested; expected result unknown') tester.testDone() return TESTS.append(test_EncodeUri) # str:padding() def test_Padding(tester): sty = """ """ expected = """\ ---4567----23----890 Is this EXSLT? No. no +-++-++-++""" source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty) test_harness.XsltTest(tester, source, [sheet], expected, title='str:padding()') return TESTS.append(test_Padding) # str:replace() def test_Replace(tester): sty1 = """ e seven our the HI OO
$name $id phd 1234
""" expected1 = """ kiss me kiss me kiss me bye-bye silly bye-bye silly bye-bye silly ha-ha silly ha-ha silly ha-ha silly fOO scor and yars ago, OO forfars fOO scor and yars ago, OO forfars fOO scor and yars ago, OO forfars four score and seven years ago, our forefathers four score and seven years ago, our forefathers four score and seven years ago, our forefathers four score and seven ago, our forefathers four score and seven ago, our forefathers four score and seven ago, our forefathers line one
line two
line three
line one
line two
line three
line one
line two
line three
Patient: $name ($id)
""" sty2 = """ """ expected2 = """ bye-bye silly ha-ha silly """ source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty1) test_harness.XsltTest(tester, source, [sheet], expected1, title='str:replace() 1') source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty2) test_harness.XsltTest(tester, source, [sheet], expected2, title='str:replace() 2') return TESTS.append(test_Replace) # str:split() def test_Split(tester): sty1 = """ """ expected1 = """ a simple string date math str f o o """ source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty1) test_harness.XsltTest(tester, source, [sheet], expected1, title='str:split()') return TESTS.append(test_Split) # str:tokenize() def test_Tokenize(tester): sty = """ """ expected = """ 2001 06 03 11 40 23 date math str f o o """ source = test_harness.FileInfo(string=SOURCE) sheet = test_harness.FileInfo(string=sty) test_harness.XsltTest(tester, source, [sheet], expected, title='str:tokenize()') return TESTS.append(test_Tokenize) def Test(tester): tester.startGroup('Strings') for test in TESTS: test(tester) tester.groupDone() return