Ejemplo n.º 1
0
    def runTest(self):
        to_upper_transformer = NameAndValue(
            'TRANSFORMER_SYMBOL',
            StringTransformerSdvConstantTestImpl(to_uppercase()))

        src_file = fs.File('src-file.txt', 'contents of source file')
        src_file_symbol = NameAndValue('SRC_FILE_SYMBOL', src_file.name)

        expected_dst_file = fs.File('dst-file-name.txt',
                                    src_file.contents.upper())
        dst_file_symbol = NameAndValue('DST_FILE_SYMBOL',
                                       expected_dst_file.name)

        transformed_file_syntax = string_source_abs_stx.TransformedStringSourceAbsStx(
            string_source_abs_stx.StringSourceOfFileAbsStx(
                PathSymbolReferenceAbsStx(src_file_symbol.name)),
            str_trans_abs_stx.StringTransformerSymbolReferenceAbsStx(
                to_upper_transformer.name))
        instruction_syntax = instr_abs_stx.create_w_explicit_contents(
            PathSymbolReferenceAbsStx(dst_file_symbol.name),
            transformed_file_syntax,
        )

        # ACT #
        for layout_case in tokens_layout.STANDARD_LAYOUT_SPECS:
            with self.subTest(layout_case.name):
                instruction = self.conf.parse_checker.parse__abs_stx(
                    self, instruction_syntax, layout_case.value)
                assert isinstance(
                    instruction,
                    TestCaseInstructionWithSymbols)  # Sanity check

                # ASSERT #

                expected_symbol_usages = [
                    asrt_sym_ref.matches_reference_2(
                        dst_file_symbol.name,
                        asrt_w_str_rend_rest.equals__w_str_rendering(
                            path_or_string_reference_restrictions(
                                new_file.REL_OPT_ARG_CONF.options.
                                accepted_relativity_variants))),
                    asrt_sym_ref.matches_reference_2(
                        src_file_symbol.name,
                        asrt_w_str_rend_rest.equals__w_str_rendering(
                            path_or_string_reference_restrictions(
                                src_rel_opt_arg_conf_for_phase(
                                    self.conf.phase_is_after_act()).options.
                                accepted_relativity_variants))),
                    is_reference_to_string_transformer__usage(
                        to_upper_transformer.name),
                ]
                expected_symbol_references = asrt.matches_sequence(
                    expected_symbol_usages)
                expected_symbol_references.apply_without_message(
                    self, instruction.symbol_usages())
Ejemplo n.º 2
0
 def expected_symbols(self) -> Sequence[Assertion[SymbolReference]]:
     return [
         asrt_sym_ref.matches_reference_2(
             self.min_depth.name,
             asrt_data_rest.equals__w_str_rendering(
                 reference_restrictions.
                 is_string__all_indirect_refs_are_strings())),
         asrt_sym_ref.matches_reference_2(
             self.max_depth.name,
             asrt_data_rest.equals__w_str_rendering(
                 reference_restrictions.
                 is_string__all_indirect_refs_are_strings())),
         self._helper.files_matcher_sym_assertion(),
     ]
Ejemplo n.º 3
0
    def test_string_token(self):
        # ARRANGE #
        plain_string = 'plain'
        symbol_name = 'symbol_name'

        cases = [
            Case('plain string',
                 plain_string,
                 Expectation(
                     elements=[list_resolvers.str_element(plain_string)],
                     validators=asrt.is_empty_sequence,
                     references=asrt.is_empty_sequence,
                 )),
            Case('symbol reference',
                 symbol_reference_syntax_for_name(symbol_name),
                 Expectation(
                     elements=[list_resolvers.symbol_element(symbol_reference(symbol_name))],
                     validators=asrt.is_empty_sequence,
                     references=asrt.matches_sequence([asrt_sym_ref.matches_reference_2(
                         symbol_name,
                         is_any_data_type_reference_restrictions())
                     ]),
                 )),
        ]
        # ACT & ASSERT #
        _test_cases(self, cases)
Ejemplo n.º 4
0
 def test_symbol_usages_of_object_returned_by_parser_SHOULD_be_reported(
         self):
     # ARRANGE #
     symbol_reference = NameAndValue(
         'symbol_name',
         reference_restrictions.is_any_type_w_str_rendering())
     expected_symbol_references = [
         SymbolReference(symbol_reference.name, symbol_reference.value)
     ]
     actor = sut.ActorFromParts(
         ParserWithConstantResult(
             SymbolUserWithConstantSymbolReferences(
                 expected_symbol_references)),
         sut.UnconditionallySuccessfulValidatorConstructor(),
         _ExecutorConstructorForConstant(
             UnconditionallySuccessfulExecutor()),
     )
     # ACT & ASSERT #
     check_execution(
         self, actor, [], arrangement_w_tcds(),
         Expectation(symbol_usages=asrt.matches_sequence([
             asrt_sym_ref.matches_reference_2(
                 symbol_reference.name,
                 data_restrictions_assertions.equals__w_str_rendering(
                     symbol_reference.value))
         ])))
