Skip to content

Commit 4eff7bd

Browse files
committed
Improved unit test coverage.
1 parent 8e89a3c commit 4eff7bd

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/types/UTF8StringSuite.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,32 @@ class UTF8StringSuite extends SparkFunSuite {
4444
test("contains") {
4545
assert(UTF8String.fromString("hello").contains(UTF8String.fromString("ello")))
4646
assert(!UTF8String.fromString("hello").contains(UTF8String.fromString("vello")))
47+
assert(!UTF8String.fromString("hello").contains(UTF8String.fromString("hellooo")))
4748
assert(UTF8String.fromString("大千世界").contains(UTF8String.fromString("千世")))
4849
assert(!UTF8String.fromString("大千世界").contains(UTF8String.fromString("世千")))
50+
assert(!UTF8String.fromString("大千世界").contains(UTF8String.fromString("大千世界好")))
4951
}
5052

5153
test("prefix") {
5254
assert(UTF8String.fromString("hello").startsWith(UTF8String.fromString("hell")))
5355
assert(!UTF8String.fromString("hello").startsWith(UTF8String.fromString("ell")))
56+
assert(!UTF8String.fromString("hello").startsWith(UTF8String.fromString("hellooo")))
5457
assert(UTF8String.fromString("大千世界").startsWith(UTF8String.fromString("大千")))
5558
assert(!UTF8String.fromString("大千世界").startsWith(UTF8String.fromString("")))
59+
assert(!UTF8String.fromString("大千世界").startsWith(UTF8String.fromString("大千世界好")))
5660
}
5761

5862
test("suffix") {
5963
assert(UTF8String.fromString("hello").endsWith(UTF8String.fromString("ello")))
6064
assert(!UTF8String.fromString("hello").endsWith(UTF8String.fromString("ellov")))
65+
assert(!UTF8String.fromString("hello").endsWith(UTF8String.fromString("hhhello")))
6166
assert(UTF8String.fromString("大千世界").endsWith(UTF8String.fromString("世界")))
6267
assert(!UTF8String.fromString("大千世界").endsWith(UTF8String.fromString("")))
68+
assert(!UTF8String.fromString("大千世界").endsWith(UTF8String.fromString("我的大千世界")))
6369
}
6470

6571
test("slice") {
72+
assert(UTF8String.fromString("hello").slice(0, 0) == UTF8String.fromString(""))
6673
assert(UTF8String.fromString("hello").slice(1, 3) == UTF8String.fromString("el"))
6774
assert(UTF8String.fromString("大千世界").slice(0, 1) == UTF8String.fromString(""))
6875
assert(UTF8String.fromString("大千世界").slice(1, 3) == UTF8String.fromString("千世"))

unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public byte[] getBytes() {
9797
/**
9898
* Returns a substring of this.
9999
* @param start the position of first code point
100-
* @param until the position after last code point
100+
* @param until the position after last code point, exclusive.
101101
*/
102102
public UTF8String slice(final int start, final int until) {
103103
if (until <= start || start >= bytes.length) {
104-
return new UTF8String();
104+
return UTF8String.fromBytes(new byte[0]);
105105
}
106106

107107
int i = 0;

0 commit comments

Comments
 (0)