vy commented on code in PR #2691: URL: https://github.com/apache/logging-log4j2/pull/2691#discussion_r1662515820
########## log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/StringBuildersTest.java: ########## @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j.core.util; + + +import java.util.stream.Stream; +import org.apache.logging.log4j.core.util.internal.StringBuilders; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class StringBuildersTest { + + static Stream<Arguments> testTruncateLines_happyCases() { + return Stream.of( + // maxOccurrenceCount < lines count + Arguments.of("abc\ndef\nghi\njkl\n", "\n", 2, "abc\ndef\n"), + // maxOccurrenceCount == lines count + Arguments.of("abc|def|ghi|jkl|", "|", 4, "abc|def|ghi|jkl|"), + // maxOccurrenceCount > lines count + Arguments.of("abc|def|ghi|jkl|", "|", 10, "abc|def|ghi|jkl|"), + // maxOccurrenceCount == Integer.MAX_VALUE + Arguments.of("abc|def|ghi|jkl|", "|", Integer.MAX_VALUE, "abc|def|ghi|jkl|"), + // maxOccurrenceCount == 0 + Arguments.of("abc|def|ghi|jkl|", "|", 0, ""), + // empty buffer + Arguments.of("", "|", 2, ""), + // empty delimiter + Arguments.of("abc|def|ghi|jkl|", "", 2, "abc|def|ghi|jkl|"), + // delimiter | + Arguments.of("|", "|", 10, "|"), + Arguments.of("||", "|", 10, "||"), + Arguments.of("a|", "|", 10, "a|"), + Arguments.of("|a", "|", 10, "|"), + // delimiter || + Arguments.of("||", "||", 10, "||"), + Arguments.of("|||", "||", 10, "||"), + Arguments.of("||||", "||", 10, "||||"), + Arguments.of("a|", "||", 10, ""), + Arguments.of("a||", "||", 10, "a||"), + Arguments.of("a|||", "||", 10, "a||"), + Arguments.of("a||||", "||", 10, "a||||"), + Arguments.of("|a", "||", 10, ""), + Arguments.of("||a", "||", 10, "||"), + Arguments.of("|||a", "||", 10, "||"), + Arguments.of("||||a", "||", 10, "||||") Review Comment: I am not able to follow. `truncateAfterDelimiter("a|", "||", 1)` should return the input (i.e., `"a|"`) intact. The subject here I wanted to stress with this particular test case is to make sure the function doesn't do unintended substring matches. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
