mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Testing framework for new entity replacement code
This commit is contained in:
parent
aa3b09e77c
commit
a46e9ef881
2
src/calibre/ebooks/html_entities.h
generated
2
src/calibre/ebooks/html_entities.h
generated
@ -1,5 +1,5 @@
|
||||
/* ANSI-C code produced by gperf version 3.1 */
|
||||
/* Command-line: gperf -t --readonly --includes */
|
||||
/* Command-line: gperf --struct-type --readonly --includes */
|
||||
/* Computed positions: -k'1-7,10,12,$' */
|
||||
|
||||
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
|
||||
|
@ -2135,13 +2135,26 @@ html5_entities = {
|
||||
}
|
||||
|
||||
|
||||
def find_tests():
|
||||
import unittest
|
||||
class TestHTMLEntityReplacement(unittest.TestCase):
|
||||
def test_html_entity_replacement(self):
|
||||
from calibre_extensions.fast_html_entities import replace_entities
|
||||
def t(inp, exp):
|
||||
self.assertEqual(exp, replace_entities(inp), f'Failed for input: {inp!r}')
|
||||
t('', '')
|
||||
t('a', 'a')
|
||||
|
||||
return unittest.defaultTestLoader.loadTestsFromTestCase(TestHTMLEntityReplacement)
|
||||
|
||||
|
||||
def generate_entity_lists():
|
||||
import re
|
||||
from html import entities as e
|
||||
entities = {k.rstrip(';'): e.name2codepoint[k] for k in e.name2codepoint}
|
||||
entities.update({k.rstrip(';'): e.html5[k] for k in e.html5})
|
||||
# common misspelled entity names
|
||||
for k, v in {'apos': "'", 'squot': "'", 'hellips': entities['hellip']}.items():
|
||||
for k, v in {'squot': "'", 'hellips': entities['hellip']}.items():
|
||||
if k not in entities:
|
||||
entities[k] = v
|
||||
lines = []
|
||||
|
@ -269,6 +269,8 @@ def find_tests(which_tests=None, exclude_tests=None):
|
||||
a(find_tests())
|
||||
from calibre.gui2.viewer.annotations import find_tests
|
||||
a(find_tests())
|
||||
from calibre.ebooks.html_entities import find_tests
|
||||
a(find_tests())
|
||||
if ok('misc'):
|
||||
from calibre.ebooks.html.input import find_tests
|
||||
a(find_tests())
|
||||
|
Loading…
x
Reference in New Issue
Block a user