Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Documentation example of split doesn't work
I'm wasn't super sure I was following your test functions so I just tested the observables by transforming them to and from arrays.

Part of the problem is StringObservable.split() seems to always behave like String.split() limit 0 which trims excess empty strings at the end. There also doesn't seem to be a way to change the limit so at least the documentation needs to be updated to show this behavior.

Changing the limit in testSplit() doesn't help which is why I went with the array tests.
Limit -1 or even something like 6 should preserve the empty strings if you follow the normal String.split().
But that limit could be for something else. I didn't dive that deep in the test code.
  • Loading branch information
jake-lively committed May 15, 2016
commit 19f24e2daa7595d839443f8047c139cdf788b882
13 changes: 13 additions & 0 deletions src/test/java/rx/observables/StringObservableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ public void testSplitOnColon() {
public void testSplitOnOh() {
testSplit("boo:and:foo", "o", 0, "b", "", ":and:f");
}

@Test
public void testDocumentationSplit() {
//Documentation Example
//split(["boo:an", "d:foo"], "o") --> ["b", "", ":and:f", "", ""]

List<String> expected = Observable.from(new String[]{"b", "", ":and:f", "", ""}).toList().toBlocking().single();

Observable<String> test = Observable.from(new String[]{"boo:an", "d:foo"});
List<String> actual = StringObservable.split(test, "o").toList().toBlocking().single();

assertArrayEquals(expected.toArray(new String[expected.size()]), new String[actual.size()]);
}

@Test
public void testSplitOnEmptyStream() {
Expand Down