Skip to content

Commit

Permalink
(#1488) Add ctor for `Text'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Nov 1, 2020
1 parent a8e0dab commit eb160bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/org/cactoos/scalar/LengthOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import java.util.Iterator;
import org.cactoos.Input;
import org.cactoos.Scalar;
import org.cactoos.Text;
import org.cactoos.io.InputOf;

/**
* Length.
*
* <p>There is no thread-safety guarantee.
* <p>
* There is no thread-safety guarantee.
*
* @since 0.1
*/
Expand Down Expand Up @@ -60,6 +63,14 @@ public <T> LengthOf(final Iterable<T> items) {
});
}

/**
* Ctor.
* @param text The input
*/
public LengthOf(final Text text) {
this(new InputOf(text));
}

/**
* Ctor.
* @param input The input
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/cactoos/scalar/LengthOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.cactoos.io.InputOf;
import org.cactoos.iterable.IterableOf;
import org.cactoos.list.ListOf;
import org.cactoos.text.TextOf;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import org.llorllale.cactoos.matchers.Assertion;
Expand Down Expand Up @@ -185,4 +186,15 @@ public void lengthOfEmptyIterator() {
new IsEqual<>(0)
).affirm();
}

@Test
public void lengthOfText() {
new Assertion<>(
"Must calculate length of empty iterator",
new LengthOf(
new TextOf("abcd")
).intValue(),
new IsEqual<>(4)
).affirm();
}
}

0 comments on commit eb160bf

Please sign in to comment.