Support 'a' (absolute) justification. Let EvForm accept EvCells as mappings. Resolve #2762
This commit is contained in:
parent
158b9e2e12
commit
9709ecbc57
5 changed files with 207 additions and 51 deletions
|
|
@ -2,6 +2,8 @@
|
|||
Unit tests for the EvForm text form generator
|
||||
|
||||
"""
|
||||
from unittest import skip
|
||||
|
||||
from django.test import TestCase
|
||||
from evennia.utils import ansi, evform, evtable
|
||||
|
||||
|
|
@ -261,3 +263,137 @@ class TestEvFormParallelTables(TestCase):
|
|||
tables={"2": self.table2, "3": self.table3},
|
||||
)
|
||||
self.assertEqual(ansi.strip_ansi(str(form).strip()), _EXPECTED.strip())
|
||||
|
||||
|
||||
class TestEvFormErrors(TestCase):
|
||||
"""
|
||||
Tests of EvForm errors found for v1.0-dev
|
||||
|
||||
"""
|
||||
|
||||
maxDiff = None
|
||||
|
||||
def _form(self, form, **kwargs):
|
||||
|
||||
formdict = {
|
||||
"form": form,
|
||||
"formchar": "x",
|
||||
"tablechar": "c",
|
||||
}
|
||||
form = evform.EvForm(formdict, **kwargs)
|
||||
# this is necessary since editors/black tend to strip lines spaces
|
||||
# from the end of lines for the comparison strings.
|
||||
form = ansi.strip_ansi(str(form))
|
||||
form = "\n".join(line.rstrip() for line in form.split("\n"))
|
||||
|
||||
return form
|
||||
|
||||
def _validate(self, expected, result):
|
||||
"""easier debug"""
|
||||
err = f"\n{'expected':-^60}\n{expected}\n{'result':-^60}\n{result}\n{'':-^60}"
|
||||
self.assertEqual(expected.lstrip(), result.lstrip(), err)
|
||||
|
||||
@skip("Pending rebuild of markup")
|
||||
def test_2757(self):
|
||||
"""
|
||||
Testing https://github.com/evennia/evennia/issues/2757
|
||||
|
||||
Using || ansi escaping messes with rectangle width
|
||||
|
||||
This should be delayed until refactor of markup.
|
||||
|
||||
"""
|
||||
form = """
|
||||
xxxxxx
|
||||
||---| xx1xxx
|
||||
xxxxxx
|
||||
"""
|
||||
cell_mapping = {1: "Monty"}
|
||||
|
||||
expected = """
|
||||
|
||||
|---| Monty
|
||||
|
||||
"""
|
||||
self._validate(expected, self._form(form, cells=cell_mapping))
|
||||
|
||||
def test_2759(self):
|
||||
"""
|
||||
Testing https://github.com/evennia/evennia/issues/2759
|
||||
|
||||
Leading space in EvCell is stripped
|
||||
|
||||
"""
|
||||
# testing the underlying problem
|
||||
|
||||
cell = evtable.EvCell(" Hi", align="l")
|
||||
self.assertEqual(cell._align(cell.data), [ansi.ANSIString("Hi ")])
|
||||
|
||||
cell = evtable.EvCell(" Hi", align="l")
|
||||
self.assertEqual(cell._align(cell.data), [ansi.ANSIString("Hi ")])
|
||||
|
||||
cell = evtable.EvCell(" Hi", align="a")
|
||||
self.assertEqual(cell._align(cell.data), [ansi.ANSIString(" Hi")])
|
||||
|
||||
form = """
|
||||
.-----------------------.
|
||||
| Test Form |
|
||||
| |
|
||||
|.xxxxx .xxxxxxxxxxxxx |
|
||||
|.xx1xx .xxxxxx2xxxxxx |
|
||||
|.xxxxx .xxxxxxxxxxxxx |
|
||||
| .xxxxxxxxxxxxx |
|
||||
| |
|
||||
-----------------------
|
||||
"""
|
||||
|
||||
cell1 = " Hi."
|
||||
cell2 = " Single space\n Double\n Single again"
|
||||
|
||||
cell_mapping = {1: cell1, 2: cell2}
|
||||
|
||||
# default is left-aligned cells
|
||||
expected = """
|
||||
.-----------------------.
|
||||
| Test Form |
|
||||
| |
|
||||
|.Hi. .Single space |
|
||||
|. .Double |
|
||||
|. .Single again |
|
||||
| . |
|
||||
| |
|
||||
-----------------------
|
||||
"""
|
||||
self._validate(expected, self._form(form, cells=cell_mapping))
|
||||
|
||||
# test with absolute alignment (pass cells directly)
|
||||
cell_mapping = {
|
||||
1: evtable.EvCell(cell1, align="a", valign="t"),
|
||||
2: evtable.EvCell(cell2, align="a", valign="t"),
|
||||
}
|
||||
|
||||
expected = """
|
||||
.-----------------------.
|
||||
| Test Form |
|
||||
| |
|
||||
|. Hi. . Single space |
|
||||
|. . Double |
|
||||
|. . Single again |
|
||||
| . |
|
||||
| |
|
||||
-----------------------
|
||||
"""
|
||||
self._validate(expected, self._form(form, cells=cell_mapping))
|
||||
|
||||
def test_2763(self):
|
||||
"""
|
||||
Testing https://github.com/evennia/evennia/issues/2763
|
||||
|
||||
Duplication of ANSI sequences in evform
|
||||
"""
|
||||
|
||||
formdict = {"form": "|R A |n _ x1xx"}
|
||||
cell_mapping = {1: "test"}
|
||||
expected = f"{ansi.ANSI_RED} A {ansi.ANSI_NORMAL} _ test"
|
||||
form = evform.EvForm(formdict, cells=cell_mapping)
|
||||
self._validate(expected, str(form))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue