2024-09-11 11:14:03 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
|
import sys, re, os, enum, itertools
|
|
|
|
|
from functools import partial, partialmethod
|
|
|
|
|
from time import sleep
|
|
|
|
|
from operator import itemgetter
|
|
|
|
|
from defl import log, cl, Path, Undefined, Null, Assert, Time, Obj, Dunder
|
|
|
|
|
from defl import CLIError
|
|
|
|
|
from defl._typing_ import *
|
|
|
|
|
import defl
|
2025-03-09 09:17:53 -04:00
|
|
|
from defl._configFormats_ import ConfigInput, ConfigOutput
|
2024-09-11 11:14:03 -04:00
|
|
|
from defl.markdown_ import *
|
|
|
|
|
from defl.testing_ import Test, Tester, TestState
|
|
|
|
|
|
|
|
|
|
tester = Tester(name=__file__)
|
2025-03-09 09:17:53 -04:00
|
|
|
markdownTestData = defl.Dath(__file__).parent / 'markdown.txt'
|
|
|
|
|
markdownTestData = markdownTestData.readText()
|
2024-09-11 11:14:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def genny(text):
|
|
|
|
|
yield defl.formatMultiLineStr(text, dedent=True, filt=True, join=False)
|
|
|
|
|
confIn = ConfigInput(text).markdown()
|
|
|
|
|
# print(defl.jdumps(confIn, colorize=True))
|
|
|
|
|
yield confIn
|
|
|
|
|
confOut = ConfigOutput(confIn).markdown()
|
|
|
|
|
# print(confOut)
|
|
|
|
|
assert isinstance(confOut, str)
|
|
|
|
|
yield defl.formatMultiLineStr(confOut, dedent=True, filt=True, join=False)
|
|
|
|
|
|
2025-03-09 09:17:53 -04:00
|
|
|
|
|
|
|
|
# @tester.add() # TODO
|
2024-09-11 11:14:03 -04:00
|
|
|
def mdList():
|
2025-03-09 09:17:53 -04:00
|
|
|
gen = genny("""
|
2024-09-11 11:14:03 -04:00
|
|
|
- 1
|
|
|
|
|
- 2
|
|
|
|
|
- 3
|
|
|
|
|
- 4
|
2025-03-09 09:17:53 -04:00
|
|
|
""")
|
2024-09-11 11:14:03 -04:00
|
|
|
dedent = next(gen)
|
2025-03-09 09:17:53 -04:00
|
|
|
outp = ['- 1', ' - 2', ' - 3', ' - 4']
|
2024-09-11 11:14:03 -04:00
|
|
|
Assert(dedent) == outp
|
|
|
|
|
|
2025-03-09 09:17:53 -04:00
|
|
|
Assert(next(gen)) == [
|
|
|
|
|
{
|
|
|
|
|
'typ': 'list',
|
|
|
|
|
'lines': ['1'],
|
|
|
|
|
'children': [
|
|
|
|
|
{'typ': 'list', 'lines': ['2']},
|
|
|
|
|
{'typ': 'list', 'lines': ['3']},
|
|
|
|
|
{'typ': 'list', 'lines': ['4']},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
]
|
2024-09-11 11:14:03 -04:00
|
|
|
|
|
|
|
|
Assert(next(gen)) == a
|
|
|
|
|
|
2025-03-09 09:17:53 -04:00
|
|
|
|
|
|
|
|
# @tester.add() # TODO
|
2024-09-11 11:14:03 -04:00
|
|
|
def mdTable():
|
|
|
|
|
gen = genny(
|
2025-03-09 09:17:53 -04:00
|
|
|
"""
|
2024-09-11 11:14:03 -04:00
|
|
|
| a | bb |ccc |
|
|
|
|
|
| ------ | -----------|---|
|
|
|
|
|
| 1| 444| aaa|
|
|
|
|
|
| 22|55 |bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|
|
|
|
|
|
| 333|6|c|
|
2025-03-09 09:17:53 -04:00
|
|
|
"""
|
2024-09-11 11:14:03 -04:00
|
|
|
)
|
|
|
|
|
dedent = next(gen)
|
|
|
|
|
outp = [
|
2025-03-09 09:17:53 -04:00
|
|
|
'| a | bb |ccc |',
|
|
|
|
|
'| ------ | -----------|---|',
|
|
|
|
|
'| 1| 444| aaa|',
|
|
|
|
|
'| 22|55 |bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb|',
|
|
|
|
|
'| 333|6|c|',
|
2024-09-11 11:14:03 -04:00
|
|
|
]
|
|
|
|
|
Assert(dedent) == outp
|
|
|
|
|
|
2025-03-09 09:17:53 -04:00
|
|
|
Assert(next(gen)) == [
|
|
|
|
|
{
|
|
|
|
|
'typ': 'table',
|
|
|
|
|
'lines': [
|
|
|
|
|
{'a': '1', 'bb': '444', 'ccc': 'aaa'},
|
|
|
|
|
{'a': '22', 'bb': '55', 'ccc': 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'},
|
|
|
|
|
{'a': '333', 'bb': '6', 'ccc': 'c'},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
]
|
2024-09-11 11:14:03 -04:00
|
|
|
|
|
|
|
|
Assert(next(gen)) == outp
|
|
|
|
|
|
2025-03-09 09:17:53 -04:00
|
|
|
|
|
|
|
|
@tester.add()
|
|
|
|
|
def csv():
|
|
|
|
|
a = ['a,b,c', '1,2,3', '4,5,6']
|
|
|
|
|
res = ConfigInput.Csv(a)
|
|
|
|
|
Assert(res) == [{'a': '1', 'b': '2', 'c': '3'}, {'a': '4', 'b': '5', 'c': '6'}]
|
|
|
|
|
|
|
|
|
|
|
2024-09-11 11:14:03 -04:00
|
|
|
log.info(tester.run())
|
|
|
|
|
tester.exitWithStatus()
|