Skip to content

Commit

Permalink
Parse Json from Http_Spec.enso properly
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Nov 8, 2022
1 parent bbb72d0 commit e84696f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
11 changes: 8 additions & 3 deletions engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e84696f

Please sign in to comment.