Ejemplo n.º 1
0
def equivalent_source_variants__with_source_check__consume_last_line__abs_stx(
    syntax: AbstractSyntax, ) -> List[NameAndValue[SourceCase]]:
    """
    Checks that the whole instruction_argument has been consumed,
    and that the parser is positioned at the beginning of the following line.

    Assumes that the body of the loop parses using the given source.
    """
    tokens = syntax.tokenization()

    def cases_for(
        layout_case: NameAndValue[tokens_layout.LayoutSpec]
    ) -> List[NameAndValue[SourceCase]]:
        source_str = tokens.layout(layout_case.value)
        num_source_lines = source_str.count('\n') + 1
        return [
            NameAndValue(
                'layout={}, following_lines={}'.format(layout_case.name,
                                                       repr(following_lines)),
                SourceCase(
                    remaining_source(source_str, following_lines),
                    source_assertion,
                )) for following_lines, source_assertion in
            _source_variant_test_cases__multi_line(num_source_lines)
        ]

    return collection.concat_list([
        cases_for(layout_case)
        for layout_case in tokens_layout.STANDARD_LAYOUT_SPECS
    ])
Ejemplo n.º 2
0
 def check__abs_stx__layouts__source_variants(
         self,
         put: unittest.TestCase,
         mk_source_variants: SourceStr2SourceVariants,
         source: AbstractSyntax,
         input_: INPUT,
         arrangement: Arrangement,
         expectation_: MultiSourceExpectation[PRIMITIVE, OUTPUT],
         layouts: Sequence[
             NameAndValue[LayoutSpec]] = layout.STANDARD_LAYOUT_SPECS,
         sub_test_identifiers: Mapping[str, Any] = MappingProxyType({}),
 ):
     tokens = source.tokenization()
     for layout_case in layouts:
         source_str = tokens.layout(layout_case.value)
         for source_case in mk_source_variants(source_str):
             with put.subTest(zz_layout=layout_case.name,
                              zz_source_variant=source_case.name,
                              **sub_test_identifiers):
                 self._check__parse_source(
                     put,
                     source_case.source,
                     input_,
                     arrangement,
                     source_case.expectation,
                     expectation_,
                 )
Ejemplo n.º 3
0
 def of_modification(
     modification: TokenSequence,
     contents: AbstractSyntax,
 ) -> TokenSequence:
     return TokenSequence.concat([
         modification,
         TokenSequence.optional_new_line(),
         contents.tokenization()
     ])
Ejemplo n.º 4
0
def formatting_cases(
    syntax: AbstractSyntax,
    layouts: Sequence[NameAndValue[
        layout.LayoutSpec]] = layout.STANDARD_LAYOUT_SPECS,
) -> Sequence[NameAndValue[str]]:
    tokens = syntax.tokenization()
    return [
        NameAndValue(layout_case.name, tokens.layout(layout_case.value))
        for layout_case in layouts
    ]
Ejemplo n.º 5
0
 def check__abs_stx(
         self,
         put: unittest.TestCase,
         source: AbstractSyntax,
         arrangement: Arrangement,
         expectation_: Expectation[T],
         layout: LayoutSpec = LayoutSpec.of_default(),
 ):
     source = remaining_source(source.tokenization().layout(layout))
     _ParseAndExecutionChecker(put, arrangement,
                               expectation_).execute(self.parser, source)
Ejemplo n.º 6
0
 def _check__abs_stx(self, arguments: AbstractSyntax,
                     expected_source_after_parse: Assertion[ParseSource],
                     expectation_on_exe_file: ExpectationOnExeFile,
                     validator_expectation: validation.Expectation):
     for layout_spec in STANDARD_LAYOUT_SPECS:
         with self.subTest(layout_spec.name):
             self._check(
                 arguments.tokenization().layout(layout_spec.value),
                 expected_source_after_parse,
                 expectation_on_exe_file,
                 validator_expectation,
             )
Ejemplo n.º 7
0
 def parse__abs_stx(
     self,
     put: unittest.TestCase,
     valid_source: AbstractSyntax,
     layout: tokens_layout.LayoutSpec = tokens_layout.LayoutSpec.of_default(
     ),
 ) -> T:
     parse_source = remaining_source(
         valid_source.tokenization().layout(layout))
     actual = self.parser.parse(ARBITRARY_FS_LOCATION_INFO, parse_source)
     put.assertIsNotNone(actual, 'parsed object')
     return actual
