use of org.apache.commons.text.lookup.StringLookup in project commons-text by apache.
the class StringSubstitutorTest method testReplaceInTakingTwoAndThreeIntsReturningFalse.
@Test
public void testReplaceInTakingTwoAndThreeIntsReturningFalse() {
final Map<String, Object> hashMap = new HashMap<>();
final StringLookup mapStringLookup = StringLookupFactory.INSTANCE.mapStringLookup(hashMap);
final StringMatcher strMatcher = StringMatcherFactory.INSTANCE.tabMatcher();
final StringSubstitutor strSubstitutor = new StringSubstitutor(mapStringLookup, strMatcher, strMatcher, 'b', strMatcher);
assertFalse(strSubstitutor.replaceIn((StringBuilder) null, 1315, (-1369)));
assertEquals('b', strSubstitutor.getEscapeChar());
assertFalse(strSubstitutor.isPreserveEscapes());
}
use of org.apache.commons.text.lookup.StringLookup in project dropwizard by dropwizard.
the class SubstitutingSourceProviderTest method shouldSubstituteWithDefaultValue.
@Test
void shouldSubstituteWithDefaultValue() throws IOException {
StringLookup dummyLookup = (x) -> null;
SubstitutingSourceProvider provider = new SubstitutingSourceProvider(new DummySourceProvider(), new StringSubstitutor(dummyLookup));
assertThat(provider.open("foo: ${bar:-default}")).hasSameContentAs(new ByteArrayInputStream("foo: default".getBytes(StandardCharsets.UTF_8)));
}
use of org.apache.commons.text.lookup.StringLookup in project dropwizard by dropwizard.
the class SubstitutingSourceProviderTest method shouldSubstituteOnlyExistingVariables.
@Test
void shouldSubstituteOnlyExistingVariables() throws IOException {
StringLookup dummyLookup = (x) -> null;
SubstitutingSourceProvider provider = new SubstitutingSourceProvider(new DummySourceProvider(), new StringSubstitutor(dummyLookup));
assertThat(provider.open("foo: ${bar}")).hasSameContentAs(new ByteArrayInputStream("foo: ${bar}".getBytes(StandardCharsets.UTF_8)));
}
use of org.apache.commons.text.lookup.StringLookup in project commons-text by apache.
the class StringSubstitutorTest method testReplaceInTakingStringBuilderWithNonNull.
@Test
public void testReplaceInTakingStringBuilderWithNonNull() {
final StringLookup strLookup = StringLookupFactory.INSTANCE.systemPropertyStringLookup();
final StringSubstitutor strSubstitutor = new StringSubstitutor(strLookup, "b<H", "b<H", '\'');
final StringBuilder stringBuilder = new StringBuilder((CharSequence) "b<H");
assertEquals('\'', strSubstitutor.getEscapeChar());
assertFalse(strSubstitutor.replaceIn(stringBuilder));
}
use of org.apache.commons.text.lookup.StringLookup in project dropwizard by dropwizard.
the class SubstitutingSourceProviderTest method shouldSubstituteCorrectly.
@Test
void shouldSubstituteCorrectly() throws IOException {
StringLookup dummyLookup = (x) -> "baz";
DummySourceProvider dummyProvider = new DummySourceProvider();
SubstitutingSourceProvider provider = new SubstitutingSourceProvider(dummyProvider, new StringSubstitutor(dummyLookup));
assertThat(provider.open("foo: ${bar}")).hasSameContentAs(new ByteArrayInputStream("foo: baz".getBytes(StandardCharsets.UTF_8)));
// ensure that opened streams are closed
assertThatIOException().isThrownBy(() -> dummyProvider.lastStream.read()).withMessage("Stream closed");
}
Aggregations