def equals_symbol_reference_with_restriction_on_direct_target(expected_name: str,
                                                              assertion_on_direct_restriction: ValueAssertion
                                                              ) -> ValueAssertion[su.SymbolReference]:
    return asrt_sym_ref.matches_reference_2(expected_name,
                                            matches_restrictions_on_direct_and_indirect(
                                                assertion_on_direct=assertion_on_direct_restriction,
                                                assertion_on_every=asrt.ValueIsNone()))
Ejemplo n.º 6
0
    def test(self):
        # ARRANGE #
        plain_string1 = 'plain_1'
        plain_string2 = 'plain_2'
        symbol_name_1 = 'symbol_name_1'
        symbol_name_2 = 'symbol_name_2'
        remaining_part_of_current_line_with_sym_ref = ''.join(['before',
                                                               symbol_reference_syntax_for_name(symbol_name_2),
                                                               'after'])

        cases = [
            Case('plain strings',
                 ab.sequence([plain_string1,
                              plain_string2]).as_str,
                 Expectation(
                     elements=[list_resolvers.str_element(plain_string1),
                               list_resolvers.str_element(plain_string2)],
                     validators=asrt.is_empty_sequence,
                     references=asrt.is_empty_sequence,
                 )),
            Case('symbol reference + plain string + until-end-of-line',
                 ab.sequence([ab.symbol_reference(symbol_name_1),
                              plain_string1,
                              syntax_elements.REMAINING_PART_OF_CURRENT_LINE_AS_LITERAL_MARKER,
                              remaining_part_of_current_line_with_sym_ref,
                              ]).as_str,
                 Expectation(
                     elements=[list_resolvers.symbol_element(symbol_reference(symbol_name_1)),
                               list_resolvers.str_element(plain_string1),
                               list_resolvers.string_element(string_resolvers.from_fragments([
                                   string_resolvers.str_fragment('before'),
                                   string_resolvers.symbol_fragment(symbol_reference(symbol_name_2)),
                                   string_resolvers.str_fragment('after'),
                               ]))
                               ],
                     validators=asrt.is_empty_sequence,
                     references=asrt.matches_sequence([
                         asrt_sym_ref.matches_reference_2(symbol_name_1,
                                                          is_any_data_type_reference_restrictions()),
                         asrt_sym_ref.matches_reference_2(symbol_name_2,
                                                          is_any_data_type_reference_restrictions()),
                     ]),
                 )),
        ]
        # ACT & ASSERT #
        _test_cases(self, cases)
Ejemplo n.º 7
0
def is_reference_to__path_or_string(symbol_name: str,
                                    accepted_relativities: PathRelativityVariants,
                                    ) -> Assertion[SymbolReference]:
    return asrt_sym_ref.matches_reference_2(
        symbol_name,
        asrt_data_ref_restriction.equals__w_str_rendering(
            path_or_string_reference_restrictions(accepted_relativities))
    )
Ejemplo n.º 8
0
def matches_symbol_reference_with_restriction_on_direct_target(
        expected_name: str,
        assertion_on_direct_restriction: Assertion[ValueRestriction]
) -> Assertion[SymbolReference]:
    return asrt_sym_ref.matches_reference_2(expected_name,
                                            asrt_w_str_rend_rest.matches__on_direct_and_indirect(
                                                assertion_on_direct=assertion_on_direct_restriction,
                                                assertion_on_indirect=asrt.ValueIsNone()))
Ejemplo n.º 9
0
def equals_data_type_symbol_reference(expected: SymbolReference) -> Assertion[SymbolReference]:
    restrictions = expected.restrictions
    if not isinstance(restrictions, WithStrRenderingTypeRestrictions):
        raise ValueError('Restrictions must be {}. Found {}'.format(
            WithStrRenderingTypeRestrictions,
            restrictions,
        ))
    return asrt_sym_ref.matches_reference_2(expected.name,
                                            asrt_w_str_rend_rest.equals__w_str_rendering(restrictions))