Ejemplo n.º 8
0
 def check_invalid_syntax__abs_stx(
         self,
         put: unittest.TestCase,
         invalid_source: AbstractSyntax,
         sub_test_identifiers: Mapping[str, Any] = MappingProxyType({}),
 ):
     for layout_case in STANDARD_LAYOUT_SPECS:
         parse_source = ParseSource(invalid_source.tokenization().layout(
             layout_case.value))
         with put.subTest(zz_layout=layout_case.name,
                          **sub_test_identifiers):
             self.check_invalid_arguments(put, parse_source)
Ejemplo n.º 9
0
 def check__abs_stx(
         self,
         put: unittest.TestCase,
         source: AbstractSyntax,
         input_: INPUT,
         arrangement: Arrangement,
         expectation: Expectation[PRIMITIVE, OUTPUT],
         layout_: LayoutSpec = LayoutSpec.of_default(),
 ):
     checker = _ParseAndExecutionChecker(
         put, input_, self._parser, arrangement, self._configuration,
         self._check_application_result_with_tcds, expectation)
     checker.check(remaining_source(source.tokenization().layout(layout_)))
Ejemplo n.º 10
0
def check__abs_stx(
    put: unittest.TestCase,
    instruction_argument: AbstractSyntax,
    arrangement: Arrangement,
    expectation: Expectation,
):
    for layout_spec in STANDARD_LAYOUT_SPECS:
        with put.subTest(layout=layout_spec.name):
            check(
                put,
                instruction_argument.tokenization().layout(layout_spec.value),
                arrangement,
                expectation,
            )
Ejemplo n.º 11
0
 def check__abs_stx(
     self,
     put: unittest.TestCase,
     syntax: AbstractSyntax,
     arrangement: Arrangement,
     expectation: Expectation,
 ):
     for layout_spec in layout.STANDARD_LAYOUT_SPECS:
         source_str = syntax.tokenization().layout(layout_spec.value)
         source_lines = source_str.splitlines(keepends=False)
         with put.subTest(layout=layout_spec.name):
             self.check(
                 put,
                 [act_phase_instruction.instr(source_lines)],
                 arrangement,
                 expectation,
             )
Ejemplo n.º 12
0
 def check__abs_stx__source_variants(
     self,
     put: unittest.TestCase,
     source: AbstractSyntax,
     arrangement: Arrangement2,
     expected_parsed_path: Assertion[PathSdv],
 ):
     # ARRANGE #
     parser = sut.PathParser(arrangement.rel_option_argument_configuration)
     for source_variant_case in equivalent_source_variants.expr_parse__s__nsc(
             source.as_str__default()):
         with put.subTest(source=source_variant_case.name):
             source = source_variant_case.source
             # ACT #
             actual = parser.parse(source, arrangement.source_file_path)
             # ASSERT #
             source_variant_case.expectation.apply_with_message(
                 put, source, 'source')
             expected_parsed_path.apply_with_message(
                 put, actual, 'path sdv')
Ejemplo n.º 13
0
 def check_multi_source__abs_stx(
     self,
     put: unittest.TestCase,
     source: AbstractSyntax,
     arrangement: Arrangement,
     expectation: MultiSourceExpectation,
 ):
     tokens = source.tokenization()
     for layout_case in layout.STANDARD_LAYOUT_SPECS:
         source_str = tokens.layout(layout_case.value)
         for source_case in equivalent_source_variants__consume_last_line__s__nsc(
                 source_str):
             with put.subTest(layout=layout_case.name,
                              source_variant=source_case.name):
                 self.check(
                     put,
                     source_case.source,
                     arrangement,
                     expectation.as_expectation_w_source(
                         source_case.expectation),
                 )
Ejemplo n.º 14
0
 def check__abs_stx__source_variants(self,
                                     put: unittest.TestCase,
                                     syntax: AbstractSyntax,
                                     arrangement: ArrangementPostAct2,
                                     expectation: MultiSourceExpectation,
                                     ):
     tokens = syntax.tokenization()
     for layout_case in layout.STANDARD_LAYOUT_SPECS:
         source_str = tokens.layout(layout_case.value)
         for source_case in equivalent_source_variants__consume_last_line__s__nsc(source_str):
             with put.subTest(layout=layout_case.name,
                              source_variant=source_case.name):
                 self.check_2(
                     put,
                     source_case.source,
                     arrangement,
                     Expectation2(
                         ParseExpectation(
                             source_case.expectation,
                             expectation.symbol_usages,
                         ),
                         expectation.execution,
                     )
                 )
Ejemplo n.º 15
0
def parse_source_of__abs_stx(syntax: AbstractSyntax) -> ParseSource:
    return remaining_source(syntax.tokenization().layout(
        LayoutSpec.of_default()))