Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 1, 2025
1 parent 09d36a6 commit b65859b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public void testUnicodeAtEnd() throws Exception
assertNotNull(o);
assertTrue(o.isArray());
assertEquals(1, o.size());
assertEquals(o.get(0).textValue(), doc);
assertEquals(o.get(0).stringValue(), doc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import tools.jackson.core.StreamReadConstraints;
import tools.jackson.core.exc.StreamConstraintsException;
import tools.jackson.databind.DatabindException;
import tools.jackson.databind.ObjectMapper;

// Tests copied from databind "JDKNumberDeserTest" (only a small subset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,36 @@ private static JsonNode mapFromComplianceNode(ObjectNode expected) {
final JsonNodeCreator nodeF = expected;
if (expected.has("type") && expected.has("value")) {
JsonNode value = expected.get("value");
switch (expected.get("type").textValue()) {
switch (expected.get("type").stringValue()) {
case "string":
// for some reason, the compliance tests escape these values. this makes some tests fail right now
return nodeF.textNode(value.textValue());
return nodeF.textNode(value.stringValue());
case "integer":
return nodeF.numberNode(NumberInput.parseBigInteger(value.textValue(), false));
return nodeF.numberNode(NumberInput.parseBigInteger(value.stringValue(), false));
case "float":
switch (value.textValue()) {
switch (value.stringValue()) {
case "inf":
return nodeF.numberNode(Double.POSITIVE_INFINITY);
case "-inf":
return nodeF.numberNode(Double.NEGATIVE_INFINITY);
case "nan":
return nodeF.numberNode(Double.NaN);
default:
return nodeF.numberNode(NumberInput.parseBigDecimal(value.textValue(), false));
return nodeF.numberNode(NumberInput.parseBigDecimal(value.stringValue(), false));
}
case "boolean":
return nodeF.booleanNode(Boolean.parseBoolean(value.textValue()));
return nodeF.booleanNode(Boolean.parseBoolean(value.stringValue()));
case "offset datetime":
return nodeF.pojoNode(OffsetDateTime.parse(value.textValue()));
return nodeF.pojoNode(OffsetDateTime.parse(value.stringValue()));
case "local datetime":
case "datetime-local":
return nodeF.pojoNode(LocalDateTime.parse(value.textValue()));
return nodeF.pojoNode(LocalDateTime.parse(value.stringValue()));
case "local date":
case "date":
return nodeF.pojoNode(LocalDate.parse(value.textValue()));
return nodeF.pojoNode(LocalDate.parse(value.stringValue()));
case "local time":
case "time":
return nodeF.pojoNode(LocalTime.parse(value.textValue()));
return nodeF.pojoNode(LocalTime.parse(value.stringValue()));
case "array":
ArrayNode array = nodeF.arrayNode();
for (JsonNode member : value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void string() throws IOException {
}
toml.append("'");
ObjectNode node = (ObjectNode) NO_LIMITS_MAPPER.readTree(toml.toString());
Assert.assertEquals(SCALE, node.get("foo").textValue().length());
Assert.assertEquals(SCALE, node.get("foo").stringValue().length());
}

@Test
Expand All @@ -124,6 +124,6 @@ public void stringEscapes() throws IOException {
ObjectNode node = TomlParser.parse(FACTORY, testIOContext(),
TomlWriteFeature.INTERNAL_PROHIBIT_INTERNAL_BUFFER_ALLOCATE, new StringReader(toml.toString()));

Assert.assertEquals(SCALE, node.get("foo").textValue().length());
Assert.assertEquals(SCALE, node.get("foo").stringValue().length());
}
}
1 change: 0 additions & 1 deletion yaml/src/test/java/perf/YAMLDeserPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import tools.jackson.core.*;
import tools.jackson.databind.JavaType;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.type.TypeFactory;
import tools.jackson.dataformat.yaml.YAMLMapper;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public void testParseBooleanLikeWordsAsStringDefault() throws Exception

JsonNode root = mapper.readTree(YAML);
assertEquals(root.get("one").getNodeType(), JsonNodeType.STRING);
assertEquals(root.get("one").textValue(), "Yes");
assertEquals(root.get("one").stringValue(), "Yes");

assertEquals(root.get("two").getNodeType(), JsonNodeType.STRING);
assertEquals(root.get("two").textValue(), "No");
assertEquals(root.get("two").stringValue(), "No");

assertEquals(root.get("three").getNodeType(), JsonNodeType.STRING);
assertEquals(root.get("three").textValue(), "Off");
assertEquals(root.get("three").stringValue(), "Off");

assertEquals(root.get("four").getNodeType(), JsonNodeType.STRING);
assertEquals(root.get("four").textValue(), "On");
assertEquals(root.get("four").stringValue(), "On");

assertEquals(root.get("five").getNodeType(), JsonNodeType.BOOLEAN);
assertTrue(root.get("five").booleanValue());
Expand All @@ -46,9 +46,9 @@ public void testParseBooleanLikeWordsAsStringDefault() throws Exception
assertFalse(root.get("six").booleanValue());

assertEquals(root.get("seven").getNodeType(), JsonNodeType.STRING);
assertEquals(root.get("seven").textValue(), "Y");
assertEquals(root.get("seven").stringValue(), "Y");

assertEquals(root.get("eight").getNodeType(), JsonNodeType.STRING);
assertEquals(root.get("eight").textValue(), "N");
assertEquals(root.get("eight").stringValue(), "N");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testNumberDecoding50052() throws Exception
// tag basically ignored, returned as empty String otken
JsonNode n = YAML_MAPPER.readTree("!!int");
assertEquals(JsonToken.VALUE_STRING, n.asToken());
assertEquals("", n.textValue());
assertEquals("", n.stringValue());
}

// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50339
Expand Down

0 comments on commit b65859b

Please sign in to comment.