Exemplo n.º 1
0
 def test_section_content_indent(self):
     paragraph_item_formatter = paragraph_item.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                                                         paragraph_item.Wrapper(page_width=100),
                                                         num_item_separator_lines=0)
     content_indent = '  '
     formatter = sut.Formatter(paragraph_item_formatter,
                               section_content_indent_str=content_indent,
                               separation=sut.Separation(between_sections=1,
                                                         between_header_and_content=2,
                                                         between_initial_paragraphs_and_sub_sections=3))
     header = text('Section Header')
     contents = SectionContents([single_text_para('initial paragraph')],
                                [Section(text('Sub Section Header'),
                                         empty_section_contents())])
     cases = [
         ('section', Section(header, contents)),
         ('article', Article(header, ArticleContents([], contents))),
     ]
     for test_case_name, section_item in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(section_item)
             # ASSERT #
             self.assertEqual(['Section Header',
                               BLANK_LINE,
                               BLANK_LINE,
                               content_indent + 'initial paragraph',
                               BLANK_LINE,
                               BLANK_LINE,
                               BLANK_LINE,
                               content_indent + 'Sub Section Header',
                               ],
                              actual)
Exemplo n.º 2
0
 def test_empty_section_item(self):
     # ARRANGE #
     paragraph_item_formatter = paragraph_item.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                                                         paragraph_item.Wrapper(page_width=100),
                                                         num_item_separator_lines=0)
     formatter = sut.Formatter(paragraph_item_formatter,
                               sut.Separation(between_sections=1,
                                              between_header_and_content=2,
                                              between_initial_paragraphs_and_sub_sections=3))
     header_string = 'Section Header'
     cases = [
         ('section', empty_section(header_string)),
         ('section with target', Section(text(header_string),
                                         empty_section_contents(),
                                         target=CrossReferenceTarget())),
         ('article', empty_article(header_string)),
         ('article with target', Article(text(header_string),
                                         empty_article_contents(),
                                         target=CrossReferenceTarget())),
     ]
     for test_case_name, section_item in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(section_item)
             # ASSERT #
             self.assertEqual([header_string],
                              actual)
Exemplo n.º 3
0
 def test_empty_section_item(self):
     # ARRANGE #
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=100),
         num_item_separator_lines=0)
     formatter = sut.Formatter(
         paragraph_item_formatter,
         sut.Separation(between_sections=1,
                        between_header_and_content=2,
                        between_initial_paragraphs_and_sub_sections=3))
     header_string = 'Section Header'
     cases = [
         ('section', empty_section(header_string)),
         ('section with target',
          Section(text(header_string),
                  empty_section_contents(),
                  target=CrossReferenceTarget())),
         ('article', empty_article(header_string)),
         ('article with target',
          Article(text(header_string),
                  empty_article_contents(),
                  target=CrossReferenceTarget())),
     ]
     for test_case_name, section_item in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(section_item)
             # ASSERT #
             self.assertEqual([header_string], actual)
