Skip to content

Commit

Permalink
added more tests and fixed more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Nov 23, 2024
1 parent c3fcb19 commit 6996898
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.uri.URIUtil;
import io.usethesource.vallang.IInteger;
Expand Down Expand Up @@ -494,7 +492,6 @@ private int getCol() {
}
}


@Override
public IValue visitAbstractData(Type type) throws IOException {
if (in.peek() == JsonToken.STRING) {
Expand Down Expand Up @@ -574,6 +571,9 @@ else if (explicitConstructorNames && consName == null) {
if (alternatives.size() > 1) {
monitor.warning("selecting arbitrary constructor for " + type, vf.sourceLocation(in.getPath()));
}
else if (alternatives.size() == 0) {
throw new IOException("No fitting constructor found for " + in.getPath());

Check warning on line 575 in src/org/rascalmpl/library/lang/json/internal/JsonValueReader.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/library/lang/json/internal/JsonValueReader.java#L575

Added line #L575 was not covered by tests
}
Type cons = alternatives.iterator().next();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ test bool explicitDataTypes() {
assert json == "{\"_constructor\":\"data4\",\"_type\":\"DATA4\",\"e\":{\"_constructor\":\"z\",\"_type\":\"Enum\"}}";
// _constructor and _type must be the first fields
assert parseJSON(#DATA4, json, explicitDataTypes=true) == example;
// _type and _constructor may appear in a different order
flippedJson = "{\"_type\":\"DATA4\",\"_constructor\":\"data4\",\"e\":{\"_constructor\":\"z\",\"_type\":\"Enum\"}}";
assert parseJSON(#DATA4, flippedJson, explicitDataTypes=true) == example;
// here we can't be sure to get z() back, but we will get some Enum
// assert data4(e=Enum _) := parseJSON(#DATA4, json, explicitDataTypes=false);
assert data4(e=Enum _) := parseJSON(#DATA4, json, explicitDataTypes=false);
return true;
}

0 comments on commit 6996898

Please sign in to comment.