Exemplo n.º 1
0
 def test_assignment_of_symbols_and_constant_text_within_soft_quotes(self):
     # ARRANGE #
     referred_symbol1 = SymbolWithReferenceSyntax('referred_symbol_1')
     referred_symbol2 = SymbolWithReferenceSyntax('referred_symbol_2')
     name_of_defined_symbol = 'defined_symbol'
     source = single_line_source('{string_type} {name} = {soft_quote}{sym_ref1} between {sym_ref2}{soft_quote}',
                                 soft_quote=SOFT_QUOTE_CHAR,
                                 name=name_of_defined_symbol,
                                 sym_ref1=referred_symbol1,
                                 sym_ref2=referred_symbol2)
     expected_resolver = string_resolver_from_fragments([
         symbol(referred_symbol1.name),
         constant(' between '),
         symbol(referred_symbol2.name),
     ])
     container_of_expected_resolver = container(expected_resolver)
     expected_definition = SymbolDefinition(name_of_defined_symbol,
                                            container_of_expected_resolver)
     expectation = Expectation(
         symbol_usages=asrt.matches_sequence([
             vs_asrt.equals_symbol(expected_definition, ignore_source_line=True),
         ]),
         symbols_after_main=assert_symbol_table_is_singleton(
             name_of_defined_symbol,
             equals_container(container_of_expected_resolver),
         )
     )
     # ACT & ASSERT #
     self._check(source, ArrangementWithSds(), expectation)
Exemplo n.º 2
0
 def test_assignment_of_symbols_and_constant_text_within_soft_quotes(self):
     # ARRANGE #
     referred_symbol1 = SymbolWithReferenceSyntax('referred_symbol_1')
     referred_symbol2 = SymbolWithReferenceSyntax('referred_symbol_2')
     assigned_symbol = StringSymbolContext.of_sdv(
         'defined_symbol',
         string_sdv_from_fragments([
             symbol(referred_symbol1.name),
             constant(' between '),
             symbol(referred_symbol2.name),
         ]))
     source = single_line_source('{string_type} {name} = {soft_quote}{sym_ref1} between {sym_ref2}{soft_quote}',
                                 soft_quote=SOFT_QUOTE_CHAR,
                                 name=assigned_symbol.name,
                                 sym_ref1=referred_symbol1,
                                 sym_ref2=referred_symbol2)
     expectation = Expectation.phase_agnostic(
         symbol_usages=asrt.matches_sequence([
             assigned_symbol.assert_matches_definition_of_sdv,
         ]),
         symbols_after_main=assert_symbol_table_is_singleton(
             assigned_symbol.name,
             assigned_symbol.value.assert_matches_container_of_sdv,
         )
     )
     # ACT & ASSERT #
     INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Exemplo n.º 3