Ejemplo n.º 10
0
def equals_list_sdv_element(expected: list_sdv.ElementSdv,
                            symbols: SymbolTable = None) -> Assertion[list_sdv.ElementSdv]:
    if symbols is None:
        symbols = symbol_table_with_values_matching_references(list(expected.references))
    expected_resolved_value_list = expected.resolve(symbols)
    assertion_on_resolved_value = asrt.matches_sequence(
        [equals_string_ddv(sv) for sv in expected_resolved_value_list])
    component_assertions = [
        asrt.sub_component('references',
                           lambda x: list(x.references),
                           equals_symbol_references__w_str_rendering(list(expected.references))),
        asrt.sub_component('resolved value',
                           lambda x: x.resolve(symbols),
                           assertion_on_resolved_value),

    ]
    symbol_reference_assertion = asrt.is_none
    reference = expected.symbol_reference_if_is_symbol_reference
    if reference is not None:
        reference_restrictions = reference.restrictions
        if not isinstance(reference_restrictions, WithStrRenderingTypeRestrictions):
            raise ValueError('A list element must reference a data type value')
        assert isinstance(reference_restrictions, WithStrRenderingTypeRestrictions)  # Type info for IDE

        symbol_reference_assertion = equals_data_type_symbol_reference(reference)

        asrt_sym_ref.matches_reference_2(
            reference.name,
            data_restrictions_assertions.equals__w_str_rendering(
                reference_restrictions)
        )

    symbol_reference_component_assertion = asrt.sub_component('symbol_reference_if_is_symbol_reference',
                                                              lambda x: x.symbol_reference_if_is_symbol_reference,
                                                              symbol_reference_assertion)
    component_assertions.append(symbol_reference_component_assertion)
    return asrt.is_instance_with(
        list_sdv.ElementSdv,
        asrt.and_(component_assertions))
Ejemplo n.º 11
0
    def test_remaining_part_of_current_line_as_literal(self):
        # ARRANGE #
        symbol_name = 'symbol_name'
        str_with_space_and_invalid_token_syntax = 'before and after space, ' + SOFT_QUOTE_CHAR + 'after quote'

        cases = [
            Case('string with one space after marker, and no space at EOL',
                 ' '.join([
                     syntax_elements.REMAINING_PART_OF_CURRENT_LINE_AS_LITERAL_MARKER,
                     str_with_space_and_invalid_token_syntax]),
                 Expectation(
                     elements=[list_resolvers.str_element(str_with_space_and_invalid_token_syntax)],
                     validators=asrt.is_empty_sequence,
                     references=asrt.is_empty_sequence,
                 )),
            Case('with surrounding space',
                 ' '.join([
                     syntax_elements.REMAINING_PART_OF_CURRENT_LINE_AS_LITERAL_MARKER,
                     '   ' + str_with_space_and_invalid_token_syntax + '  \t ']),
                 Expectation(
                     elements=[list_resolvers.str_element(str_with_space_and_invalid_token_syntax)],
                     validators=asrt.is_empty_sequence,
                     references=asrt.is_empty_sequence,
                 )),
            Case('with symbol reference',
                 ' '.join([
                     syntax_elements.REMAINING_PART_OF_CURRENT_LINE_AS_LITERAL_MARKER,
                     ''.join(['before',
                              symbol_reference_syntax_for_name(symbol_name),
                              'after'])]),
                 Expectation(
                     elements=[list_resolvers.string_element(string_resolvers.from_fragments([
                         string_resolvers.str_fragment('before'),
                         string_resolvers.symbol_fragment(symbol_reference(symbol_name)),
                         string_resolvers.str_fragment('after'),
                     ]))
                     ],
                     validators=asrt.is_empty_sequence,
                     references=asrt.matches_sequence([asrt_sym_ref.matches_reference_2(
                         symbol_name,
                         is_any_data_type_reference_restrictions())
                     ]),
                 )),
        ]
        # ACT & ASSERT #
        _test_cases(self, cases)
Ejemplo n.º 12
0
def is_reference_to__w_str_rendering(symbol_name: str
                                     ) -> Assertion[SymbolReference]:
    return matches_reference_2(
        symbol_name,
        asrt_data_ref_restriction.is__w_str_rendering(),
    )
Ejemplo n.º 13
0
def is_reference_to__string(symbol_name: str) -> Assertion[SymbolReference]:
    return asrt_sym_ref.matches_reference_2(
        symbol_name,
        IS_STRING_REFERENCE_RESTRICTION,
    )
