From e84696fed6d8803693d557ccc73ad984f9345c81 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Tue, 8 Nov 2022 15:14:47 +0100 Subject: [PATCH] Parse Json from Http_Spec.enso properly --- .../main/java/org/enso/compiler/TreeToIr.java | 11 +++++--- .../org/enso/compiler/EnsoCompilerTest.java | 26 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java b/engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java index 357ae5bf66ac..1be69291591d 100644 --- a/engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java +++ b/engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java @@ -957,7 +957,7 @@ IR.Literal translateLiteral(Tree.TextLiteral txt) { return new IR$Literal$Text(value, getIdentifiedLocation(txt), meta(), diag()); } String buildTextConstant(Iterable elements, boolean stripComments) { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); for (var t : elements) { switch (t) { case TextElement.Section s -> { @@ -972,14 +972,19 @@ String buildTextConstant(Iterable elements, boolean stripComments) { } else { sb.append('"'); sb.append(seg); - sb.append('"'); + if (i + 1 < quotedSegments.length) { + sb.append('"'); + } } } } else { sb.append(text); } } - case TextElement.Escape e -> sb.appendCodePoint(e.getToken().getValue()); + case TextElement.Escape e -> { + var val = e.getToken().getValue(); + sb.appendCodePoint(val); + } default -> throw new UnhandledEntity(t, "buildTextConstant"); } } diff --git a/engine/runtime/src/test/java/org/enso/compiler/EnsoCompilerTest.java b/engine/runtime/src/test/java/org/enso/compiler/EnsoCompilerTest.java index 416e9a788088..c9d5c13fdb89 100644 --- a/engine/runtime/src/test/java/org/enso/compiler/EnsoCompilerTest.java +++ b/engine/runtime/src/test/java/org/enso/compiler/EnsoCompilerTest.java @@ -1164,6 +1164,32 @@ public void testQuotedValues() throws Exception { """, true, true, false); } + @Test + public void testSimpleTrippleQuote() throws Exception { + parseTest(""" + expected_response = Json.parse <| ''' + { + "headers": { + "Content-Length": "13", + "Content-Type": "application/json", + "User-Agent": "Java-http-client/11.0.13" + }, + "origin": "127.0.0.1", + "url": "", + "args": {}, + "data": "{\\"key\\":\\"val\\"}", + "files": null, + "form": null, + "json": { + "key": "val" + } + } + json = Json.parse <| ''' + {"key":"val"} + res = Http.new.post_json url_post json + """, true, true, false); + } + @Test @Ignore // enable CodeLocationsTest: "be correct in the presence of comments" public void testInThePresenceOfComments() throws Exception {