0
 def runTest(self):
     cases = [
         ('', []),
         ('abc', [constant('abc')]),
         (sut.symbol_reference_syntax_for_name('sym_name'),
          [symbol('sym_name')]),
         (sut.symbol_reference_syntax_for_name('sym_NAME_1'),
          [symbol('sym_NAME_1')]),
         (sut.symbol_reference_syntax_for_name('not a symbol name'), [
             constant(
                 sut.symbol_reference_syntax_for_name('not a symbol name'))
         ]),
         (sut.symbol_reference_syntax_for_name(''),
          [constant(sut.symbol_reference_syntax_for_name(''))]),
         (sut.symbol_reference_syntax_for_name('  '),
          [constant(sut.symbol_reference_syntax_for_name('  '))]),
         (sut.symbol_reference_syntax_for_name('1isAValidSymbolName'),
          [symbol('1isAValidSymbolName')]),
         ('const{sym_ref}'.format(
             sym_ref=sut.symbol_reference_syntax_for_name('sym_name')),
          [constant('const'), symbol('sym_name')]),
         ('{sym_ref}const'.format(
             sym_ref=sut.symbol_reference_syntax_for_name('sym_name')),
          [symbol('sym_name'), constant('const')]),
         ('{sym_ref1}{sym_ref2}'.format(
             sym_ref1=sut.symbol_reference_syntax_for_name('sym_name1'),
             sym_ref2=sut.symbol_reference_syntax_for_name('sym_name2')),
          [symbol('sym_name1'), symbol('sym_name2')]),
         ('{sym_begin}{sym_ref}'.format(
             sym_begin=sut.SYMBOL_REFERENCE_BEGIN,
             sym_ref=sut.symbol_reference_syntax_for_name('sym_name')),
          [constant(sut.SYMBOL_REFERENCE_BEGIN),
           symbol('sym_name')]),
         ('{sym_ref1}const 1{not_a_symbol_name1}{not_a_symbol_name2}const 2{sym_ref2}'
          .format(
              sym_ref1=sut.symbol_reference_syntax_for_name('sym_name1'),
              not_a_symbol_name1=sut.symbol_reference_syntax_for_name(
                  'not a sym1'),
              not_a_symbol_name2=sut.symbol_reference_syntax_for_name(
                  'not a sym2'),
              sym_ref2=sut.symbol_reference_syntax_for_name('sym_name2')),
          [
              symbol('sym_name1'),
              constant('const 1' +
                       sut.symbol_reference_syntax_for_name('not a sym1') +
                       sut.symbol_reference_syntax_for_name('not a sym2') +
                       'const 2'),
              symbol('sym_name2')
          ]),
     ]
     for source, expected in cases:
         with self.subTest(source=source):
             actual = sut.split(source)
             self.assertEqual(expected, actual)
Exemplo n.º 4
0
    def test_assignment_of_single_symbol_reference(self):
        # ARRANGE #
        referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
        expected_sdv = string_sdv_from_fragments([symbol(referred_symbol.name),
                                                  constant('\n')])
        assigned_symbol = StringSymbolContext.of_sdv(
            'defined_symbol',
            expected_sdv,
        )
        sb = SB.new_with(referred_symbol=referred_symbol,
                         name_of_defined_symbol=assigned_symbol.name)

        source = sb.lines(
            here_doc_lines(first_line_start='{string_type} {name_of_defined_symbol} = ',
                           marker='EOF',
                           contents_lines=[str(referred_symbol)])
        )
        # EXPECTATION #
        expectation = Expectation.phase_agnostic(
            symbol_usages=asrt.matches_sequence([
                assigned_symbol.assert_matches_definition_of_sdv,
            ]),
            symbols_after_main=assert_symbol_table_is_singleton(
                assigned_symbol.name,
                assigned_symbol.value.assert_matches_container_of_sdv,
            )
        )
        # ACT & ASSERT #
        INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Exemplo n.º 5
0
def successful_parse_of_single_symbol() -> List[TC]:
    symbol_ref = SymbolWithReferenceSyntax('validSymbol_name_1')
    single_symbol = [symbol(symbol_ref.name)]
    return [
        TC(
            _src('{symbol_reference}', symbol_reference=symbol_ref),
            Expectation(
                fragments=single_symbol,
                token_stream=assert_token_stream(is_null=asrt.is_true),
            )),
        TC(
            _src('{symbol_reference} rest', symbol_reference=symbol_ref),
            Expectation(
                fragments=single_symbol,
                token_stream=assert_token_stream(
                    head_token=assert_token_string_is('rest')),
            )),
        TC(
            _src('{soft_quote}{symbol_reference}{soft_quote} rest',
                 soft_quote=SOFT_QUOTE_CHAR,
                 symbol_reference=symbol_ref),
            Expectation(
                fragments=single_symbol,
                token_stream=assert_token_stream(
                    head_token=assert_token_string_is('rest')),
            )),
    ]