Exemplo n.º 4
0
    def test_with_fixed_root_target(self):
        # ARRANGE #

        root_header = StringText('root header')
        sub_header = StringText('sub header')
        sub_local_target_name = 'should not be used'

        fixed_target = CustomCrossReferenceTargetTestImpl('the fixed root target')

        default_target = CustomCrossReferenceTargetTestImpl('default target component')

        target_factory = ConstantTargetInfoFactoryTestImpl(default_target)

        unadjusted_object = sut.hierarchy(root_header,
                                          paragraphs.empty(),
                                          [sut.child(sub_local_target_name,
                                                     sut.leaf(sub_header.value,
                                                              section_contents(doc.empty_section_contents())))
                                           ]
                                          )
        adjusted_object = sut.with_fixed_root_target(fixed_target,
                                                     unadjusted_object)

        # EXPECTATION #

        expected_root_target_info = TargetInfo(root_header,
                                               fixed_target)

        expected_sub_target_info = TargetInfo(sub_header,
                                              default_target)

        target_info_node_assertion = equals_target_info_node(
            TargetInfoNode(expected_root_target_info,
                           [target_info_leaf(expected_sub_target_info)]),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(fixed_target),
            header=asrt_para.equals_text(expected_root_target_info.presentation_text),
            contents=section_contents_matches(
                initial_paragraphs=asrt.is_empty_sequence,
                sections=asrt.matches_sequence([
                    section_matches(
                        target=equals_custom_cross_ref_test_impl(default_target),
                        header=asrt_para.equals_text(sub_header),
                        contents=section_contents_matches(
                            initial_paragraphs=asrt.is_empty_sequence,
                            sections=asrt.is_empty_sequence
                        )
                    )
                ])
            ))

        # ACT & ASSERT #

        self._act_and_assert(adjusted_object,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Exemplo n.º 5
0
    def test_hierarchy_with_sub_sections(self):
        # ARRANGE #

        target_factory = TargetInfoFactoryTestImpl(['target_component'])
        expected_section_contents_object1 = doc.empty_section_contents()
        expected_section_contents_object2 = docs.section_contents(docs.paras('testing testing'))
        expected_root_initial_para = docs.para('root initial paras')
        expected_root_initial_paras = [expected_root_initial_para]

        root_header = StringText('root header')

        sub_section_header_1 = 'sub1'
        sub_section_header_2 = 'sub2'
        sub_section_local_target_1 = 'sub-target1'
        sub_section_local_target_2 = 'sub-target2'

        object_to_test = sut.hierarchy(
            root_header,
            paragraphs.constant(expected_root_initial_paras),
            [sut.child(sub_section_local_target_1,
                       sut.leaf(sub_section_header_1,
                                section_contents(expected_section_contents_object1))),
             sut.child(sub_section_local_target_2,
                       sut.leaf(sub_section_header_2,
                                section_contents(expected_section_contents_object2)))
             ])
        # EXPECTATION #
        expected_root_target_info = target_factory.root(root_header)

        sub1_target = target_factory.sub(sub_section_header_1, sub_section_local_target_1)
        sub2_target = target_factory.sub(sub_section_header_2, sub_section_local_target_2)
        target_info_node_assertion = equals_target_info_node(
            TargetInfoNode(expected_root_target_info,
                           [
                               target_info_leaf(sub1_target),
                               target_info_leaf(sub2_target),
                           ]),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion2 = section_matches(
            target=equals_custom_cross_ref_test_impl(expected_root_target_info.target),
            header=asrt_para.equals_text(expected_root_target_info.presentation_text),
            contents=section_contents_matches(
                initial_paragraphs=asrt.matches_sequence([asrt.Is(expected_root_initial_para)]),
                sections=asrt.matches_sequence([
                    section_matches(
                        target=equals_custom_cross_ref_test_impl(sub1_target.target),
                        header=asrt_para.equals_text(sub1_target.presentation_text),
                        contents=asrt.Is(expected_section_contents_object1)),
                    section_matches(
                        target=equals_custom_cross_ref_test_impl(sub2_target.target),
                        header=asrt_para.equals_text(sub2_target.presentation_text),
                        contents=asrt.Is(expected_section_contents_object2)),
                ])))
        # ACT & ASSERT #
        self._act_and_assert(object_to_test,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion2)
Exemplo n.º 6
0
 def test_article_separation_between_header_and_content(self):
     # ARRANGE #
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=100),
         num_item_separator_lines=0)
     formatter = sut.Formatter(
         paragraph_item_formatter,
         sut.Separation(between_sections=1,
                        between_header_and_content=2,
                        between_initial_paragraphs_and_sub_sections=3))
     header = text('Article Header')
     cases = [
         ('single abstract para / no contents para',
          Article(
              header,
              ArticleContents([single_text_para('abstract paragraph')],
                              empty_section_contents())), [
                                  'Article Header',
                                  BLANK_LINE,
                                  BLANK_LINE,
                                  'abstract paragraph',
                              ]),
         ('single abstract para / single contents para',
          Article(
              header,
              ArticleContents([single_text_para('abstract paragraph')],
                              single_para_contents('contents paragraph'))),
          [
              'Article Header',
              BLANK_LINE,
              BLANK_LINE,
              'abstract paragraph',
              'contents paragraph',
          ]),
         ('single abstract para / single contents para',
          Article(
              header,
              ArticleContents(
                  [single_text_para('abstract paragraph')],
                  SectionContents([],
                                  [empty_section('Sub Section Header')]))),
          [
              'Article Header',
              BLANK_LINE,
              BLANK_LINE,
              'abstract paragraph',
              BLANK_LINE,
              BLANK_LINE,
              BLANK_LINE,
              'Sub Section Header',
          ]),
     ]
     for test_case_name, article, expected_lines in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(article)
             #  ASSERT #
             self.assertEqual(expected_lines, actual)
