Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Trim on String -> Character conversion #94

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ static Boolean toBoolean(Object from, Converter converter) {
}

static char toCharacter(Object from, Converter converter) {
String str = StringUtilities.trimToNull(asString(from));
if (str == null) {
String str = (String)from;
if (str == null || str.isEmpty()) {
return CommonValues.CHARACTER_ZERO;
}
if (str.length() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private static Stream<Arguments> toYear_extremeParams() {
);
}


@ParameterizedTest
@MethodSource("toYear_extremeParams")
void toYear_withExtremeParams_returnsValue(String source, int value) {
Expand All @@ -89,6 +90,31 @@ void toYear_withExtremeParams_returnsValue(String source, int value) {
assertThat(actual).isEqualTo(expected);
}

private static Stream<Arguments> toCharParams() {
return Stream.of(
Arguments.of("0000", '\u0000'),
Arguments.of("65", 'A'),
Arguments.of("\t", '\t'),
Arguments.of("\u0005", '\u0005')
);
}

@ParameterizedTest
@MethodSource("toCharParams")
void toChar(String source, char value) {
char actual = this.converter.convert(source, char.class);
//System.out.println(Integer.toHexString(actual) + " = " + Integer.toHexString(value));
assertThat(actual).isEqualTo(value);
}

@ParameterizedTest
@MethodSource("toCharParams")
void toChar(String source, Character value) {
Character actual = this.converter.convert(source, Character.class);
//System.out.println(Integer.toHexString(actual) + " = " + Integer.toHexString(value));
assertThat(actual).isEqualTo(value);
}

private static Stream<Arguments> toCharSequenceTypes() {
return Stream.of(
Arguments.of(StringBuffer.class),
Expand Down
Loading