Skip to content

Commit

Permalink
new: test: added a test for issue #31
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele Tessaro committed Aug 26, 2019
1 parent 5481eab commit 254bc0c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
16 changes: 13 additions & 3 deletions test/markdown_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def __init__(self, delimiter='```uml'):
self._end_delimiter = '::end-uml::' if delimiter == '::uml::' else re.sub(r'\w', '', delimiter)
self._buffer = ""
self._extended_syntax = False
self._indent = 0
self._reset_diagram()

def _reset_diagram(self):
Expand All @@ -29,8 +30,8 @@ def _emit_diagram(self):
if self._diagram_buffer:
delim = re.sub(r'(\W{3,})(\w+)', r'\1{\2', self._delimiter) if self._extended_syntax else self._delimiter
args = self._format + self._class + self._alt + self._title + self._width + self._height
self._buffer += delim+args+('}' if self._extended_syntax else '')
self._buffer += "\n"+self._diagram_buffer+"\n"+self._end_delimiter+"\n"
self._buffer += (' '*self._indent)+delim+args+('}' if self._extended_syntax else '')
self._buffer += "\n"+(' '*self._indent)+self._diagram_buffer+"\n"+(' '*self._indent)+self._end_delimiter+"\n"

self._reset_diagram()

Expand Down Expand Up @@ -108,7 +109,7 @@ def text(self, txt):
self._buffer += txt
return self

def diagram(self, diag):
def diagram(self, diag, indent=0):
"""
Define a new diagram.
:param diag: Diagram source
Expand All @@ -118,6 +119,15 @@ def diagram(self, diag):
self._diagram_buffer = diag
return self

def indent(self, value):
"""
Indent next block of text with the specified number of spaces.
:param value: how many spaces to indent
:return: The object itself
"""
self._indent = value
return self

def build(self):
"""
Return the markdown source build with the previous commands.
Expand Down
2 changes: 1 addition & 1 deletion test/plantuml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
PLANTUML_VER="1.2018.2"
[ -f "/tmp/plantuml.${PLANTUML_VER}.jar" ] || wget -q "http://sourceforge.net/projects/plantuml/files/plantuml.${PLANTUML_VER}.jar/download" -O /tmp/plantuml.${PLANTUML_VER}.jar
java -jar /tmp/plantuml.${PLANTUML_VER}.jar ${@}
java -Djava.awt.headless=true -jar /tmp/plantuml.${PLANTUML_VER}.jar ${@}
18 changes: 17 additions & 1 deletion test/test_plantuml.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,24 @@ def test_other_fenced_code(self):
self.assertEqual(self._stripImageData(self._load_file('code_and_diag.html')),
self._stripImageData(self.md.convert(text)))

def test_unicode_chars(self):
def test_indented_fenced_code(self):
"""
Test handling of indented fenced code
"""
text = self.text_builder.text('* list item\n\n') \
.indent(4) \
.diagram('A --> B') \
.build()
self.assertEqual('''<ul>
<li>
<p>list item</p>
<p><img alt="uml diagram" class="uml" src="data:image/png;base64,%s" title="" /></p>
</li>
</ul>''' % self.FAKE_IMAGE,
self._stripImageData(self.md.convert(text)))

def test_unicode_chars(self):
"""indented_code
Test that svg_inline handles correctly utf8 characters
"""
# Example diagram from issue 21
Expand Down

0 comments on commit 254bc0c

Please sign in to comment.