Exemplo n.º 7
0
    def test_hierarchy_with_sub_sections(self):
        # ARRANGE #

        target_factory = TargetInfoFactoryTestImpl(['target_component'])
        expected_section_contents_object1 = doc.empty_section_contents()
        expected_section_contents_object2 = docs.section_contents(docs.paras('testing testing'))
        expected_root_initial_para = docs.para('root initial paras')
        expected_root_initial_paras = [expected_root_initial_para]

        root_header = StringText('root header')

        sub_section_header_1 = 'sub1'
        sub_section_header_2 = 'sub2'
        sub_section_local_target_1 = 'sub-target1'
        sub_section_local_target_2 = 'sub-target2'

        object_to_test = sut.hierarchy(
            root_header,
            paragraphs.constant(expected_root_initial_paras),
            [sut.child(sub_section_local_target_1,
                       sut.leaf(sub_section_header_1,
                                section_contents(expected_section_contents_object1))),
             sut.child(sub_section_local_target_2,
                       sut.leaf(sub_section_header_2,
                                section_contents(expected_section_contents_object2)))
             ])
        # EXPECTATION #
        expected_root_target_info = target_factory.root(root_header)

        sub1_target = target_factory.sub(sub_section_header_1, sub_section_local_target_1)
        sub2_target = target_factory.sub(sub_section_header_2, sub_section_local_target_2)
        target_info_node_assertion = equals_target_info_node(
            TargetInfoNode(expected_root_target_info,
                           [
                               target_info_leaf(sub1_target),
                               target_info_leaf(sub2_target),
                           ]),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion2 = section_matches(
            target=equals_custom_cross_ref_test_impl(expected_root_target_info.target),
            header=asrt_para.equals_text(expected_root_target_info.presentation_text),
            contents=section_contents_matches(
                initial_paragraphs=asrt.matches_sequence([asrt.Is(expected_root_initial_para)]),
                sections=asrt.matches_sequence([
                    section_matches(
                        target=equals_custom_cross_ref_test_impl(sub1_target.target),
                        header=asrt_para.equals_text(sub1_target.presentation_text),
                        contents=asrt.Is(expected_section_contents_object1)),
                    section_matches(
                        target=equals_custom_cross_ref_test_impl(sub2_target.target),
                        header=asrt_para.equals_text(sub2_target.presentation_text),
                        contents=asrt.Is(expected_section_contents_object2)),
                ])))
        # ACT & ASSERT #
        self._act_and_assert(object_to_test,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion2)
Exemplo n.º 8
0
    def test_with_fixed_root_target(self):
        # ARRANGE #

        root_header = StringText('root header')
        sub_header = StringText('sub header')
        sub_local_target_name = 'should not be used'

        fixed_target = CustomCrossReferenceTargetTestImpl('the fixed root target')

        default_target = CustomCrossReferenceTargetTestImpl('default target component')

        target_factory = ConstantTargetInfoFactoryTestImpl(default_target)

        unadjusted_object = sut.hierarchy(root_header,
                                          paragraphs.empty(),
                                          [sut.child(sub_local_target_name,
                                                     sut.leaf(sub_header.value,
                                                              section_contents(doc.empty_section_contents())))
                                           ]
                                          )
        adjusted_object = sut.with_fixed_root_target(fixed_target,
                                                     unadjusted_object)

        # EXPECTATION #

        expected_root_target_info = TargetInfo(root_header,
                                               fixed_target)

        expected_sub_target_info = TargetInfo(sub_header,
                                              default_target)

        target_info_node_assertion = equals_target_info_node(
            TargetInfoNode(expected_root_target_info,
                           [target_info_leaf(expected_sub_target_info)]),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(fixed_target),
            header=asrt_para.equals_text(expected_root_target_info.presentation_text),
            contents=section_contents_matches(
                initial_paragraphs=asrt.is_empty_sequence,
                sections=asrt.matches_sequence([
                    section_matches(
                        target=equals_custom_cross_ref_test_impl(default_target),
                        header=asrt_para.equals_text(sub_header),
                        contents=section_contents_matches(
                            initial_paragraphs=asrt.is_empty_sequence,
                            sections=asrt.is_empty_sequence
                        )
                    )
                ])
            ))

        # ACT & ASSERT #

        self._act_and_assert(adjusted_object,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Exemplo n.º 9
0
def builtin_symbol(symbol: SymbolContext) -> BuiltinSymbol:
    return BuiltinSymbol(
        symbol.name,
        symbol.value.value_type,
        symbol.sdv,
        CustomSymbolDocumentation(
            'the single line description',
            document.empty_section_contents(),
        ),
    )
Exemplo n.º 10
0
 def test_section(self):
     # ARRANGE   #
     section = sut.Section(StringText('header'),
                           sut.empty_section_contents())
     visitor = SectionItemVisitorThatRecordsExpectedClassAndReturnsArg()
     # ACT #
     ret_val = section.accept(visitor)
     # ASSERT #
     self.assertEqual([sut.Section], visitor.visited_classes)
     self.assertIs(section, ret_val)
Exemplo n.º 11
0
 def test_article_separation_between_header_and_content(self):
     # ARRANGE #
     paragraph_item_formatter = paragraph_item.Formatter(CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
                                                         paragraph_item.Wrapper(page_width=100),
                                                         num_item_separator_lines=0)
     formatter = sut.Formatter(paragraph_item_formatter,
                               sut.Separation(between_sections=1,
                                              between_header_and_content=2,
                                              between_initial_paragraphs_and_sub_sections=3))
     header = text('Article Header')
     cases = [
         ('single abstract para / no contents para',
          Article(header,
                  ArticleContents([single_text_para('abstract paragraph')],
                                  empty_section_contents())),
          [
              'Article Header',
              BLANK_LINE,
              BLANK_LINE,
              'abstract paragraph',
          ]),
         ('single abstract para / single contents para',
          Article(header,
                  ArticleContents([single_text_para('abstract paragraph')],
                                  single_para_contents('contents paragraph'))),
          [
              'Article Header',
              BLANK_LINE,
              BLANK_LINE,
              'abstract paragraph',
              'contents paragraph',
          ]),
         ('single abstract para / single contents para',
          Article(header,
                  ArticleContents([single_text_para('abstract paragraph')],
                                  SectionContents([],
                                                  [empty_section('Sub Section Header')]))),
          [
              'Article Header',
              BLANK_LINE,
              BLANK_LINE,
              'abstract paragraph',
              BLANK_LINE,
              BLANK_LINE,
              BLANK_LINE,
              'Sub Section Header',
          ]),
     ]
     for test_case_name, article, expected_lines in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(article)
             #  ASSERT #
             self.assertEqual(expected_lines,
                              actual)
Exemplo n.º 12
0
 def test_with_empty_main_description(self):
     # ARRANGE #
     doc = TypeDocumentation(TypeCategory.DATA,
                             A_TYPE_NAME_AND_CROSS_REFERENCE_ID,
                             A_SYNTAX_ELEMENT_INFO,
                             empty_section_contents())
     renderer = sut.IndividualTypeConstructor(doc)
     # ACT #
     actual = renderer.apply(CONSTRUCTION_ENVIRONMENT)
     # ASSERT #
     struct_check.is_article_contents.apply(self, actual)
Exemplo n.º 13
0
 def test_section(self):
     # ARRANGE   #
     section = sut.Section(StringText('header'),
                           sut.empty_section_contents())
     visitor = SectionItemVisitorThatRecordsExpectedClassAndReturnsArg()
     # ACT #
     ret_val = visitor.visit(section)
     # ASSERT #
     self.assertEqual([sut.Section],
                      visitor.visited_classes)
     self.assertIs(section, ret_val)
Exemplo n.º 14
0
 def test_article(self):
     # ARRANGE   #
     article = sut.Article(
         StringText('header'),
         ArticleContents([], sut.empty_section_contents()))
     visitor = SectionItemVisitorThatRecordsExpectedClassAndReturnsArg()
     # ACT #
     ret_val = article.accept(visitor)
     # ASSERT #
     self.assertEqual([sut.Article], visitor.visited_classes)
     self.assertIs(article, ret_val)
Exemplo n.º 15
0
 def test_with_empty_main_description(self):
     # ARRANGE #
     for type_cat_case in SYNTAX_ELEM_TYPE_CATEGORY_CASES:
         doc = TypeDocumentation(A_TYPE_NAME_AND_CROSS_REFERENCE_ID,
                                 type_cat_case.value,
                                 empty_section_contents())
         renderer = sut.IndividualTypeConstructor(doc)
         with self.subTest(type_cat_case.name):
             # ACT #
             actual = renderer.apply(CONSTRUCTION_ENVIRONMENT)
             # ASSERT #
             struct_check.is_article_contents.apply(self, actual)
Exemplo n.º 16
0
 def test_article(self):
     # ARRANGE   #
     article = sut.Article(StringText('header'),
                           ArticleContents([],
                                           sut.empty_section_contents()))
     visitor = SectionItemVisitorThatRecordsExpectedClassAndReturnsArg()
     # ACT #
     ret_val = visitor.visit(article)
     # ASSERT #
     self.assertEqual([sut.Article],
                      visitor.visited_classes)
     self.assertIs(article, ret_val)
Exemplo n.º 17
0
    def test_leaf_not_in_toc(self):
        # ARRANGE #
        target_factory = TargetInfoFactoryTestImpl(['target_component'])
        expected_section_contents_object = doc.empty_section_contents()
        header = StringText('header')
        generator_to_test = sut.leaf_not_in_toc(header.value,
                                                section_contents(expected_section_contents_object))
        # EXPECTATION #

        target_info_node_assertion = asrt.is_none

        section_assertion = section_matches(
            target=asrt.is_none,
            header=asrt_para.equals_text(header),
            contents=asrt.Is(expected_section_contents_object))

        # ACT & ASSERT #
        self._act_and_assert(generator_to_test,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Exemplo n.º 18
0
    def test_leaf(self):
        # ARRANGE #
        target_factory = TargetInfoFactoryTestImpl(['target_component'])
        expected_section_contents_object = doc.empty_section_contents()
        object_to_test = sut.leaf('header', section_contents(expected_section_contents_object))
        # EXPECTATION #
        expected_target_info = target_factory.root(StringText('header'))

        target_info_node_assertion = equals_target_info_node(
            target_info_leaf(expected_target_info),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(expected_target_info.target),
            header=asrt_para.equals_text(expected_target_info.presentation_text),
            contents=asrt.Is(expected_section_contents_object))

        # ACT & ASSERT #
        self._act_and_assert(object_to_test,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Exemplo n.º 19
0
    def test_leaf(self):
        # ARRANGE #
        target_factory = TargetInfoFactoryTestImpl(['target_component'])
        expected_section_contents_object = doc.empty_section_contents()
        object_to_test = sut.leaf('header', section_contents(expected_section_contents_object))
        # EXPECTATION #
        expected_target_info = target_factory.root(StringText('header'))

        target_info_node_assertion = equals_target_info_node(
            target_info_leaf(expected_target_info),
            mk_equals_cross_ref_id=equals_custom_cross_ref_test_impl)

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(expected_target_info.target),
            header=asrt_para.equals_text(expected_target_info.presentation_text),
            contents=asrt.Is(expected_section_contents_object))

        # ACT & ASSERT #
        self._act_and_assert(object_to_test,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Exemplo n.º 20
0
    def test_with_hidden_from_toc(self):
        # ARRANGE #
        target_factory = TargetInfoFactoryTestImpl(['target_component'])
        expected_section_contents_object = doc.empty_section_contents()
        header = StringText('header')
        unadjusted_object = sut.leaf(header.value,
                                     section_contents(expected_section_contents_object))
        adjusted_object = sut.with_not_in_toc(unadjusted_object)
        # EXPECTATION #
        expected_target_info = target_factory.root(header)

        target_info_node_assertion = asrt.is_none

        section_assertion = section_matches(
            target=equals_custom_cross_ref_test_impl(expected_target_info.target),
            header=asrt_para.equals_text(header),
            contents=asrt.Is(expected_section_contents_object))

        # ACT & ASSERT #
        self._act_and_assert(adjusted_object,
                             target_factory,
                             target_info_node_assertion,
                             section_assertion)
Exemplo n.º 21
0
 def test_section_content_indent(self):
     paragraph_item_formatter = paragraph_item.Formatter(
         CROSS_REF_TITLE_ONLY_TEXT_FORMATTER,
         paragraph_item.Wrapper(page_width=100),
         num_item_separator_lines=0)
     content_indent = '  '
     formatter = sut.Formatter(
         paragraph_item_formatter,
         section_content_indent_str=content_indent,
         separation=sut.Separation(
             between_sections=1,
             between_header_and_content=2,
             between_initial_paragraphs_and_sub_sections=3))
     header = text('Section Header')
     contents = SectionContents(
         [single_text_para('initial paragraph')],
         [Section(text('Sub Section Header'), empty_section_contents())])
     cases = [
         ('section', Section(header, contents)),
         ('article', Article(header, ArticleContents([], contents))),
     ]
     for test_case_name, section_item in cases:
         with self.subTest(test_case_name):
             # ACT #
             actual = formatter.format_section_item(section_item)
             # ASSERT #
             self.assertEqual([
                 'Section Header',
                 BLANK_LINE,
                 BLANK_LINE,
                 content_indent + 'initial paragraph',
                 BLANK_LINE,
                 BLANK_LINE,
                 BLANK_LINE,
                 content_indent + 'Sub Section Header',
             ], actual)
Exemplo n.º 22
0
def to_lower_case_doc() -> CustomSymbolDocumentation:
    return CustomSymbolDocumentation(
        'Converts all cased characters to lowercase',
        document.empty_section_contents(),
    )
Exemplo n.º 23
0
from exactly_lib.definitions.entity import types, syntax_elements
from exactly_lib.help.entities.types.contents_structure import LogicTypeWithExpressionGrammarDocumentation, \
    TypeDocumentation
from exactly_lib.test_case_utils.file_matcher import parse_file_matcher
from exactly_lib.test_case_utils.line_matcher import parse_line_matcher
from exactly_lib.test_case_utils.string_transformer import parse_string_transformer
from exactly_lib.type_system.value_type import TypeCategory
from exactly_lib.util.textformat.structure import structures as docs
from exactly_lib.util.textformat.structure.document import empty_section_contents

LINE_MATCHER_DOCUMENTATION = LogicTypeWithExpressionGrammarDocumentation(
    types.LINE_MATCHER_TYPE_INFO,
    syntax_elements.LINE_MATCHER_SYNTAX_ELEMENT,
    parse_line_matcher.GRAMMAR,
    empty_section_contents())

FILE_MATCHER_DOCUMENTATION = LogicTypeWithExpressionGrammarDocumentation(
    types.FILE_MATCHER_TYPE_INFO,
    syntax_elements.FILE_MATCHER_SYNTAX_ELEMENT,
    parse_file_matcher.GRAMMAR,
    empty_section_contents())

STRING_TRANSFORMER_DOCUMENTATION = LogicTypeWithExpressionGrammarDocumentation(
    types.STRING_TRANSFORMER_TYPE_INFO,
    syntax_elements.STRING_TRANSFORMER_SYNTAX_ELEMENT,
    parse_string_transformer.GRAMMAR,
    empty_section_contents())

STRING_MATCHER_DOCUMENTATION = TypeDocumentation(TypeCategory.LOGIC,
                                                 types.STRING_MATCHER_TYPE_INFO,
                                                 syntax_elements.STRING_MATCHER_SYNTAX_ELEMENT,
Exemplo n.º 24
0
    def test_simple(self):
        cases = [
            ('empty',
             Article(StringText('header'),
                     ArticleContents([],
                                     empty_section_contents())),
             '<root>'
             '<article>'

             '<header>'
             '<h1>header</h1>'
             '</header>'

             '</article>'
             '</root>'
             ),
            ('empty with target',
             Article(StringText('header'),
                     ArticleContents([],
                                     empty_section_contents()),
                     target=CrossReferenceTargetTestImpl('target-name')),
             '<root>'
             '<article id="target-name">'

             '<header>'
             '<h1>header</h1>'
             '</header>'

             '</article>'
             '</root>'
             ),
            ('empty with tags',
             Article(StringText('header'),
                     ArticleContents([],
                                     empty_section_contents()),
                     tags={'label1', 'label2'}),
             '<root>'
             '<article class="label1 label2">'

             '<header>'
             '<h1>header</h1>'
             '</header>'

             '</article>'
             '</root>'
             ),
            ('empty with target and tags',
             Article(StringText('header'),
                     ArticleContents([],
                                     empty_section_contents()),
                     target=CrossReferenceTargetTestImpl('article-target'),
                     tags={'label1', 'label2'}),
             '<root>'
             '<article class="label1 label2" id="article-target">'

             '<header>'
             '<h1>header</h1>'
             '</header>'

             '</article>'
             '</root>'
             ),
            ('single abstract paragraph',
             Article(StringText('header'),
                     ArticleContents([para('abstract paragraph')],
                                     empty_section_contents())),
             '<root>'
             '<article>'

             '<header>'
             '<h1>header</h1>'
             '<p>abstract paragraph</p>'
             '</header>'

             '</article>'
             '</root>'
             )
        ]
        for test_case_name, article, expected in cases:
            with self.subTest(test_case_name):
                root = Element('root')
                environment = sut.Environment(0)
                # ACT #
                ret_val = TEST_RENDERER.render_section_item(environment,
                                                            root,
                                                            article)
                # ASSERT #
                assert_contents_and_that_last_child_is_returned(
                    expected,
                    root, ret_val, self)
Exemplo n.º 25
0
    def test(self):
        # ARRANGE #
        cases = [
            ('empty',
             Section(
                 StringText('header 1'),
                 empty_section_contents()),
             '<root>'
             '<section>'

             '<header>'
             '<h1>header 1</h1>'
             '</header>'

             '</section>'
             '</root>'
             ),
            ('empty with target',
             Section(
                 StringText('header 1'),
                 empty_section_contents(),
                 target=CrossReferenceTargetTestImpl('section-target-name')),
             '<root>'
             '<section id="section-target-name">'

             '<header>'
             '<h1>header 1</h1>'
             '</header>'

             '</section>'
             '</root>'
             ),
            ('empty with tags',
             Section(
                 StringText('header 1'),
                 empty_section_contents(),
                 tags={'first-label', 'second-label'}),
             '<root>'
             '<section class="first-label second-label">'

             '<header>'
             '<h1>header 1</h1>'
             '</header>'

             '</section>'
             '</root>'
             ),
            ('empty with target and tags',
             Section(
                 StringText('header 1'),
                 empty_section_contents(),
                 target=CrossReferenceTargetTestImpl('t'),
                 tags={'l1', 'l2'}),
             '<root>'
             '<section class="l1 l2" id="t">'

             '<header>'
             '<h1>header 1</h1>'
             '</header>'

             '</section>'
             '</root>'
             ),
            ('with contents',
             Section(
                 StringText('header 1'),
                 SectionContents(
                     [para('para 1')],
                     [Section(
                         StringText('header 1/1'),
                         SectionContents(
                             [para('para 1/1')], []))])
             ),
             '<root>'
             '<section>'

             '<header>'
             '<h1>header 1</h1>'
             '</header>'

             '<p>para 1</p>'

             '<section>'

             '<header>'
             '<h2>header 1/1</h2>'
             '</header>'

             '<p>para 1/1</p>'

             '</section>'
             '</section>'
             '</root>'
             ),
        ]
        for test_case_name, section, expected in cases:
            with self.subTest(test_case_name):
                root = Element('root')
                # ACT #
                ret_val = TEST_RENDERER.render_section_item(sut.Environment(0),
                                                            root,
                                                            section)
                # ASSERT #
                assert_contents_and_that_last_child_is_returned(
                    expected,
                    root, ret_val, self)
Exemplo n.º 26
0
 def description(self) -> DescriptionWithSubSections:
     text = '{}s help system.'.format(formatting.program_name(program_info.PROGRAM_NAME))
     return DescriptionWithSubSections(docs.text(text),
                                       empty_section_contents())
Exemplo n.º 27
0
def empty_section_contents() -> SectionContents:
    return document.empty_section_contents()
Exemplo n.º 28
0
def empty_section_contents() -> SectionContents:
    return document.empty_section_contents()
Exemplo n.º 29
0
 def description(self) -> DescriptionWithSubSections:
     text = '{}s help system.'.format(
         formatting.program_name(program_info.PROGRAM_NAME))
     return DescriptionWithSubSections(docs.text(text),
                                       empty_section_contents())
Exemplo n.º 30
0
 def test(self):
     # ARRANGE #
     cases = [
         ('empty', Section(StringText('header 1'),
                           empty_section_contents()),
          element('root',
                  children=[
                      element('section',
                              children=[
                                  _header_w_h('header 1'),
                              ])
                  ])),
         ('empty with target',
          Section(
              StringText('header 1'),
              empty_section_contents(),
              target=CrossReferenceTargetTestImpl('section-target-name')),
          element('root',
                  children=[
                      element('section',
                              attributes={'id': 'section-target-name'},
                              children=[_header_w_h('header 1')])
                  ])),
         ('empty with tags',
          Section(StringText('header 1'),
                  empty_section_contents(),
                  tags={'first-label', 'second-label'}),
          element('root',
                  children=[
                      element(
                          'section',
                          attributes={'class': 'first-label second-label'},
                          children=[_header_w_h('header 1')])
                  ])),
         ('empty with target and tags',
          Section(StringText('header 1'),
                  empty_section_contents(),
                  target=CrossReferenceTargetTestImpl('t'),
                  tags={'l1', 'l2'}),
          element('root',
                  children=[
                      element('section',
                              attributes={
                                  'class': 'l1 l2',
                                  'id': 't'
                              },
                              children=[_header_w_h('header 1')])
                  ])),
         ('with contents',
          Section(
              StringText('header 1'),
              SectionContents([para('para 1')], [
                  Section(StringText('header 1/1'),
                          SectionContents([para('para 1/1')], []))
              ])),
          element('root',
                  children=[
                      element('section',
                              children=[
                                  _header_w_h('header 1'),
                                  element('p', text='para 1'),
                                  element('section',
                                          children=[
                                              _header_w_h(
                                                  'header 1/1', 'h2'),
                                              element('p', text='para 1/1'),
                                          ])
                              ])
                  ])),
     ]
     for test_case_name, section, expected in cases:
         with self.subTest(test_case_name):
             root_element_to_mutate = Element('root')
             # ACT #
             ret_val = TEST_RENDERER.render_section_item(
                 sut.Environment(0), root_element_to_mutate, section)
             # ASSERT #
             assert_contents_and_that_last_child_is_returned(
                 expected, root_element_to_mutate, ret_val, self)
Exemplo n.º 31
0
 def test_simple(self):
     cases = [
         ('empty',
          Article(StringText('header'),
                  ArticleContents([], empty_section_contents())),
          element('root',
                  children=[
                      element('article', children=[
                          _header_w_h('header'),
                      ])
                  ])),
         ('empty with target',
          Article(StringText('header'),
                  ArticleContents([], empty_section_contents()),
                  target=CrossReferenceTargetTestImpl('target-name')),
          element('root',
                  children=[
                      element('article',
                              attributes={'id': 'target-name'},
                              children=[_header_w_h('header')])
                  ])),
         ('empty with tags',
          Article(StringText('header'),
                  ArticleContents([], empty_section_contents()),
                  tags={'label1', 'label2'}),
          element('root',
                  children=[
                      element('article',
                              attributes={'class': 'label1 label2'},
                              children=[_header_w_h('header')])
                  ])),
         ('empty with target and tags',
          Article(StringText('header'),
                  ArticleContents([], empty_section_contents()),
                  target=CrossReferenceTargetTestImpl('article-target'),
                  tags={'label1', 'label2'}),
          element('root',
                  children=[
                      element('article',
                              attributes={
                                  'class': 'label1 label2',
                                  'id': 'article-target'
                              },
                              children=[_header_w_h('header')])
                  ])),
         ('single abstract paragraph',
          Article(
              StringText('header'),
              ArticleContents([para('abstract paragraph')],
                              empty_section_contents())),
          element('root',
                  children=[
                      element('article',
                              children=[
                                  element(
                                      'header',
                                      children=[
                                          element('h1', text='header'),
                                          element(
                                              'p',
                                              text='abstract paragraph'),
                                      ],
                                  )
                              ])
                  ]))
     ]
     for test_case_name, article, expected in cases:
         with self.subTest(test_case_name):
             root = Element('root')
             environment = sut.Environment(0)
             # ACT #
             ret_val = TEST_RENDERER.render_section_item(
                 environment, root, article)
             # ASSERT #
             assert_contents_and_that_last_child_is_returned(
                 expected, root, ret_val, self)