Repository: DesignLiquido/delegua
Pull request #770 (2025-06-20 17:01:10)

#762 Suporte texto multilinha
Resolve: https://github.com/DesignLiquido/delegua/issues/762

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: 72.75%">72.75% (-0% 🔻)</div> | 6784/9325 |
| 🟡 | Branches | <div title="Base coverage is: 63.16%">63.16% (-0.01% 🔻)</div> | 2189/3466 |
| 🟡 | Functions | 62.06% | 965/1555 |
| 🟡 | Lines | <div title="Base coverage is: 73.27%">73.28% (+0.01% 🔼)</div> | 6632/9050 |


<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 |
| :-: | :- | :- | :- | :- | :- |
| 🟢 | lexador/lexador.ts | <div title="Base coverage is: 97.63%">96.92% (-0.71% 🔻)</div> | <div title="Base coverage is: 95.33%">94.5% (-0.83% 🔻)</div> | 100% | <div title="Base coverage is: 97.59%">97.27% (-0.32% 🔻)</div> |

</details>

## Test suite run success
583 tests passing in 35 suites.

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

Patch:
diff --git a/fontes/lexador/lexador.ts b/fontes/lexador/lexador.ts
index 803867d5..687cc17a 100644
--- a/fontes/lexador/lexador.ts
+++ b/fontes/lexador/lexador.ts
@@ -164,21 +164,43 @@ export class Lexador implements LexadorInterface<SimboloInterface> {
     }
 
     analisarTexto(delimitador = '"'): void {
-        while (this.simboloAtual() !== delimitador && !this.eFinalDoCodigo()) {
-            this.avancar();
-        }
+        let textoCompleto = '';
+
+        this.avancar();
+
+        while (!this.eFinalDoCodigo()) {
+            const caractere = this.simboloAtual();
 
-        if (this.eFinalDoCodigo()) {
-            this.erros.push({
-                linha: this.linha + 1,
-                caractere: this.simboloAnterior(),
-                mensagem: 'Texto não finalizado.',
-            } as ErroLexador);
-            return;
+            if (caractere === delimitador) {
+                this.avancar();
+                this.adicionarSimbolo(tiposDeSimbolos.TEXTO, textoCompleto);
+                return;
+            }
+
+            if (caractere === '\0' && this.eUltimaLinha()) {
+                this.erros.push({
+                    linha: this.linha + 1,
+                    caractere: this.simboloAnterior(),
+                    mensagem: 'Texto não finalizado.',
+                } as ErroLexador);
+                return;
+            }
+
+            if (caractere === '\0') {
+                textoCompleto += '\n';
+                this.avancar();
+                continue;
+            }
+
+            textoCompleto += caractere;
+            this.avancar();
         }
 
-        const valor = this.codigo[this.linha].substring(this.inicioSimbolo + 1, this.atual);
-        this.adicionarSimbolo(tiposDeSimbolos.TEXTO, valor);
+        this.erros.push({
+            linha: this.linha + 1,
+            caractere: this.simboloAnterior(),
+            mensagem: 'Texto não finalizado.',
+        } as ErroLexador);
     }
 
     analisarNumero(): void {
@@ -439,15 +461,11 @@ export class Lexador implements LexadorInterface<SimboloInterface> {
                 this.avancar();
                 break;
             case '"':
-                this.avancar();
                 this.analisarTexto('"');
-                this.avancar();
                 break;
 
             case "'":
-                this.avancar();
                 this.analisarTexto("'");
-                this.avancar();
                 break;
 
             default:


Test patch:
diff --git a/testes/lexador/lexador.test.ts b/testes/lexador/lexador.test.ts
index 27a8b2c3..3073c8e3 100644
--- a/testes/lexador/lexador.test.ts
+++ b/testes/lexador/lexador.test.ts
@@ -199,6 +199,31 @@ describe('Lexador', () => {
 
                 expect(resultado).toBeTruthy();
             });
+
+            it('Sucesso - Suporte a strings multilinha', () => {
+                const resultado = lexador.mapear(
+                    [
+                        'escreva("a',
+                        'b")'
+                    ],
+                    -1
+                );
+
+                expect(resultado).toBeTruthy();
+                expect(resultado.simbolos).toHaveLength(4);
+
+                expect(resultado.simbolos).toEqual(
+                    expect.arrayContaining([
+                        expect.objectContaining({ tipo: tiposDeSimbolos.ESCREVA }),
+                        expect.objectContaining({ tipo: tiposDeSimbolos.PARENTESE_ESQUERDO }),
+                        expect.objectContaining({
+                            tipo: tiposDeSimbolos.TEXTO,
+                            literal: 'a\nb'
+                        }),
+                        expect.objectContaining({ tipo: tiposDeSimbolos.PARENTESE_DIREITO })
+                    ])
+                );
+            });
         });
 
         describe('Cenários de falha', () => {