Skip to content

Commit

Permalink
(#1489) Return character-length instead of byte-length
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Nov 5, 2020
1 parent 9f3fa11 commit e55c217
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/cactoos/scalar/LengthOf.java
Expand Up @@ -65,12 +65,12 @@ public <T> LengthOf(final Iterable<T> items) {

/**
* Ctor.
* Byte-length of Text.
*
* Character-length of Text.
*
* @param text The input
*/
public LengthOf(final Text text) {
this(new InputOf(text));
this(() -> (double) text.asString().length());
}

/**
Expand Down
13 changes: 11 additions & 2 deletions src/test/java/org/cactoos/scalar/LengthOfTest.java
Expand Up @@ -199,10 +199,19 @@ public void lengthOfEmptyText() {
}

@Test
public void lengthOfUnicode() {
public void lengthOfUnicodeAsText() {
new Assertion<>(
"Must calculate length of empty string",
"Must calculate character-length of unicode text",
new LengthOf(new TextOf("привет")).intValue(),
new IsEqual<>(6)
).affirm();
}

@Test
public void lengthOfUnicodeAsInput() {
new Assertion<>(
"Must calculate character-length of unicode input",
new LengthOf(new InputOf("Привет")).intValue(),
new IsEqual<>(12)
).affirm();
}
Expand Down

0 comments on commit e55c217

Please sign in to comment.