Skip to content

Commit

Permalink
Esboço de injete. Terminar depois.
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelsanchesdasilva committed May 24, 2024
1 parent 63cde3a commit 7d9b6ac
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
21 changes: 17 additions & 4 deletions fontes/bibliotecas/primitivas-vetor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,26 @@ export default {
return retorno;
},
imutável: (interpretador: VisitanteComumInterface, vetor: Array<any>): Promise<any> => Promise.resolve(),
injete: (interpretador: VisitanteComumInterface, vetor: Array<any>): Promise<any> => Promise.resolve(),
injete: async (interpretador: VisitanteComumInterface, vetor: Array<any>, funcao: DeleguaFuncao): Promise<any> => {
// TODO: Terminar
/* if (funcao === undefined || funcao === null) {
return Promise.reject("É necessário passar uma função para o método 'injete'.");
}
let retorno: any;
for (let elemento of vetor) {
retorno = await funcao.chamar(interpretador, [retorno, elemento]);
}
return retorno; */
return Promise.resolve();
},
insira: (
interpretador: VisitanteComumInterface,
vetor: Array<any>,
vetor: Array<any[]>,
posicao: number,
elemento: string
): Promise<any> => {
elemento: any
): Promise<any[]> => {
let copia = [...vetor];
copia.splice(posicao - 1, 0, elemento);
return Promise.resolve(copia);
Expand Down
39 changes: 39 additions & 0 deletions testes/primitivas/primitivas-vetor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,45 @@ describe('Primitivas de vetor - Potigol', () => {
});
});

describe('injete()', () => {
it.skip('Trivial, apenas um argumento', async () => {
const deleguaFuncao: DeleguaFuncao = new DeleguaFuncao(
'funcao',
new FuncaoConstruto(-1, -1, [
{
abrangencia: 'padrao',
nome: new Simbolo(tiposDeSimbolos.IDENTIFICADOR, 'x', 'x', -1, -1),
tipoDado: { nome: 'x', tipo: 'numero' }
} as ParametroInterface,
{
abrangencia: 'padrao',
nome: new Simbolo(tiposDeSimbolos.IDENTIFICADOR, 'y', 'y', -1, -1),
tipoDado: { nome: 'y', tipo: 'numero' }
} as ParametroInterface
], [
new Retorna(
{
linha: -1,
hashArquivo: -1,
lexema: '',
literal: '',
tipo: 'qualquer',
},
new Binario(
-1,
new Variavel(-1, new Simbolo(tiposDeSimbolos.IDENTIFICADOR, 'x', 'x', -1, -1)),
new Simbolo(tiposDeSimbolos.ADICAO, '<', '<', -1, -1),
new Variavel(-1, new Simbolo(tiposDeSimbolos.IDENTIFICADOR, 'y', 'y', -1, -1))
)
)
])
);

const resultado = await primitivasVetor.injete(interpretador, [2, 4, 6], deleguaFuncao);
expect(resultado).toStrictEqual(12);
});
});

describe('inverta()', () => {
it('Trivial', async () => {
const resultado = await primitivasVetor.inverta(interpretador, [2, 4, 6, 8, 10]);
Expand Down

0 comments on commit 7d9b6ac

Please sign in to comment.