Exemplo n.º 6
0
    def test_assignment_of_single_symbol_reference(self):
        # ARRANGE #
        referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
        name_of_defined_symbol = 'defined_symbol'
        sb = SB.new_with(referred_symbol=referred_symbol,
                         name_of_defined_symbol=name_of_defined_symbol)

        source = sb.lines(
            here_doc_lines(first_line_start='{string_type} {name_of_defined_symbol} = ',
                           marker='EOF',
                           contents_lines=[str(referred_symbol)])
        )
        # EXPECTATION #
        expected_resolver = string_resolver_from_fragments([symbol(referred_symbol.name),
                                                            constant('\n')])
        container_of_expected_resolver = container(expected_resolver)
        expected_definition = SymbolDefinition(name_of_defined_symbol,
                                               container_of_expected_resolver)
        expectation = Expectation(
            symbol_usages=asrt.matches_sequence([
                vs_asrt.equals_symbol(expected_definition, ignore_source_line=True),
            ]),
            symbols_after_main=assert_symbol_table_is_singleton(
                name_of_defined_symbol,
                equals_container(container_of_expected_resolver),
            )
        )
        # ACT & ASSERT #
        self._check(source, ArrangementWithSds(), expectation)
Exemplo n.º 7
0
 def parse_from_token_parser(self, token_parser: TokenParser) -> StringSdv:
     either_sym_name_or_string = self._sym_name_or_string_parser.parse_from_token_parser(
         token_parser)
     if either_sym_name_or_string.is_right():
         return either_sym_name_or_string.right()
     else:
         return parse_string.string_sdv_from_fragments(
             [symbol_syntax.symbol(either_sym_name_or_string.left())],
             parse_string.DEFAULT_CONFIGURATION.reference_restrictions,
         )
Exemplo n.º 8
0
def successful_parse_of_complex_structure() -> List[TC]:
    return [
        TC(
            _src(
                '  {soft_quote}{sym_ref1}const 1{not_a_symbol_name1}{not_a_symbol_name2}const 2{sym_ref2}{soft_quote}',
                soft_quote=SOFT_QUOTE_CHAR,
                sym_ref1=symbol_reference_syntax_for_name('sym_name1'),
                not_a_symbol_name1=symbol_reference_syntax_for_name(
                    'not a sym1'),
                not_a_symbol_name2=symbol_reference_syntax_for_name(
                    'not a sym2'),
                sym_ref2=symbol_reference_syntax_for_name('sym_name2')),
            Expectation(
                fragments=[
                    symbol('sym_name1'),
                    constant('const 1' +
                             symbol_reference_syntax_for_name('not a sym1') +
                             symbol_reference_syntax_for_name('not a sym2') +
                             'const 2'),
                    symbol('sym_name2')
                ],
                token_stream=assert_token_stream(is_null=asrt.is_true),
            ))
    ]
Exemplo n.º 9
0
 def test_successful_parse(self):
     # ARRANGE #
     symbol_ref = SymbolWithReferenceSyntax('validSymbol_name_1')
     single_symbol = [symbol(symbol_ref.name)]
     parse_source = ParseSource(
         _src('{soft_quote}{symbol_reference}{soft_quote} rest',
              soft_quote=SOFT_QUOTE_CHAR,
              symbol_reference=symbol_ref))
     # ACT #
     actual = sut.parse_string_sdv_from_parse_source(parse_source)
     # ASSERT #
     assertion_on_result = assert_equals_string_sdv(single_symbol)
     assertion_on_result.apply_with_message(self, actual, 'result')
     assertion_on_parse_source = assert_source(
         remaining_part_of_current_line=asrt.equals('rest'))
     assertion_on_parse_source.apply_with_message(self, parse_source,
                                                  'parse_source')
Exemplo n.º 10
0
 def test_assignment_of_single_symbol_reference(self):
     # ARRANGE #
     referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
     assigned_symbol = StringSymbolContext.of_sdv('defined_symbol',
                                                  string_sdv_from_fragments([symbol(referred_symbol.name)]))
     source = single_line_source('{string_type} {name} = {symbol_reference}',
                                 name=assigned_symbol.name,
                                 symbol_reference=referred_symbol)
     expectation = Expectation.phase_agnostic(
         symbol_usages=asrt.matches_sequence([
             assigned_symbol.assert_matches_definition_of_sdv,
         ]),
         symbols_after_main=assert_symbol_table_is_singleton(
             assigned_symbol.name,
             assigned_symbol.value.assert_matches_container_of_sdv,
         )
     )
     # ACT & ASSERT #
     INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Exemplo n.º 11
