def test_mult(): s = "1024x768" rule = wg.context["mult"] out, i = rule.accept(s, 4, wg.context) assert out == compat.unichr(215) s = "Up to 3x faster" rule = wg.context["mult"] out, i = rule.accept(s, 7, wg.context) assert out == compat.unichr(215) s = "Up to 3x faster" rule = wg.context["para"] out, i = rule.accept(s, 0, wg.context) assert out == {"type": "para", "indent": 0, "text": [u"Up to 3", u"\u00d7", u" faster"]} from bookish.grammars.wiki import mult, para from bookish.parser import condition_string from bookish.parser.bootstrap import bootstrap_context s = condition_string(s) ctx = bootstrap_context() out, i = mult(s, 7, ctx) assert out is not p.Miss assert out == compat.unichr(215) out, i = para(s, 0, ctx) assert out == {"type": "para", "indent": 0, "text": [u"Up to 3", u"\u00d7", u" faster"]}
def test_escape(): assert bs.escchar.test2("\\n") == ("\n", 2) assert bs.escchar.test2("\\r") == ("\r", 2) assert bs.escchar.test2("\\t") == ("\t", 2) assert bs.escchar.test2("\\b") == ("\b", 2) assert bs.escchar.test2("\\f") == ("\f", 2) assert bs.escchar.test2('\\"') == ('"', 2) assert bs.escchar.test2("\\'") == ("'", 2) assert bs.escchar.test2("\\xFF", context=_ctx()) == (unichr(255), 4) assert bs.escchar.test2("\\\\") == ("\\", 2) assert bs.escchar.test("\\") is p.Miss
def test_entity(): sigma = compat.unichr(963) rule = wg.context["entity"] out, i = rule.accept("σ", 0, wg.context) assert out == sigma rule = wg.context["entity"] out, i = rule.accept("σ", 0, wg.context) assert out == sigma rule = wg.context["entity"] out, i = rule.accept("σ", 0, wg.context) assert out == sigma
def test_escape(): rule = _boot_parse(r""" escchar = '\\' ('n' -> "\n" | 'r' -> "\r" | 't' -> "\t" | 'b' -> "\b" | 'f' -> "\f" | '"' -> '"' | '\'' -> "'" | 'x' <hexdigit hexdigit>:d -> compat.unichr(int(d, 16)) | '\\' -> "\\") """) assert _test_rule(rule, "\\n") == "\n" assert _test_rule(rule, "\\r") == "\r" assert _test_rule(rule, "\\t") == "\t" assert _test_rule(rule, "\\b") == "\b" assert _test_rule(rule, "\\f") == "\f" assert _test_rule(rule, '\\"') == '"' assert _test_rule(rule, "\\'") == "'" assert _test_rule(rule, "\\xFF") == unichr(255) assert _test_rule(rule, "\\\\") == "\\" assert _test_rule(rule, "\\") is p.Miss
def test_embedded_entity(): rule = wg.context["blocks"] s = "(σ<sup>2</sup>)" out, i = rule.accept(s, 0, wg.context) assert out is not p.Miss assert out["text"] == ["(", compat.unichr(963), {"type": "xml", "tag": "sup", "attrs": {}, "text": ["2"]}, ")"]
from __future__ import print_function import re import textwrap try: from html.parser import HTMLParser except ImportError: from HTMLParser import HTMLParser from bookish.compat import StringIO from bookish.compat import string_type from bookish.compat import unichr _charmap = [ (unichr(8221), '"'), (unichr(8220), '"'), (unichr(8217), "'"), (unichr(8212), "---"), (unichr(8211), "--"), (unichr(8592), "<-"), (unichr(8594), "->"), (unichr(8804), "<="), (unichr(8805), ">="), (unichr(8660), "<=>"), (unichr(188), "1/4"), (unichr(189), "1/2"), (unichr(190), "3/4"),