Skip to content

Commit

Permalink
fix remove_indentation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanderhoof committed Dec 11, 2022
1 parent 3f83a6f commit 93ee4a3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 1.0.6

- Fix: removing indentation bug

# 1.0.6

- Fix: (#26) bug in note empty line stripping, thanks @Jaschenn for reporting
- New: get_references_for_sql table method

Expand Down
3 changes: 3 additions & 0 deletions pydbml/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def strip_empty_lines(source: str) -> str:


def remove_indentation(source: str) -> str:
if not source:
return source

pattern = re.compile(r'^\s*')

lines = source.split('\n')
Expand Down
15 changes: 13 additions & 2 deletions test/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest import TestCase

from pydbml.classes import Note
from pydbml.tools import comment_to_dbml
from pydbml.tools import comment_to_dbml, remove_indentation
from pydbml.tools import comment_to_sql
from pydbml.tools import indent
from pydbml.tools import note_option_to_dbml
Expand Down Expand Up @@ -98,4 +98,15 @@ def test_one_empty_line(self) -> None:
def test_end(self) -> None:
stripped = ' line1\n\n line2'
source = f'\n{stripped}\n '
self.assertEqual(strip_empty_lines(source), stripped)
self.assertEqual(strip_empty_lines(source), stripped)


class TestRemoveIndentation(TestCase):
def test_empty(self) -> None:
source = ''
self.assertEqual(remove_indentation(source), source)

def test_not_empty(self) -> None:
source = ' line1\n line2'
expected = 'line1\n line2'
self.assertEqual(remove_indentation(source), expected)

0 comments on commit 93ee4a3

Please sign in to comment.