0
 def test_assignment_of_single_symbol_reference(self):
     # ARRANGE #
     referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
     name_of_defined_symbol = 'defined_symbol'
     source = single_line_source('{string_type} {name} = {symbol_reference}',
                                 name=name_of_defined_symbol,
                                 symbol_reference=referred_symbol)
     expected_resolver = string_resolver_from_fragments([symbol(referred_symbol.name)])
     container_of_expected_resolver = container(expected_resolver)
     expected_definition = SymbolDefinition(name_of_defined_symbol,
                                            container_of_expected_resolver)
     expectation = Expectation(
         symbol_usages=asrt.matches_sequence([
             vs_asrt.equals_symbol(expected_definition, ignore_source_line=True),
         ]),
         symbols_after_main=assert_symbol_table_is_singleton(
             name_of_defined_symbol,
             equals_container(container_of_expected_resolver),
         )
     )
     # ACT & ASSERT #
     self._check(source, ArrangementWithSds(), expectation)
Exemplo n.º 12
0
 def runTest(self):
     cases = [
         ('', []),
         ('abc', [constant('abc')]),
         (
             sut.symbol_reference_syntax_for_name('sym_name'),
             [symbol('sym_name')]
         ),
         (
             sut.symbol_reference_syntax_for_name('sym_NAME_1'),
             [symbol('sym_NAME_1')]
         ),
         (
             sut.symbol_reference_syntax_for_name('not a symbol name'),
             [constant(sut.symbol_reference_syntax_for_name('not a symbol name'))]
         ),
         (
             sut.symbol_reference_syntax_for_name(''),
             [constant(sut.symbol_reference_syntax_for_name(''))]
         ),
         (
             sut.symbol_reference_syntax_for_name('  '),
             [constant(sut.symbol_reference_syntax_for_name('  '))]
         ),
         (
             sut.symbol_reference_syntax_for_name('1isAValidSymbolName'),
             [symbol('1isAValidSymbolName')]
         ),
         (
             'const{sym_ref}'.format(sym_ref=sut.symbol_reference_syntax_for_name('sym_name')),
             [constant('const'),
              symbol('sym_name')]
         ),
         (
             '{sym_ref}const'.format(sym_ref=sut.symbol_reference_syntax_for_name('sym_name')),
             [symbol('sym_name'),
              constant('const')]
         ),
         (
             '{sym_ref1}{sym_ref2}'.format(
                 sym_ref1=sut.symbol_reference_syntax_for_name('sym_name1'),
                 sym_ref2=sut.symbol_reference_syntax_for_name('sym_name2')),
             [symbol('sym_name1'),
              symbol('sym_name2')]
         ),
         (
             '{sym_begin}{sym_ref}'.format(
                 sym_begin=sut.SYMBOL_REFERENCE_BEGIN,
                 sym_ref=sut.symbol_reference_syntax_for_name('sym_name')),
             [constant(sut.SYMBOL_REFERENCE_BEGIN),
              symbol('sym_name')]
         ),
         (
             '{sym_ref1}const 1{not_a_symbol_name1}{not_a_symbol_name2}const 2{sym_ref2}'.format(
                 sym_ref1=sut.symbol_reference_syntax_for_name('sym_name1'),
                 not_a_symbol_name1=sut.symbol_reference_syntax_for_name('not a sym1'),
                 not_a_symbol_name2=sut.symbol_reference_syntax_for_name('not a sym2'),
                 sym_ref2=sut.symbol_reference_syntax_for_name('sym_name2')),
             [symbol('sym_name1'),
              constant('const 1' +
                       sut.symbol_reference_syntax_for_name('not a sym1') +
                       sut.symbol_reference_syntax_for_name('not a sym2') +
                       'const 2'),
              symbol('sym_name2')]
         ),
     ]
     for source, expected in cases:
         with self.subTest(source=source):
             actual = sut.split(source)
             self.assertEqual(expected,
                              actual)