#! /usr/bin/env python
# -*- coding: utf-8 -*-
# $Id: test_east_asian_text.py 5889 2009-04-01 20:00:21Z gbrandl $
# Author: David Goodger <goodger@python.org>
# Copyright: This module has been placed in the public domain.
"""
Tests for East Asian text with double-width characters.
"""
from __init__ import DocutilsTestSupport
import unicodedata
try:
east_asian_width = unicodedata.east_asian_width
except AttributeError:
east_asian_width = None
from docutils._compat import b
def suite():
s = DocutilsTestSupport.ParserTestSuite()
s.generateTests(totest)
return s
totest = {}
if not east_asian_width:
print ('test_east_asian_text.py tests skipped; '
'Python 2.4 or higher required.')
else:
totest['double-width'] = [
[u"""\
1
=========
2
========
""",
u"""\
<document source="test data">
<section ids="id1" names="1">
<title>
1
<section ids="id2" names="2">
<title>
2
<system_message level="2" line="5" source="test data" type="WARNING">
<paragraph>
Title underline too short.
<literal_block xml:space="preserve">
2
========
"""],
[ur"""
+-----------------------+
| * :1 |
| * 2 |
+-----------------------+
| \* 1 |
| * 2 |
+-----------------------+
""",
u"""\
<document source="test data">
<table>
<tgroup cols="1">
<colspec colwidth="23">
<tbody>
<row>
<entry>
<bullet_list bullet="*">
<list_item>
<paragraph>
:1
<list_item>
<paragraph>
2
<row>
<entry>
<paragraph>
* 1
* 2
"""],
[u"""\
Complex spanning pattern (no edge knows all rows/cols):
+--------+---------------------+
| | |
| +--------------+------+
| | | |
+--------+--------------+ |
| | |
+-----------------------+------+
""",
u"""\
<document source="test data">
<paragraph>
Complex spanning pattern (no edge knows all rows/cols):
<table>
<tgroup cols="3">
<colspec colwidth="8">
<colspec colwidth="14">
<colspec colwidth="6">
<tbody>
<row>
<entry morerows="1">
<paragraph>
<entry morecols="1">
<paragraph>
<row>
<entry>
<paragraph>
<entry morerows="1">
<paragraph>
<row>
<entry morecols="1">
<paragraph>
"""],
[u"""\
========= =========
1 2
========= =========
======== =========
1 2
======== =========
""",
u"""\
<document source="test data">
<table>
<tgroup cols="2">
<colspec colwidth="9">
<colspec colwidth="9">
<tbody>
<row>
<entry>
<paragraph>
1
<entry>
<paragraph>
2
<system_message level="3" line="5" source="test data" type="ERROR">
<paragraph>
Malformed table.
Text in column margin at line offset 1.
<literal_block xml:space="preserve">
======== =========
1 2
======== =========
"""],
[u"""\
Some ambiguous-width characters:
= ===================================
copyright sign
registered sign
left pointing guillemet
right pointing guillemet
en-dash
em-dash
single turned comma quotation mark
single comma quotation mark
low single comma quotation mark
double turned comma quotation mark
double comma quotation mark
low double comma quotation mark
dagger
double dagger
ellipsis
trade mark sign
left-right double arrow
= ===================================
""",
b("""\
<document source="test data">
<paragraph>
Some ambiguous-width characters:
<table>
<tgroup cols="2">
<colspec colwidth="1">
<colspec colwidth="35">
<tbody>
<row>
<entry>
<paragraph>
\xa9
<entry>
<paragraph>
copyright sign
<row>
<entry>
<paragraph>
\xae
<entry>
<paragraph>
registered sign
<row>
<entry>
<paragraph>
\xab
<entry>
<paragraph>
left pointing guillemet
<row>
<entry>
<paragraph>
\xbb
<entry>
<paragraph>
right pointing guillemet
<row>
<entry>
<paragraph>
\\u2013
<entry>
<paragraph>
en-dash
<row>
<entry>
<paragraph>
\\u2014
<entry>
<paragraph>
em-dash
<row>
<entry>
<paragraph>
\\u2018
<entry>
<paragraph>
single turned comma quotation mark
<row>
<entry>
<paragraph>
\\u2019
<entry>
<paragraph>
single comma quotation mark
<row>
<entry>
<paragraph>
\\u201a
<entry>
<paragraph>
low single comma quotation mark
<row>
<entry>
<paragraph>
\\u201c
<entry>
<paragraph>
double turned comma quotation mark
<row>
<entry>
<paragraph>
\\u201d
<entry>
<paragraph>
double comma quotation mark
<row>
<entry>
<paragraph>
\\u201e
<entry>
<paragraph>
low double comma quotation mark
<row>
<entry>
<paragraph>
\\u2020
<entry>
<paragraph>
dagger
<row>
<entry>
<paragraph>
\\u2021
<entry>
<paragraph>
double dagger
<row>
<entry>
<paragraph>
\\u2026
<entry>
<paragraph>
ellipsis
<row>
<entry>
<paragraph>
\\u2122
<entry>
<paragraph>
trade mark sign
<row>
<entry>
<paragraph>
\\u21d4
<entry>
<paragraph>
left-right double arrow
""").decode('raw_unicode_escape')],
]
'''
[u"""\
""",
u"""\
"""],
'''
if __name__ == '__main__':
import unittest
unittest.main(defaultTest='suite')
|