Ejemplo n.º 14
0
    def test(self):
        # ARRANGE #
        plain_string1 = 'plain_1'
        plain_string2 = 'plain_2'
        symbol_name_1 = 'symbol_name_1'
        symbol_name_2 = 'symbol_name_2'
        remaining_part_of_current_line_with_sym_ref = ''.join([
            'before',
            symbol_reference_syntax_for_name(symbol_name_2), 'after'
        ])

        cases = [
            Case.of_multi(
                'plain strings', [
                    ArgumentOfRichStringAbsStx.of_str(plain_string1),
                    ArgumentOfRichStringAbsStx.of_str(plain_string2)
                ], ARRANGEMENT__NEUTRAL,
                Expectation(
                    elements=[
                        list_sdvs.str_element(plain_string1),
                        list_sdvs.str_element(plain_string2)
                    ],
                    validators=asrt.is_empty_sequence,
                    references=asrt.is_empty_sequence,
                )),
            Case.of_multi(
                'plain strings on several lines (separated by continuation token)',
                [
                    ArgumentOfRichStringAbsStx.of_str(plain_string1),
                    ContinuationTokenFollowedByArgumentAbsStx(
                        ArgumentOfRichStringAbsStx.of_str(plain_string2)),
                ], ARRANGEMENT__NEUTRAL,
                Expectation(
                    elements=[
                        list_sdvs.str_element(plain_string1),
                        list_sdvs.str_element(plain_string2)
                    ],
                    validators=asrt.is_empty_sequence,
                    references=asrt.is_empty_sequence,
                )),
            Case.of_multi(
                'plain strings on several lines (separated by continuation token) / first line empty',
                [
                    ContinuationTokenFollowedByArgumentAbsStx(
                        ArgumentOfRichStringAbsStx.of_str(plain_string1)),
                    ArgumentOfRichStringAbsStx.of_str(plain_string2),
                ], ARRANGEMENT__NEUTRAL,
                Expectation(
                    elements=[
                        list_sdvs.str_element(plain_string1),
                        list_sdvs.str_element(plain_string2)
                    ],
                    validators=asrt.is_empty_sequence,
                    references=asrt.is_empty_sequence,
                )),
            Case.of_multi(
                'symbol reference + plain string + until-end-of-line', [
                    ArgumentOfSymbolReferenceAbsStx(symbol_name_1),
                    ArgumentOfRichStringAbsStx.of_str(plain_string1),
                    ArgumentOfRichStringAbsStx.of_str_until_eol(
                        remaining_part_of_current_line_with_sym_ref),
                ],
                Arrangement(
                    SymbolContext.symbol_table_of_contexts([
                        StringSymbolContext.of_arbitrary_value(symbol_name_1),
                        StringSymbolContext.of_arbitrary_value(symbol_name_2),
                    ])),
                Expectation(
                    elements=[
                        list_sdvs.symbol_element(
                            reference_to__on_direct_and_indirect(
                                symbol_name_1)),
                        list_sdvs.str_element(plain_string1),
                        list_sdvs.string_element(
                            string_sdvs.from_fragments([
                                string_sdvs.str_fragment('before'),
                                string_sdvs.symbol_fragment(
                                    reference_to__on_direct_and_indirect(
                                        symbol_name_2)),
                                string_sdvs.str_fragment('after'),
                            ]))
                    ],
                    validators=asrt.is_empty_sequence,
                    references=asrt.matches_sequence([
                        asrt_sym_ref.matches_reference_2(
                            symbol_name_1,
                            asrt_data_rest.is__w_str_rendering()),
                        asrt_sym_ref.matches_reference_2(
                            symbol_name_2,
                            asrt_data_rest.is__w_str_rendering()),
                    ]),
                )),
        ]
        # ACT & ASSERT #
        _test_cases_w_source_variants(self, cases)
