diff --git a/.github/workflows/principal.yml b/.github/workflows/principal.yml index f84b450..553dd50 100644 --- a/.github/workflows/principal.yml +++ b/.github/workflows/principal.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2-beta + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: '16' + node-version: '20' # Maneira tradicional de build, sem cobertura. - name: NPM - Dependências run: | @@ -27,8 +27,7 @@ jobs: - name: Cobertura de Código uses: MishaKav/jest-coverage-comment@main # Os pacotes abaixo continuam dando o seguinte problema: - # https://github.com/ArtiomTr/jest-coverage-report-action/issues/233 - # A solução dada pelo autor não resolve o problema. + # Error: Error: EACCES: permission denied, rmdir 'node_modules/.bin' # - uses: ArtiomTr/jest-coverage-report-action@v2 # id: coverage # with: diff --git a/fontes/interpretador/interpretador-visualg.ts b/fontes/interpretador/interpretador-visualg.ts index fbc329b..b828e69 100644 --- a/fontes/interpretador/interpretador-visualg.ts +++ b/fontes/interpretador/interpretador-visualg.ts @@ -7,8 +7,7 @@ import { Construto, FimPara, FormatacaoEscrita, - Logico, - Variavel, + Logico } from '@designliquido/delegua/construtos'; import { Aleatorio, diff --git a/package.json b/package.json index cc7cdf8..ac77f0a 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "deixar-codigo-bonito": "yarn prettier --config .prettierrc --write fontes/**/*.ts" }, "dependencies": { - "@designliquido/delegua": "^0.39.6", + "@designliquido/delegua": "^0.39.8", "lodash": "^4.17.21" }, "devDependencies": { diff --git a/testes/interpretador.test.ts b/testes/interpretador.test.ts index 6fd22fe..7721489 100644 --- a/testes/interpretador.test.ts +++ b/testes/interpretador.test.ts @@ -697,83 +697,119 @@ describe('Interpretador', () => { }); }); - it('Procedimento', async () => { - const saidasMensagens = ['Digite dois valores: ', 'A variavel escolhida é 3'] - // Aqui vamos simular a resposta para duas variáveis de `leia()`. - const respostas = [ - "2", "3" - ]; - (interpretador as any).interfaceEntradaSaida = { - question: (mensagem: string, callback: Function) => { - callback(respostas.pop()); + describe('Procedimentos', () => { + it('Sem parâmetros', async () => { + const retornoLexador = lexador.mapear([ + 'algoritmo "DetectorPesado"', + 'var', + ' I: inteiro', + ' N, Pesado: caractere', + ' P, Mai: real', + 'procedimento Topo', + 'inicio', + ' LimpaTela', + ' EscrevaL("-----------------------------------")', + ' EscrevaL("D E T E C T O R D E P E S A D O")', + ' EscrevaL("-----------------------------------")', + 'fimprocedimento', + 'inicio', + ' Topo', + 'fimalgoritmo' + ], -1); + const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); + + let chamadasLimpaTela = 0; + interpretador.funcaoLimpaTela = () => { + chamadasLimpaTela++; } - }; - - const retornoLexador = lexador.mapear([ - 'algoritmo "semnome"', - '// Função :', - '// Autor :', - '// Data : 27/02/2014', - '// Seção de Declarações ', - 'var', - 'a,b:inteiro', - 'procedimento mostranumero (a:inteiro;b:inteiro)', - '', - 'inicio', - '', - 'se a > b entao', - ' escreval ("A variavel escolhida é ",a)', - 'senao', - ' escreval ("A variavel escolhida é ",b)', - 'fimse', - 'fimprocedimento', - '', - 'inicio', - 'escreval ("Digite dois valores: ")', - 'leia (a,b)', - 'mostranumero (a,b)', - '', - 'fimalgoritmo' - ], -1); - const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); - - interpretador.funcaoDeRetorno = (saida: any) => { - expect(saidasMensagens.includes(saida)).toBeTruthy() - } - const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); + const _saidas: string[] = []; + interpretador.funcaoDeRetorno = (saida: any) => { + _saidas.push(saida); + } + + const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); + + expect(retornoInterpretador.erros).toHaveLength(0); + expect(chamadasLimpaTela).toBe(1); + expect(_saidas).toHaveLength(3); + }); - expect(retornoInterpretador.erros).toHaveLength(0); + it('Com parâmetros', async () => { + const saidasMensagens = ['Digite dois valores: ', 'A variavel escolhida é 3'] + // Aqui vamos simular a resposta para duas variáveis de `leia()`. + const respostas = [ + "2", "3" + ]; + (interpretador as any).interfaceEntradaSaida = { + question: (mensagem: string, callback: Function) => { + callback(respostas.pop()); + } + }; + + const retornoLexador = lexador.mapear([ + 'algoritmo "semnome"', + '// Função :', + '// Autor :', + '// Data : 27/02/2014', + '// Seção de Declarações ', + 'var', + 'a,b:inteiro', + 'procedimento mostranumero (a:inteiro;b:inteiro)', + 'inicio', + ' se a > b entao', + ' escreval ("A variavel escolhida é ",a)', + ' senao', + ' escreval ("A variavel escolhida é ",b)', + ' fimse', + 'fimprocedimento', + 'inicio', + 'escreval ("Digite dois valores: ")', + 'leia (a,b)', + 'mostranumero (a,b)', + '', + 'fimalgoritmo' + ], -1); + const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); + + interpretador.funcaoDeRetorno = (saida: any) => { + expect(saidasMensagens.includes(saida)).toBeTruthy() + } + + const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); + + expect(retornoInterpretador.erros).toHaveLength(0); + }); + + it('Procedimento com passagem por referência', async () => { + const retornoLexador = lexador.mapear([ + 'algoritmo "Exemplo Parametros Referencia"', + 'var', + ' m,n,res: inteiro', + ' procedimento soma (x,y: inteiro; var result: inteiro)', + ' inicio', + ' result <- x + y', + ' fimprocedimento', + 'inicio', + ' n <- 4', + ' m <- -9', + ' soma(n,m,res)', + ' escreva(res)', + 'fimalgoritmo' + ], -1); + + const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); + + interpretador.funcaoDeRetornoMesmaLinha = (saida: string) => { + expect(saida).toEqual("-5") + } + + const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); + + expect(retornoInterpretador.erros).toHaveLength(0); + }); }); - it('Procedimento com passagem por referência', async () => { - const retornoLexador = lexador.mapear([ - 'algoritmo "Exemplo Parametros Referencia"', - 'var', - ' m,n,res: inteiro', - ' procedimento soma (x,y: inteiro; var result: inteiro)', - ' inicio', - ' result <- x + y', - ' fimprocedimento', - 'inicio', - ' n <- 4', - ' m <- -9', - ' soma(n,m,res)', - ' escreva(res)', - 'fimalgoritmo' - ], -1); - - const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1); - - interpretador.funcaoDeRetornoMesmaLinha = (saida: string) => { - expect(saida).toEqual("-5") - } - - const retornoInterpretador = await interpretador.interpretar(retornoAvaliadorSintatico.declaracoes); - - expect(retornoInterpretador.erros).toHaveLength(0); - }) - it('Operadores Lógicos', async () => { const saidasMensagens = ['A verdadeiro', 'A falso', 'A falso', 'A verdadeiro', 'B falso', 'C verdadeiro'] const retornoLexador = lexador.mapear([ diff --git a/yarn.lock b/yarn.lock index ade2ff5..856353a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -277,10 +277,10 @@ dependencies: "@jridgewell/trace-mapping" "0.3.9" -"@designliquido/delegua@^0.39.6": - version "0.39.6" - resolved "https://registry.yarnpkg.com/@designliquido/delegua/-/delegua-0.39.6.tgz#c9bcd8915492d8a441e45e3ee5786c62f22d200e" - integrity sha512-J5pHpgBZZgZoDeMUtXc4I06JEbv9RzdSsL0wMh9eRa3j8UufZicMGVzExR2naFuydSQDy20+hYaFCu2kFXYQXw== +"@designliquido/delegua@^0.39.8": + version "0.39.8" + resolved "https://registry.yarnpkg.com/@designliquido/delegua/-/delegua-0.39.8.tgz#d6b2b63717aedc95da2c62a96b77419d5794835a" + integrity sha512-nKCL+kDHX8r2oOQdsN2V/K3UVuTZdvNnaPuE3JUmgZR66BlvjsdVSlyLn5yizOrwbVxG9Hoz0KFczLormMKmOg== dependencies: antlr4ts "^0.5.0-alpha.4" browser-process-hrtime "^1.0.0"