Skip to content

Commit

Permalink
Improved unit test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
rxin committed Jun 11, 2015
1 parent 8e89a3c commit 4eff7bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,32 @@ class UTF8StringSuite extends SparkFunSuite {
test("contains") {
assert(UTF8String.fromString("hello").contains(UTF8String.fromString("ello")))
assert(!UTF8String.fromString("hello").contains(UTF8String.fromString("vello")))
assert(!UTF8String.fromString("hello").contains(UTF8String.fromString("hellooo")))
assert(UTF8String.fromString("大千世界").contains(UTF8String.fromString("千世")))
assert(!UTF8String.fromString("大千世界").contains(UTF8String.fromString("世千")))
assert(!UTF8String.fromString("大千世界").contains(UTF8String.fromString("大千世界好")))
}

test("prefix") {
assert(UTF8String.fromString("hello").startsWith(UTF8String.fromString("hell")))
assert(!UTF8String.fromString("hello").startsWith(UTF8String.fromString("ell")))
assert(!UTF8String.fromString("hello").startsWith(UTF8String.fromString("hellooo")))
assert(UTF8String.fromString("大千世界").startsWith(UTF8String.fromString("大千")))
assert(!UTF8String.fromString("大千世界").startsWith(UTF8String.fromString("")))
assert(!UTF8String.fromString("大千世界").startsWith(UTF8String.fromString("大千世界好")))
}

test("suffix") {
assert(UTF8String.fromString("hello").endsWith(UTF8String.fromString("ello")))
assert(!UTF8String.fromString("hello").endsWith(UTF8String.fromString("ellov")))
assert(!UTF8String.fromString("hello").endsWith(UTF8String.fromString("hhhello")))
assert(UTF8String.fromString("大千世界").endsWith(UTF8String.fromString("世界")))
assert(!UTF8String.fromString("大千世界").endsWith(UTF8String.fromString("")))
assert(!UTF8String.fromString("大千世界").endsWith(UTF8String.fromString("我的大千世界")))
}

test("slice") {
assert(UTF8String.fromString("hello").slice(0, 0) == UTF8String.fromString(""))
assert(UTF8String.fromString("hello").slice(1, 3) == UTF8String.fromString("el"))
assert(UTF8String.fromString("大千世界").slice(0, 1) == UTF8String.fromString(""))
assert(UTF8String.fromString("大千世界").slice(1, 3) == UTF8String.fromString("千世"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public byte[] getBytes() {
/**
* Returns a substring of this.
* @param start the position of first code point
* @param until the position after last code point
* @param until the position after last code point, exclusive.
*/
public UTF8String slice(final int start, final int until) {
if (until <= start || start >= bytes.length) {
return new UTF8String();
return UTF8String.fromBytes(new byte[0]);
}

int i = 0;
Expand Down

0 comments on commit 4eff7bd

Please sign in to comment.