-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRStringReplacementTest.java
More file actions
68 lines (48 loc) · 1.89 KB
/
RStringReplacementTest.java
File metadata and controls
68 lines (48 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.holi;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
/**
* Created by selonj on 16-9-5.
*/
public class RStringReplacementTest {
@Test public void replaceAllIfAllMatched() throws Exception {
RString foo = RString.valueOf("foo");
RString result = foo.replace("[a-z]", toUpperCase());
assertThat(result.toString(), equalTo("FOO"));
}
@Test public void returnDirectlyIfMismatched() throws Exception {
RString foo = RString.valueOf("0");
RString result = foo.replace("^[a-z]", toUpperCase());
assertThat(result.toString(), equalTo("0"));
}
@Test public void preserveTheHeadingMismatched() throws Exception {
RString foo = RString.valueOf("1f");
RString result = foo.replace("[a-z]", toUpperCase());
assertThat(result.toString(), equalTo("1F"));
}
@Test public void preserveTheSurroundingMismatched() throws Exception {
RString foo = RString.valueOf("f1f");
RString result = foo.replace("[a-z]", toUpperCase());
assertThat(result.toString(), equalTo("F1F"));
}
@Test public void preserveTheTailingMismatched() throws Exception {
RString foo = RString.valueOf("f1");
RString result = foo.replace("[a-z]", toUpperCase());
assertThat(result.toString(), equalTo("F1"));
}
@Test public void throwsMissingValueExceptionIfReplaceGroupWithNullValue() throws Exception {
RString foo = RString.valueOf("f1");
try {
foo.replace(".*", name -> null);
fail("should failed");
} catch (MissingValueException expected) {
assertThat(expected, hasMessage(equalTo("missing variable `groups`!")));
}
}
private Context<Context<Integer, String>, String> toUpperCase() {
return (groups) -> groups.get(0).toUpperCase();
}
}