Ejemplo n.º 15
0
    def test_remaining_part_of_current_line_as_literal(self):
        # ARRANGE #
        symbol_name = 'symbol_name'
        str_with_space_and_invalid_token_syntax = 'before and after space, ' + SOFT_QUOTE_CHAR + 'after quote'

        cases = [
            Case.of(
                'string with one space after marker, and no space at EOL',
                ArgumentOfRichStringAbsStx.of_str_until_eol(
                    str_with_space_and_invalid_token_syntax),
                ARRANGEMENT__NEUTRAL,
                Expectation(
                    elements=[
                        list_sdvs.str_element(
                            str_with_space_and_invalid_token_syntax)
                    ],
                    validators=asrt.is_empty_sequence,
                    references=asrt.is_empty_sequence,
                )),
            Case.of(
                'with surrounding space',
                ArgumentOfRichStringAbsStx.of_str_until_eol(
                    '   ' + str_with_space_and_invalid_token_syntax + '  \t '),
                ARRANGEMENT__NEUTRAL,
                Expectation(
                    elements=[
                        list_sdvs.str_element(
                            str_with_space_and_invalid_token_syntax)
                    ],
                    validators=asrt.is_empty_sequence,
                    references=asrt.is_empty_sequence,
                )),
            Case.of(
                'with symbol reference',
                ArgumentOfRichStringAbsStx.of_str_until_eol(''.join([
                    'before',
                    symbol_reference_syntax_for_name(symbol_name), 'after'
                ])),
                Arrangement(
                    StringSymbolContext.of_arbitrary_value(
                        symbol_name).symbol_table),
                Expectation(
                    elements=[
                        list_sdvs.string_element(
                            string_sdvs.from_fragments([
                                string_sdvs.str_fragment('before'),
                                string_sdvs.symbol_fragment(
                                    reference_to__on_direct_and_indirect(
                                        symbol_name)),
                                string_sdvs.str_fragment('after'),
                            ]))
                    ],
                    validators=asrt.is_empty_sequence,
                    references=asrt.matches_sequence([
                        asrt_sym_ref.matches_reference_2(
                            symbol_name, asrt_data_rest.is__w_str_rendering())
                    ]),
                )),
        ]
        # ACT & ASSERT #
        _test_cases_w_source_variants(self, cases)
Ejemplo n.º 16
0
def is_reference_to_string__w_all_indirect_refs_are_strings(symbol_name: str) -> Assertion[SymbolReference]:
    return matches_reference_2(
        symbol_name,
        asrt_data_ref_restriction.is__string__w_all_indirect_refs_are_strings()
    )
def symbol_usage_equals_symbol_reference(expected: SymbolReference) -> ValueAssertion[SymbolUsage]:
    return asrt.is_instance_with(
        SymbolUsage,
        asrt_sym_ref.matches_reference_2(
            expected.name,
            equals_data_type_reference_restrictions(expected.restrictions)))
