Exemple #1
0
    def test(self):
        # ARRANGE #

        e = 'between'

        cases = [
            (
                [],
                [],
            ),
            (
                [1],
                [1],
            ),
            (
                [1, 2],
                [1, e, 2],
            ),
            (
                [1, 2, 3],
                [1, e, 2, e, 3],
            ),

        ]
        for case in cases:
            with self.subTest(input=case[0],
                              expected=case[1]):
                # ACT #
                actual = sut.intersperse_list(e, case[0])

                # ASSERT #

                self.assertEqual(case[1], actual)
 def tokenization(self) -> TokenSequence:
     file_specs = collection.intersperse_list(
         TokenSequence.new_line(),
         [fs.tokenization() for fs in self._files])
     return TokenSequence.concat([
         TokenSequence.singleton(self.delimiter__begin),
         TokenSequence.preceded_by_optional_new_line_if_non_empty(
             TokenSequence.concat(file_specs), ),
         TokenSequence.optional_new_line(),
         TokenSequence.singleton(self.delimiter__end),
     ])
Exemple #3
0
    def test_references_SHOULD_be_listed_phase_order(self):
        name_of_existing_symbol = 'STRING_SYMBOL'

        reference_source = sym_def.reference_to(name_of_existing_symbol,
                                                ValueType.STRING)
        case_with_references = File(
            'test.xly',
            lines_content([
                phase_names.SETUP.syntax,
                sym_def.define_string(name_of_existing_symbol, 'value'),
                phase_names.CLEANUP.syntax,
                reference_source,
                phase_names.ASSERT.syntax,
                reference_source,
                phase_names.BEFORE_ASSERT.syntax,
                reference_source,
                phase_names.ACT.syntax,
                reference_source,
                phase_names.SETUP.syntax,
                reference_source,
            ]))

        expected_reference_outputs = [
            output.Reference(
                phase_identifier.SETUP,
                output.LineInFilePosition(case_with_references.name, 12),
                [reference_source]),
            output.Reference(phase_identifier.ACT, None, [reference_source]),
            output.Reference(
                phase_identifier.BEFORE_ASSERT,
                output.LineInFilePosition(case_with_references.name, 8),
                [reference_source]),
            output.Reference(
                phase_identifier.ASSERT,
                output.LineInFilePosition(case_with_references.name, 6),
                [reference_source]),
            output.Reference(
                phase_identifier.CLEANUP,
                output.LineInFilePosition(case_with_references.name, 4),
                [reference_source]),
        ]

        expected_output_lines = list(
            itertools.chain.from_iterable(
                intersperse_list(['', ''],
                                 list(
                                     map(output.Reference.output_lines,
                                         expected_reference_outputs)))))
        check_case_and_suite(
            self,
            symbol_command_arguments=symbol_args.individual__references(
                case_with_references.name,
                name_of_existing_symbol,
            ),
            arrangement=Arrangement(
                cwd_contents=DirContents([
                    case_with_references,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(lines_content(expected_output_lines))))
Exemple #4
0
def elements_for_binary_operator_arg(
        operator: str, operands: Sequence[ArgumentElementsRenderer]) -> List:
    return collection.concat_list(
        collection.intersperse_list([operator],
                                    [operand.elements
                                     for operand in operands]))
 def tokens(self) -> Sequence[Token]:
     tok_sequences = collection.intersperse_list(self._operator_tok_seq(),
                                                 self._operands)
     return TokenSequence.concat(tok_sequences).tokens
Exemple #6
0
def blocks_as_lines(blocks: Blocks) -> List[str]:
    return functools.reduce(lambda x, y: x + y, intersperse_list([''], blocks),
                            [])
Exemple #7
0
    def test_references_SHOULD_be_listed_phase_order(self):
        name_of_existing_symbol = 'STRING_SYMBOL'

        reference_source = sym_def.reference_to(name_of_existing_symbol, ValueType.STRING)
        case_with_references = File('test.case',
                                    lines_content([
                                        phase_names.SETUP.syntax,
                                        sym_def.define_string(name_of_existing_symbol, 'value'),

                                        phase_names.CLEANUP.syntax,
                                        reference_source,

                                        phase_names.ASSERT.syntax,
                                        reference_source,

                                        phase_names.BEFORE_ASSERT.syntax,
                                        reference_source,

                                        phase_names.ACT.syntax,
                                        reference_source,

                                        phase_names.SETUP.syntax,
                                        reference_source,

                                    ]))

        expected_reference_outputs = [
            output.Reference(
                phase_identifier.SETUP,
                output.LineInFilePosition(case_with_references.name, 12),
                [reference_source]
            ),
            output.Reference(
                phase_identifier.ACT,
                None,
                [reference_source]
            ),
            output.Reference(
                phase_identifier.BEFORE_ASSERT,
                output.LineInFilePosition(case_with_references.name, 8),
                [reference_source]
            ),
            output.Reference(
                phase_identifier.ASSERT,
                output.LineInFilePosition(case_with_references.name, 6),
                [reference_source]
            ),
            output.Reference(
                phase_identifier.CLEANUP,
                output.LineInFilePosition(case_with_references.name, 4),
                [reference_source]
            ),
        ]

        expected_output_lines = list(itertools.chain.from_iterable(
            intersperse_list([''],
                             list(map(output.Reference.output_lines,
                                      expected_reference_outputs)))
        )
        )
        test_with_files_in_tmp_dir.check(
            self,
            command_line_arguments=
            symbol_args.individual__references(
                case_with_references.name,
                name_of_existing_symbol,
            ),
            arrangement=
            Arrangement(
                cwd_contents=DirContents([
                    case_with_references,
                ]),
                main_program_config=sym_def.main_program_config(),
            ),
            expectation=
            asrt_proc_result.sub_process_result(
                exitcode=asrt.equals(exit_codes.EXIT_OK),
                stdout=asrt.equals(lines_content(expected_output_lines)))
        )