Reformat, simplify and suplement testVarcharToCharSaturatedFloorCast
Format so that input and output are one below other for easy eye-ball
comparison. Also shorten test examples and add more test cases.
@@ -61,9 +61,80 @@ public class TestCharacterStringCasts
@Test
public void testVarcharToCharSaturatedFloorCast()
{
- assertEquals(varcharToCharSaturatedFloorCast(10L, utf8Slice("1234567890")), utf8Slice("1234567890"));
- assertEquals(varcharToCharSaturatedFloorCast(10L, utf8Slice("123456789")), utf8Slice("12345678"));
- assertEquals(varcharToCharSaturatedFloorCast(10L, utf8Slice("12345678901")), utf8Slice("1234567890"));
- assertEquals(varcharToCharSaturatedFloorCast(10L, utf8Slice("")), utf8Slice(""));
+ String nonBmpCharacter = new String(Character.toChars(0x1F50D));
+
+ // Truncation
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("12345")),
+ utf8Slice("1234"));
+
+ // Size fits, preserved
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("1234")),
+ utf8Slice("1234"));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("123" + nonBmpCharacter)),
+ utf8Slice("123" + nonBmpCharacter));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("12" + nonBmpCharacter + "3")),
+ utf8Slice("12" + nonBmpCharacter + "3"));
+
+ // Size fits, preserved except char(4) representation has trailing spaces removed
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("123 ")),
+ utf8Slice("123"));
+
+ // Too short
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("123")),
+ utf8Slice("12"));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("12 ")),
+ utf8Slice("1"));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("1 ")),
+ utf8Slice(""));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice(" ")),
+ utf8Slice(""));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("12" + nonBmpCharacter)),
+ utf8Slice("12"));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("1" + nonBmpCharacter + "3")),
+ utf8Slice("1" + nonBmpCharacter));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("12\0")),
+ utf8Slice("12"));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("1\0")),
+ utf8Slice("1"));
+
+ // Smaller than any char(4)
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("\0")),
+ utf8Slice(""));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("\0\0")),
+ utf8Slice("\0"));
+ assertEquals(varcharToCharSaturatedFloorCast(
+ 4L,
+ utf8Slice("")),
+ utf8Slice(""));
}
}
