34 lines
1.6 KiB
Python
34 lines
1.6 KiB
Python
"""Complete tutorial mapping coverage and engine layout regression."""
|
|
import json
|
|
from pathlib import Path
|
|
import unittest
|
|
from test_cjk_layout import layout
|
|
|
|
|
|
class CompleteTutorialTests(unittest.TestCase):
|
|
def test_remaining_pages_fit_without_orphan_punctuation(self):
|
|
mapping = json.loads(Path(__file__).with_name('tutorial_cn.json').read_text(encoding='utf-8'))
|
|
for original, translated in list(mapping.items())[12:]:
|
|
for width in (360, 400, 480):
|
|
with self.subTest(original=original[:40], width=width):
|
|
lines, _ = layout(translated, width=width, alignment=2)
|
|
self.assertTrue(lines)
|
|
self.assertLessEqual(lines[-1][2] + 12, 140)
|
|
for raw, x, y in lines:
|
|
text = raw.decode('gb2312')
|
|
self.assertNotIn(text[0], ',。;:、!?)”')
|
|
pixels = sum(5 if c == ' ' else 8 if ord(c) < 128 else 12 for c in text)
|
|
self.assertEqual(x, width // 2 - pixels // 2)
|
|
|
|
def test_translations_cover_core_controls_and_constraints(self):
|
|
mapping = json.loads(Path(__file__).with_name('tutorial_cn.json').read_text(encoding='utf-8'))
|
|
text = '\n'.join(mapping.values())
|
|
for term in ['PgUp', 'PgDn', 'Tab', '空格', '50%', 'E 键', 'F12', 'Alt', '0%', 'P 键', 'Esc']:
|
|
self.assertIn(term, text)
|
|
self.assertEqual(sum(k.startswith('\fTo use a charged spell') for k in mapping), 1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|
|
|