(In progress) Add support for SRC code blocks.

- Add tests for blocks.
- Add Regexps.
- Correctly handle Headlines with split contents.
This commit is contained in:
Sergio Martínez Portela 2020-12-04 00:04:56 +01:00
parent 1c0ecbf8c6
commit a5bfeadfeb
3 changed files with 150 additions and 31 deletions

34
tests/04-code.org Normal file
View file

@ -0,0 +1,34 @@
#+TITLE: 04-Code
#+DESCRIPTION: Simple org file
#+TODO: TODO(t) PAUSED(p) | DONE(d)
* First Item
:PROPERTIES:
:ID: 04-code-first-item-id
:CREATED: [2020-01-01 Wed 01:01]
:END:
#+BEGIN_SRC shell
echo "This is a test"
exit 0 # Exit successfully
#+END_SRC
#+RESULTS:
: This is a test
* Second item
:PROPERTIES:
:ID: 04-code-second-item-id
:CREATED: [2020-01-01 Wed 01:01]
:END:
#+BEGIN_SRC shell :results drawer
echo "This is another test"
exit 0 # Comment
#+END_SRC
#+RESULTS:
:results:
This is another test
:end:

View file

@ -5,19 +5,8 @@ from datetime import datetime as DT
from org_dom import dumps, load, loads
from utils.dom_assertions import (
BOLD,
CODE,
HL,
ITALIC,
SPAN,
STRIKE,
UNDERLINED,
VERBATIM,
WEB_LINK,
Dom,
Tokens,
)
from utils.dom_assertions import (BOLD, CODE, HL, ITALIC, SPAN, STRIKE,
UNDERLINED, VERBATIM, WEB_LINK, Dom, Tokens)
DIR = os.path.dirname(os.path.abspath(__file__))
@ -255,3 +244,30 @@ class TestSerde(unittest.TestCase):
)
ex.assert_matches(self, doc)
def test_mimic_write_file_04(self):
with open(os.path.join(DIR, "04-code.org")) as f:
orig = f.read()
doc = loads(orig)
self.assertEqual(dumps(doc), orig)
def test_code_file_04(self):
with open(os.path.join(DIR, "04-code.org")) as f:
doc = load(f)
snippets = list(doc.get_code_snippets())
self.assertEqual(len(snippets), 2)
self.assertEqual(
snippets[0].content,
'echo "This is a test"\n' + "exit 0 # Exit successfully",
)
self.assertEqual(
snippets[0].result,
"This is a test",
)
self.assertEqual(
snippets[1].content, 'echo "This is another test"\n' + "exit 0 # Comment"
)
self.assertEqual(snippets[1].result, "This is another test")