Ejemplo n.º 18
0
 def test(self):
     single_token_value = 'single_token_value'
     single_token_value_1 = 'single_token_value_1'
     single_token_value_2 = 'single_token_value_2'
     symbol_name = 'a_symbol_name'
     cases = [
         Case(
             'multiple string constants on line that is the last line',
             source=remaining_source(single_token_value_1 + ' ' +
                                     single_token_value_2),
             expectation=Expectation(
                 elements=[
                     list_sdvs.str_element(single_token_value_1),
                     list_sdvs.str_element(single_token_value_2)
                 ],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'multiple string constants on line that is followed by an empty line',
             source=remaining_source(
                 single_token_value_1 + ' ' + single_token_value_2, ['']),
             expectation=Expectation(
                 elements=[
                     list_sdvs.str_element(single_token_value_1),
                     list_sdvs.str_element(single_token_value_2)
                 ],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'multiple string constants on line that is followed by a non-empty line',
             source=remaining_source(
                 single_token_value_1 + ' ' + single_token_value_2, ['  ']),
             expectation=Expectation(
                 elements=[
                     list_sdvs.str_element(single_token_value_1),
                     list_sdvs.str_element(single_token_value_2)
                 ],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'symbol-reference and string constant on first line',
             source=remaining_source('{sym_ref} {string_constant}'.format(
                 sym_ref=symbol_reference_syntax_for_name(symbol_name),
                 string_constant=single_token_value)),
             expectation=Expectation(
                 elements=[
                     list_sdvs.symbol_element(
                         reference_to__on_direct_and_indirect(symbol_name)),
                     list_sdvs.str_element(single_token_value)
                 ],
                 references=asrt.matches_sequence([
                     asrt_sym_ref.matches_reference_2(
                         symbol_name, asrt_data_rest.is__w_str_rendering())
                 ]),
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'complex element (sym-ref and str const) and string constant, '
             'followed by space, '
             'followed by non-empty line',
             source=remaining_source(
                 symbol_reference_syntax_for_name(symbol_name) +
                 single_token_value + ' ' + single_token_value_1, ['   ']),
             expectation=Expectation(
                 elements=[
                     list_sdvs.string_element(
                         string_sdvs.from_fragments(
                             [
                                 string_sdvs.symbol_fragment(
                                     SymbolReference(
                                         symbol_name,
                                         reference_restrictions.
                                         is_any_type_w_str_rendering()), ),
                                 string_sdvs.str_fragment(
                                     single_token_value),
                             ])),
                     list_sdvs.str_element(single_token_value_1),
                 ],
                 references=asrt.matches_sequence([
                     asrt_sym_ref.matches_reference_2(
                         symbol_name, asrt_data_rest.is__w_str_rendering())
                 ]),
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'multiple string constants on line followed by r-paren',
             source=remaining_source(
                 ' '.join((single_token_value_1, single_token_value_2,
                           reserved_words.PAREN_END, 'constant')), ['  ']),
             expectation=Expectation(
                 elements=[
                     list_sdvs.str_element(single_token_value_1),
                     list_sdvs.str_element(single_token_value_2)
                 ],
                 source=asrt_source.source_is_not_at_end(
                     current_line_number=asrt.equals(1),
                     remaining_part_of_current_line=asrt.equals(' '.join(
                         (reserved_words.PAREN_END, 'constant'))))),
         ),
         Case(
             '1st string on first line, followed by continuation-token, followed by line with 2nd string',
             source=remaining_source(
                 single_token_value_1 + ' ' + defs.CONTINUATION_TOKEN,
                 [single_token_value_2]),
             expectation=Expectation(
                 elements=[
                     list_sdvs.str_element(single_token_value_1),
                     list_sdvs.str_element(single_token_value_2)
                 ],
                 source=asrt_source.is_at_end_of_line(2)),
         ),
         Case(
             'multiple elements on two lines, separated by continuation token',
             source=remaining_source('a b ' + defs.CONTINUATION_TOKEN,
                                     ['  c d  ']),
             expectation=Expectation(
                 elements=[
                     list_sdvs.str_element('a'),
                     list_sdvs.str_element('b'),
                     list_sdvs.str_element('c'),
                     list_sdvs.str_element('d'),
                 ],
                 source=asrt_source.is_at_end_of_line(2)),
         ),
     ]
     # ACT & ASSERT #
     _test_cases(self, cases)
Ejemplo n.º 19
0
 def reference_assertion__path(
         self, symbol_name: str) -> Assertion[SymbolReference]:
     return asrt_sym_ref.matches_reference_2(
         symbol_name,
         asrt_data_ref_restriction.equals__w_str_rendering(
             self.reference_restriction__path))
Ejemplo n.º 20
0
 def test(self):
     single_token_value = 'single_token_value'
     string_symbol = NameAndValue('string_symbol_name', 'string symbol value')
     cases = [
         Case('single string constant, at end of line, on the last line',
              source=
              remaining_source(single_token_value),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value)],
                          source=
                          assert_source(is_at_eof=asrt.is_true)),
              ),
         Case('single symbol reference, at end of line, on the last line',
              source=
              remaining_source(symbol_reference_syntax_for_name(string_symbol.name)),
              expectation=
              Expectation(elements=
                          [list_resolvers.symbol_element(symbol_reference(string_symbol.name))],
                          source=
                          assert_source(is_at_eof=asrt.is_true),
                          references=
                          asrt.matches_sequence([asrt_sym_ref.matches_reference_2(
                              string_symbol.name,
                              is_any_data_type_reference_restrictions())
                          ])),
              ),
         Case('complex element (str const and sym-refs), at end of line, on the last line',
              source=
              remaining_source(single_token_value +
                               symbol_reference_syntax_for_name(string_symbol.name)),
              expectation=
              Expectation(
                  elements=
                  [
                      list_resolvers.string_element(string_resolvers.from_fragments([
                          string_resolvers.str_fragment(single_token_value),
                          string_resolvers.symbol_fragment(
                              SymbolReference(string_symbol.name,
                                              reference_restrictions.is_any_data_type())
                          ),
                      ]))],
                  references=
                  asrt.matches_sequence([asrt_sym_ref.matches_reference_2(
                      string_symbol.name,
                      is_any_data_type_reference_restrictions())
                  ]),
                  source=
                  asrt_source.is_at_end_of_line(1)),
              ),
         Case('single element, followed by more than one space, on the last line',
              source=
              remaining_source(single_token_value + '  ',
                               []),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value)],
                          source=
                          asrt_source.is_at_line(1, ' ')),
              ),
         Case('single element, followed by single space, on the last line',
              source=
              remaining_source(single_token_value + ' ',
                               []),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value)],
                          source=
                          asrt_source.is_at_end_of_line(1)),
              ),
         Case('single element, followed by space, followed by empty line',
              source=
              remaining_source(single_token_value + '  ',
                               ['']),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value)],
                          source=
                          asrt_source.is_at_line(1, ' ')),
              ),
         Case('single element, at end of line, followed by line with only space',
              source=
              remaining_source(single_token_value,
                               ['   ']),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value)],
                          source=
                          asrt_source.is_at_end_of_line(1)),
              ),
         Case('single element, followed by space, followed by line with only space',
              source=
              remaining_source(single_token_value + '  ',
                               ['   ']),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value)],
                          source=
                          asrt_source.is_at_line(1, ' ')),
              ),
         Case('single element, at end of line, followed by line with invalid quoting',
              source=
              remaining_source(single_token_value,
                               ['"   ']),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value)],
                          source=
                          asrt_source.is_at_end_of_line(1)),
              ),
     ]
     # ACT & ASSERT #
     _test_cases(self, cases)
