def runTest(self): # ARRANGE # files_matcher = FilesMatcherSymbolContextOfPrimitiveConstant( 'MATCHER', True, ) after_bin_op = 'after bin op' # ACT & ASSERT # fsm_argument = fsm_args.conjunction([ fsm_args.SymbolReference(files_matcher.name), fsm_args.Custom(after_bin_op), ]) integration_check.CHECKER__PARSE_SIMPLE.check( self, source=args.DirContents(fsm_argument, ).as_remaining_source, input_=integration_check.current_directory(), arrangement=arrangement_w_tcds( symbols=files_matcher.symbol_table, ), expectation=Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=fsm_argument.operator + ' ' + after_bin_op), symbol_references=files_matcher.references_assertion), ExecutionExpectation( main_result=asrt_matching_result.matches_value( files_matcher.result_value))), )
def runTest(self): # ARRANGE # model = model_constructor.of_str(self, 'string with at least one line') line_matcher = LineMatcherSymbolContextOfPrimitiveConstant( 'MATCHER', True, ) after_bin_op = 'after bin op' lm_argument = lm_args.And([ lm_args.SymbolReference(line_matcher.name), lm_args.Custom(after_bin_op), ]) for quantifier in Quantifier: arguments = args2.Quantification(quantifier, lm_argument.as_str) with self.subTest(quantifier): # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check( self, source=arguments.as_remaining_source, input_=model, arrangement=arrangement_w_tcds( symbols=line_matcher.symbol_table, ), expectation=Expectation( ParseExpectation(source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=lm_argument. operator_name + ' ' + after_bin_op), symbol_references=line_matcher. references_assertion), ExecutionExpectation( main_result=asrt_matching_result.matches_value( line_matcher.result_value))), )
def runTest(self): string_matcher = StringMatcherSymbolContextOfPrimitiveConstant( 'STRING_MATCHER', True, ) after_bin_op = 'after bin op' integration_check.CHECKER__PARSE_SIMPLE.check( self, source=lm_args.Contents( sm_args2.conjunction([ sm_args2.SymbolReference(string_matcher.name), sm_args2.Custom(after_bin_op), ]), ).as_remaining_source, input_=models.ARBITRARY_MODEL, arrangement=arrangement_wo_tcds( symbols=string_matcher.symbol_table, ), expectation=Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=logic.AND_OPERATOR_NAME + ' ' + after_bin_op), symbol_references=string_matcher.references_assertion), ExecutionExpectation( main_result=asrt_matching_result.matches_value__w_header( asrt.equals(string_matcher.result_value), header=TRACE_HEADER_EXPECTATION, ))), )
def runTest(self): after_lhs_expression = logic.AND_OPERATOR_NAME + ' after bin op' integer_matcher = IntegerMatcherSymbolContextOfPrimitiveConstant( 'MATCHER_SYMBOL', True, ) complex_expression = ' '.join( (integer_matcher.name__sym_ref_syntax, after_lhs_expression)) integration_check.CHECKER__PARSE_SIMPLE.check( self, args.NumLines(complex_expression).as_remaining_source, model_constructor.arbitrary(self), arrangement_w_tcds(symbols=integer_matcher.symbol_table, ), Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=after_lhs_expression, ), symbol_references=integer_matcher.references_assertion, ), ExecutionExpectation( main_result=asrt_matching_result.matches_value( integer_matcher.result_value)), ), )
def test_integer_transformer_should_be_parsed_as_simple_expression(self): # ARRANGE # after_lhs_expression = logic.AND_OPERATOR_NAME + ' after bin op' matcher_symbol = IntegerMatcherSymbolContextOfPrimitiveConstant( 'MATCHER_SYMBOL', True, ) complex_expression = ' '.join( (matcher_symbol.name__sym_ref_syntax, after_lhs_expression)) # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check( self, args.NumFiles(complex_expression, ).as_remaining_source, model.arbitrary_model(), arrangement_w_tcds(symbols=matcher_symbol.symbol_table, ), Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=after_lhs_expression, ), symbol_references=matcher_symbol.references_assertion, ), ExecutionExpectation( main_result=asrt_matching_result.matches_value( matcher_symbol.result_value)), ))
def runTest(self): checked_file = File.empty('checked-file.txt') string_matcher = StringMatcherSymbolContextOfPrimitiveConstant( 'STRING_MATCHER', True, ) after_bin_op = 'after bin op' integration_check.CHECKER__PARSE_SIMPLE.check( self, source=fm_args.FileContents( sm_args2.conjunction([ sm_args2.SymbolReference(string_matcher.name), sm_args2.Custom(after_bin_op), ]), ).as_remaining_source, input_=integration_check.constant_relative_file_name( checked_file.name), arrangement=arrangement_w_tcds( symbols=string_matcher.symbol_table, tcds_contents=tcds_populators.in_tc_dir( RelOptionType.REL_ACT, DirContents([checked_file]))), expectation=Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=logic.AND_OPERATOR_NAME + ' ' + after_bin_op), symbol_references=string_matcher.references_assertion), ExecutionExpectation( main_result=asrt_matching_result.matches_value( string_matcher.result_value))), )
def cases_wo_parentheses(expected_int: int) -> List[NSourceCase]: return [ NSourceCase( 'plain int', ParseSource(str(expected_int)), asrt_source.is_at_end_of_line(1), ), NSourceCase( 'plain int followed by other plain int', ParseSource(str(expected_int) + ' 77'), asrt_source.is_at_line(1, '77'), ), NSourceCase( 'plain int followed by end parenthesis', ParseSource(str(expected_int) + ' )'), asrt_source.is_at_line(1, ')'), ), ]
def runTest(self): # ARRANGE # model_contents = DirContents([ Dir('a-dir', [File.empty('a-file-in-pruned-dir')]), ]) file_matcher = FileMatcherSymbolContextOfPrimitiveConstant( 'FILE_MATCHER_SYMBOL', True, ) files_matcher__parsed = FilesMatcherSymbolContext.of_primitive( 'FILES_MATCHER_1', files_matcher_test_impl.FilesMatcherNumFilesTestImpl(1)) symbols = [file_matcher, files_matcher__parsed] files_matcher_bin_op_expr = fsm_args.conjunction([ fm_args.SymbolReferenceWReferenceSyntax( files_matcher__parsed.name), fsm_args.Custom('after bin op'), ]) arguments = fsm_args.Prune( fm_args.SymbolReferenceWReferenceSyntax(file_matcher.name), files_matcher_bin_op_expr, ) model_rel_opt_conf = rel_opt_confs.conf_rel_any(RelOptionType.REL_ACT) # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check( self, arguments.as_remaining_source, models.model_constructor__recursive( model_rel_opt_conf.path_sdv_for_root_dir()), arrangement_w_tcds( symbols=SymbolContext.symbol_table_of_contexts(symbols), tcds_contents=model_rel_opt_conf. populator_for_relativity_option_root(model_contents)), Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=' '.join([ files_matcher_bin_op_expr.operator, files_matcher_bin_op_expr.operands[1].as_str, ])), symbol_references=SymbolContext. references_assertion_of_contexts(symbols), ), ExecutionExpectation( main_result=matcher_assertions.is_matching_success(), ), ), )
def runTest(self): # ARRANGE # transformer = StringTransformerPrimitiveSymbolContext( 'STRING_TRANSFORMER', string_transformers.to_uppercase()) after_bin_op = 'after bin op' after_bin_op_syntax = CustomStringTransformerAbsStx.of_str( after_bin_op) composition_string_transformer = StringTransformerCompositionAbsStx( [transformer.abstract_syntax, after_bin_op_syntax], within_parens=False, allow_elements_on_separate_lines=False, ) expected_source_after_parse = asrt_source.is_at_line( current_line_number=2, remaining_part_of_current_line=' '.join( [composition_string_transformer.operator_name(), after_bin_op]), ) for pgm_and_args_case in pgm_and_args_cases.cases_w_and_wo_argument_list__including_program_reference( ): command_followed_by_transformer = FullProgramAbsStx( pgm_and_args_case.pgm_and_args, transformation=composition_string_transformer, ) symbols = list(pgm_and_args_case.symbols) + [transformer] with self.subTest(command=pgm_and_args_case.name): source = remaining_source( command_followed_by_transformer.tokenization().layout( LayoutSpec.of_default())) # ACT & ASSERT # CHECKER_WO_EXECUTION.check( self, source, None, pgm_and_args_case.mk_arrangement( SymbolContext.symbol_table_of_contexts(symbols)), Expectation( ParseExpectation( source=expected_source_after_parse, symbol_references=SymbolContext. references_assertion_of_contexts(symbols), ), primitive=lambda env: (asrt_pgm_val.matches_program( asrt_command. matches_command(driver=pgm_and_args_case. expected_command_driver(env), arguments=asrt.is_empty_sequence), stdin=asrt_pgm_val.is_no_stdin(), transformer=asrt.matches_singleton_sequence( asrt.is_(transformer.primitive)), ))))
def runTest(self): # ARRANGE # checked_dir_rel_conf = relativity_options.conf_rel_any(RelOptionType.REL_ACT) checked_dir_populator = checked_dir_rel_conf.populator_for_relativity_option_root( DirContents([ File.empty('a-file-so-that-checked-dir-is-not-empty') ] ) ) file_matcher = FileMatcherSymbolContextOfPrimitiveConstant( 'MATCHER', True, ) after_bin_op = 'after bin op' fm_argument = fm_args.conjunction([ fm_args.SymbolReference(file_matcher.name), fm_args.Custom(after_bin_op), ]) # ACT & ASSERT # for quantifier in Quantifier: arguments = args.Quantification(quantifier, fm_argument) with self.subTest(quantifier): # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check( self, source=arguments.as_remaining_source, input_=model.model_constructor__non_recursive( path_sdvs.of_rel_option(checked_dir_rel_conf.relativity) ), arrangement=arrangement_w_tcds( symbols=file_matcher.symbol_table, tcds_contents=checked_dir_populator ), expectation=Expectation( ParseExpectation( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=fm_argument.operator + ' ' + after_bin_op), symbol_references=file_matcher.references_assertion ), ExecutionExpectation( main_result=asrt_matching_result.matches_value(file_matcher.result_value) ) ), )
def runTest(self): model__original = 'the model text' the_model_constructor = model_constructor.of_str(self, model__original) string_transformer = StringTransformerSymbolContext.of_primitive( 'THE_STRING_TRANSFORMER', string_transformers.to_uppercase()) sm_equals = StringMatcherSymbolContext.of_primitive( 'STRING_MATCHER_1', string_matchers.EqualsConstant(model__original.upper())) symbol = [ string_transformer, sm_equals, ] after_bin_op = 'after bin op' sm_conjunction = args2.conjunction([ args2.SymbolReference(sm_equals.name), args2.Custom(after_bin_op), ]) arguments = args2.Transformed(string_transformer.name__sym_ref_syntax, sm_conjunction) integration_check.CHECKER__PARSE_SIMPLE.check( self, source=arguments.as_remaining_source, input_=the_model_constructor, arrangement=arrangement_w_tcds( symbols=SymbolContext.symbol_table_of_contexts(symbol), ), expectation=Expectation( ParseExpectation(source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=' '.join( [sm_conjunction.operator, after_bin_op])), symbol_references=SymbolContext. references_assertion_of_contexts(symbol)), ExecutionExpectation( main_result=asrt_matching_result.matches_value(True))), )
def runTest(self): # ARRANGE # model = ['the line'] line_matcher__constant_false = LineMatcherSymbolContextOfPrimitiveConstant( 'MATCHER', False, ) after_bin_op = 'after bin op' lm_argument = lm_args.And([ lm_args.SymbolReference(line_matcher__constant_false.name), lm_args.Custom(after_bin_op), ]) arguments = st_args.syntax_for_filter_transformer(lm_argument.as_str) # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check( self, source=remaining_source(arguments), input_=model_constructor.of_lines(self, model), arrangement=arrangement_w_tcds( symbols=line_matcher__constant_false.symbol_table, ), expectation=expectation_of_successful_execution( source=asrt_source.is_at_line( current_line_number=1, remaining_part_of_current_line=lm_argument.operator_name + ' ' + after_bin_op, ), symbol_references=line_matcher__constant_false.references_assertion, output_lines=[], may_depend_on_external_resources=True, frozen_may_depend_on_external_resources=asrt.anything_goes(), is_identity_transformer=False, ) )
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)