Skip to content

Commit

Permalink
Add missing node type of DocString
Browse files Browse the repository at this point in the history
  • Loading branch information
ducminh-phan committed Apr 8, 2019
1 parent 96a1723 commit 53f80eb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions main/ast_node/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .background import Background
from .comment import Comment
from .data_table import DataTable
from .doc_string import DocString
from .examples import Examples
from .feature import Feature
from .gherkin_document import GherkinDocument
Expand All @@ -18,6 +19,7 @@
Background,
Comment,
DataTable,
DocString,
Examples,
Feature,
GherkinDocument,
Expand Down
13 changes: 13 additions & 0 deletions main/ast_node/doc_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from attr import attrib

from ._base import prepare
from .location import Location


@prepare
class DocString:
location: Location = attrib(cmp=False, repr=False)
content: str

def __iter__(self):
yield self
5 changes: 3 additions & 2 deletions main/ast_node/step.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import Optional
from typing import Optional, Union

from attr import attrib

from ._base import prepare
from .data_table import DataTable
from .doc_string import DocString
from .location import Location


Expand All @@ -12,7 +13,7 @@ class Step:
location: Location = attrib(cmp=False, repr=False)
keyword: str
text: str
argument: Optional[DataTable] = None
argument: Optional[Union[DataTable, DocString]] = None

def __iter__(self):
yield self
Expand Down
14 changes: 14 additions & 0 deletions main/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Background,
Comment,
DataTable,
DocString,
Examples,
Feature,
GherkinDocument,
Expand Down Expand Up @@ -167,6 +168,15 @@ def normalize_comment(comment: Comment) -> str:
return "# " + comment_text


def generate_doc_string_lines(docstring: DocString) -> List[str]:
raw_lines = docstring.content.splitlines()
raw_lines = ['"""'] + raw_lines + ['"""']

indent_level = INDENT_LEVEL_MAP[Step]

return [f"{INDENT * indent_level}{line}" for line in raw_lines]


ContextMap = Dict[Union[Comment, Tag, TableRow], Any]
Lines = Iterator[str]

Expand Down Expand Up @@ -279,3 +289,7 @@ def visit_comment(self, comment: Comment) -> Lines:

comment_text = normalize_comment(comment)
yield f"{indent}{comment_text}"

@staticmethod
def visit_doc_string(docstring: DocString):
return generate_doc_string_lines(docstring)

0 comments on commit 53f80eb

Please sign in to comment.