Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions fontes/interpretador/interpretador-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2439,8 +2439,7 @@ export class InterpretadorBase implements InterpretadorInterface {
objeto instanceof DescritorTipoClasse ||
objeto instanceof DeleguaModulo
) {
if (objeto[valorIndice] === 0) return 0;
return objeto[valorIndice] || null;
return objeto[valorIndice];
}

if (typeof objeto === tipoDeDadosPrimitivos.TEXTO) {
Expand Down
3 changes: 1 addition & 2 deletions fontes/interpretador/interpretador.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,7 @@ export class Interpretador extends InterpretadorBase implements VisitanteDelegua
objeto instanceof DescritorTipoClasse ||
objeto instanceof DeleguaModulo
) {
if (objeto[valorIndice] === 0) return 0;
return objeto[valorIndice] || null;
return objeto[valorIndice];
}

if (typeof objeto === tipoDeDadosPrimitivos.TEXTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,18 @@ describe('Interpretador (Pituguês)', () => {

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

it('Deve retornar valores falsy ao acessar chave de dicionário', async () => {
const retornoLexador = lexador.mapear([
"d = {'chave': falso}",
"escreva(d['chave'])"
], -1);
const retornoAvaliadorSintatico = await avaliadorSintatico.analisar(retornoLexador, -1);
const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes);

expect(retornoInterpretador.erros).toHaveLength(0);
expect(_saidas[0]).toBe('falso');
});
});

describe('escreva() e imprima()', () => {
Expand Down
12 changes: 12 additions & 0 deletions testes/interpretador/interpretador.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,18 @@ describe('Interpretador', () => {

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

it('Deve retornar valores falsy ao acessar chave de dicionário', async () => {
const retornoLexador = lexador.mapear([
"var d = {'chave': falso}",
"escreva(d['chave'])"
], -1);
const retornoAvaliadorSintatico = await avaliadorSintatico.analisar(retornoLexador, -1);
const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes);

expect(retornoInterpretador.erros).toHaveLength(0);
expect(_saidas[0]).toBe('falso');
});
});

describe('Atribuições', () => {
Expand Down
Loading