Ejemplo n.º 21
0
 def test(self):
     single_token_value = 'single_token_value'
     single_token_value_1 = 'single_token_value_1'
     single_token_value_2 = 'single_token_value_2'
     symbol_name = 'a_symbol_name'
     cases = [
         Case('multiple string constants on line that is the last line',
              source=
              remaining_source(single_token_value_1 + ' ' + single_token_value_2),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value_1),
                           list_resolvers.str_element(single_token_value_2)
                           ],
                          source=asrt_source.is_at_end_of_line(1)),
              ),
         Case('multiple string constants on line that is followed by an empty line',
              source=
              remaining_source(single_token_value_1 + ' ' + single_token_value_2,
                               ['']),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value_1),
                           list_resolvers.str_element(single_token_value_2)
                           ],
                          source=
                          asrt_source.is_at_end_of_line(1)),
              ),
         Case('multiple string constants on line that is followed by a non-empty line',
              source=
              remaining_source(single_token_value_1 + ' ' + single_token_value_2,
                               ['  ']),
              expectation=
              Expectation(elements=
                          [list_resolvers.str_element(single_token_value_1),
                           list_resolvers.str_element(single_token_value_2)
                           ],
                          source=
                          asrt_source.is_at_end_of_line(1)),
              ),
         Case('symbol-reference and string constant on first line',
              source=
              remaining_source('{sym_ref} {string_constant}'.format(
                  sym_ref=symbol_reference_syntax_for_name(symbol_name),
                  string_constant=single_token_value)),
              expectation=
              Expectation(elements=
                          [list_resolvers.symbol_element(symbol_reference(symbol_name)),
                           list_resolvers.str_element(single_token_value)
                           ],
                          references=
                          asrt.matches_sequence([asrt_sym_ref.matches_reference_2(
                              symbol_name,
                              is_any_data_type_reference_restrictions())
                          ]),
                          source=
                          asrt_source.is_at_end_of_line(1)),
              ),
         Case('complex element (sym-ref and str const) and string constant, '
              'followed by space, '
              'followed by non-empty line',
              source=
              remaining_source(symbol_reference_syntax_for_name(symbol_name) +
                               single_token_value +
                               ' ' +
                               single_token_value_1,
                               ['   ']),
              expectation=
              Expectation(
                  elements=
                  [
                      list_resolvers.string_element(string_resolvers.from_fragments([
                          string_resolvers.symbol_fragment(SymbolReference(symbol_name,
                                                                           reference_restrictions.is_any_data_type())),
                          string_resolvers.str_fragment(single_token_value),
                      ])),
                      list_resolvers.str_element(single_token_value_1),
                  ],
                  references=
                  asrt.matches_sequence([asrt_sym_ref.matches_reference_2(
                      symbol_name,
                      is_any_data_type_reference_restrictions())
                  ]),
                  source=
                  asrt_source.is_at_end_of_line(1)),
              ),
     ]
     # ACT & ASSERT #
     _test_cases(self, cases)
def is_reference_to_data_type_symbol(symbol_name: str) -> ValueAssertion[su.SymbolReference]:
    return matches_reference_2(symbol_name,
                               is_any_data_type_reference_restrictions())
def is_reference_to_data_category_symbol(symbol_name: str) -> ValueAssertion[SymbolReference]:
    return asrt_sym_ref.matches_reference_2(symbol_name,
                                            is_type_category_restriction(TypeCategory.DATA))
Ejemplo n.º 24
0
def matches_data_type_symbol_reference(symbol_name: str,
                                       restrictions: WithStrRenderingTypeRestrictions) -> Assertion[
    SymbolReference]:
    return asrt_sym_ref.matches_reference_2(symbol_name,
                                            asrt_w_str_rend_rest.equals__w_str_rendering(restrictions))
