Repository: DesignLiquido/delegua
Pull request #448 (2023-06-09 18:05:33)

#446 Método ordenar não está ordenando vetor de textos
Resolve: https://github.com/DesignLiquido/delegua/issues/446

github-actions[bot]: <!-- jest coverage report action for options with hash 781087021f8e6c43aac1e668f4520603 -->

## Coverage report 



| <div title="Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold">St.<sup>:grey_question:</sup></div> | Category   | Percentage                                                    | Covered / Total |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------- | :------------------------------------------------------------ | :-------------: |
|                                                                           🟡                                                                           | Statements | <div title="Base coverage is: 73.55%">73.55% (-0% 🔻)</div>   |    7332/9969    |
|                                                                           🟡                                                                           | Branches   | 63.2%                                                         |    2332/3690    |
|                                                                           🟡                                                                           | Functions  | <div title="Base coverage is: 69.1%">69.08% (-0.02% 🔻)</div> |    1086/1572    |
|                                                                           🟡                                                                           | Lines      | 73.96%                                                        |    7154/9673    |


<details><summary>Show files with reduced coverage 🔻</summary>
<br/>

| <div title="Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold">St.<sup>:grey_question:</sup></div> | File                                                                           | Statements                                                  | Branches | Functions                                                      | Lines  |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------- | :---------------------------------------------------------- | :------- | :------------------------------------------------------------- | :----- |
|                                                                           🟡                                                                           | <div title="bibliotecas/primitivas-vetor.ts">`...` / primitivas-vetor.ts</div> | <div title="Base coverage is: 72.55%">72% (-0.55% 🔻)</div> | 58.82%   | <div title="Base coverage is: 88.89%">88.24% (-0.65% 🔻)</div> | 69.57% |

</details>

## Test suite run success
632 tests passing in 49 suites.

<p align="right">Report generated by <a href="https://github.com/ArtiomTr/jest-coverage-report-action">🧪jest coverage report action</a> from bac23678167ba6c86cb58cc142c1d10202a65d1a</p>
<!-- Sticky Pull Request Comment -->

Patch:
diff --git a/fontes/bibliotecas/primitivas-vetor.ts b/fontes/bibliotecas/primitivas-vetor.ts
index 12da3dd9..bdf9cbb0 100644
--- a/fontes/bibliotecas/primitivas-vetor.ts
+++ b/fontes/bibliotecas/primitivas-vetor.ts
@@ -76,6 +76,10 @@ export default {
             return vetor;
         }
 
+        if (!vetor.every(v => typeof v === 'number')) {
+            return vetor.sort();
+        }
+
         return vetor.sort((a, b) => a - b);
     },
     remover: (interpretador: VisitanteComumInterface, vetor: Array<any>, elemento: any): Promise<any> => {
diff --git a/fontes/interpretador/interpretador-base.ts b/fontes/interpretador/interpretador-base.ts
index 6f53b370..f3cdbced 100644
--- a/fontes/interpretador/interpretador-base.ts
+++ b/fontes/interpretador/interpretador-base.ts
@@ -126,9 +126,10 @@ export class InterpretadorBase implements InterpretadorInterface {
     async visitarExpressaoTipoDe(expressao: TipoDe): Promise<string> {
         let tipoDe = expressao.valor;
         
-        if(expressao.valor instanceof Variavel 
-            || expressao.valor instanceof Binario) {
-            tipoDe = await this.avaliar(expressao.valor);
+        if(tipoDe instanceof Binario
+            || tipoDe instanceof Variavel
+            || tipoDe instanceof TipoDe) {
+            tipoDe = await this.avaliar(tipoDe);
             return tipoDe.tipo || inferirTipoVariavel(tipoDe);
         }
 


Test patch:
diff --git a/testes/interpretador.test.ts b/testes/interpretador.test.ts
index 75b73270..41e7bdf1 100644
--- a/testes/interpretador.test.ts
+++ b/testes/interpretador.test.ts
@@ -214,6 +214,7 @@ describe('Interpretador', () => {
                         "classe OutroTeste {}",
                         "escreva(tipo de OutroTeste)",
                         "escreva(tipo de nulo)",
+                        "escreva(tipo de tipo de tipo de \"a\")",
                     ], -1);
                     const retornoAvaliadorSintatico = avaliadorSintatico.analisar(retornoLexador, -1);
 
diff --git a/testes/primitivas/primitivas-vetor.test.ts b/testes/primitivas/primitivas-vetor.test.ts
index f057fbb3..1a441e7d 100644
--- a/testes/primitivas/primitivas-vetor.test.ts
+++ b/testes/primitivas/primitivas-vetor.test.ts
@@ -61,9 +61,19 @@ describe('Primitivas de vetor', () => {
     });
 
     describe('ordenar()', () => {
-        it('Trivial', async () => {
-            const resultado = await primitivasVetor.ordenar(interpretador, [3, 2, 7, 1, 5], undefined as any);
-            expect(resultado).toStrictEqual([1, 2, 3, 5, 7]);
+        it('Números', async () => {
+            const resultado = await primitivasVetor.ordenar(interpretador, [2, 3, 5, 1, 10, 9], undefined as any);
+            expect(resultado).toStrictEqual([1, 2, 3, 5, 9, 10]);
+        });
+
+        it('Textos', async () => {
+            const resultado = await primitivasVetor.ordenar(interpretador, ["Erika", "Ana", "Carlos", "Daniel", "Bianca"], undefined as any);
+            expect(resultado).toStrictEqual(["Ana", "Bianca", "Carlos", "Daniel", "Erika"]);
+        });
+
+        it('Números e Textos', async () => {
+            const resultado = await primitivasVetor.ordenar(interpretador, ["Ana", "Carlos", "Bianca", 5, 3, 6], undefined as any);
+            expect(resultado).toStrictEqual([3, 5, 6, "Ana", "Bianca", "Carlos"]);
         });
     });