Skip to content

Commit

Permalink
Merge pull request #661 from Aristidescosta/funcao-retorna-lista
Browse files Browse the repository at this point in the history
Funcao retorna lista
  • Loading branch information
samuelrvg authored Feb 22, 2024
2 parents b37e088 + 41766d2 commit f6cd3d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fontes/interpretador/interpretador-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1619,8 +1619,11 @@ export class InterpretadorBase implements InterpretadorInterface {
retornoVetor += `${this.paraTexto(elemento)},`;
}

retornoVetor = retornoVetor.slice(0, -1);
if(retornoVetor.length > 1){
retornoVetor = retornoVetor.slice(0, -1);
}
retornoVetor += ']';

return retornoVetor;
}

Expand Down
26 changes: 26 additions & 0 deletions testes/interpretador/interpretador.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,32 @@ describe('Interpretador', () => {

expect(retornoInterpretador.erros).toHaveLength(0);
});

it('função que retorna lista', async () => {
const retornoLexador = lexador.mapear(
[
"funcao retorneLista() {",
"var lista = []",

"retorna lista",
"}",

"escreva(retorneLista())"
],
-1
);
const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1);

interpretador.funcaoDeRetorno = (saida: string) => {
expect(saida).toEqual('[]');
};

const retornoInterpretador = await interpretador.interpretar(
retornoAvaliadorSintatico.declaracoes
);

expect(retornoInterpretador.erros).toHaveLength(0);
});
});
});

Expand Down

0 comments on commit f6cd3d7

Please sign in to comment.