Ejemplo n.º 25
0
def is_reference_to__files_source(symbol_name: str) -> Assertion[SymbolReference]:
    return asrt_sym_ref.matches_reference_2(
        symbol_name,
        IS_FILES_SOURCE_REFERENCE_RESTRICTION,
    )
Ejemplo n.º 26
0
 def test(self):
     single_token_value = 'single_token_value'
     string_symbol = NameAndValue('string_symbol_name',
                                  'string symbol value')
     cases = [
         Case(
             'single string constant, at end of line, on the last line',
             source=remaining_source(single_token_value),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=assert_source(is_at_eof=asrt.is_true)),
         ),
         Case(
             'single symbol reference, at end of line, on the last line',
             source=remaining_source(
                 symbol_reference_syntax_for_name(string_symbol.name)),
             expectation=Expectation(
                 elements=[
                     list_sdvs.symbol_element(
                         reference_to__on_direct_and_indirect(
                             string_symbol.name))
                 ],
                 source=assert_source(is_at_eof=asrt.is_true),
                 references=asrt.matches_sequence([
                     asrt_sym_ref.matches_reference_2(
                         string_symbol.name,
                         asrt_data_rest.is__w_str_rendering())
                 ])),
         ),
         Case(
             'complex element (str const and sym-refs), at end of line, on the last line',
             source=remaining_source(
                 single_token_value +
                 symbol_reference_syntax_for_name(string_symbol.name)),
             expectation=Expectation(
                 elements=[
                     list_sdvs.string_element(
                         string_sdvs.from_fragments(
                             [
                                 string_sdvs.str_fragment(
                                     single_token_value),
                                 string_sdvs.symbol_fragment(
                                     SymbolReference(
                                         string_symbol.name,
                                         reference_restrictions.
                                         is_any_type_w_str_rendering(),
                                     )),
                             ]))
                 ],
                 references=asrt.matches_sequence([
                     asrt_sym_ref.matches_reference_2(
                         string_symbol.name,
                         asrt_data_rest.is__w_str_rendering())
                 ]),
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'single element, followed by more than one space, on the last line',
             source=remaining_source(single_token_value + '  ', []),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'single element, followed by single space, on the last line',
             source=remaining_source(single_token_value + ' ', []),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'single element, followed by space, followed by empty line',
             source=remaining_source(single_token_value + '  ', ['']),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'single element, at end of line, followed by line with only space',
             source=remaining_source(single_token_value, ['   ']),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'single element, followed by space, followed by line with only space',
             source=remaining_source(single_token_value + '  ', ['   ']),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'single element, at end of line, followed by line with invalid quoting',
             source=remaining_source(single_token_value, ['"   ']),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.is_at_end_of_line(1)),
         ),
         Case(
             'continuation token, followed by line with single element',
             source=remaining_source(defs.CONTINUATION_TOKEN,
                                     [single_token_value]),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.is_at_end_of_line(2)),
         ),
         Case(
             'single element, followed by continuation token, followed by empty line',
             source=remaining_source(
                 single_token_value + ' ' + defs.CONTINUATION_TOKEN, ['']),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.is_at_end_of_line(2)),
         ),
         Case(
             'single element, followed by r-paren and more',
             source=remaining_source(
                 ' '.join((single_token_value, reserved_words.PAREN_END,
                           'const_str')), ['"   ']),
             expectation=Expectation(
                 elements=[list_sdvs.str_element(single_token_value)],
                 source=asrt_source.source_is_not_at_end(
                     current_line_number=asrt.equals(1),
                     remaining_part_of_current_line=asrt.equals(' '.join(
                         (reserved_words.PAREN_END, 'const_str'))))),
         ),
     ]
     # ACT & ASSERT #
     _test_cases(self, cases)
Ejemplo n.º 27
0
def is_reference_to__file_name_part(symbol_name: str) -> Assertion[SymbolReference]:
    return asrt_sym_ref.matches_reference_2(
        symbol_name,
        IS_REFERENCE__STRING__W_ALL_INDIRECT_REFS_ARE_STRINGS,
    )
Ejemplo n.º 28
0
 def reference_assertion(self,
                         symbol_name: str) -> Assertion[SymbolReference]:
     return asrt_sym_ref.matches_reference_2(
         symbol_name, asrt_data_rest.is__w_str_rendering())
def equals_symbol_reference(expected: SymbolReference) -> ValueAssertion[SymbolReference]:
    return asrt_sym_ref.matches_reference_2(expected.name,
                                            equals_data_type_reference_restrictions(expected.restrictions))