diff --git a/fontes/interpretador/interpretador-base.ts b/fontes/interpretador/interpretador-base.ts index 9848fb35..bf109644 100644 --- a/fontes/interpretador/interpretador-base.ts +++ b/fontes/interpretador/interpretador-base.ts @@ -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; } diff --git a/testes/interpretador/interpretador.test.ts b/testes/interpretador/interpretador.test.ts index c7f53749..54089227 100644 --- a/testes/interpretador/interpretador.test.ts +++ b/testes/interpretador/interpretador.test.ts @@ -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); + }); }); });