-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor BstTextPrefixer.textPrefix (#11746)
* refactor BstTextPrefixer.textPrefix 1. add more unit test about nested brace cases 2. refactor the `textPrefix` method to make it clear * rewrite unit test use @ParameterizedTest and @CsvSource to rewrite unit test
- Loading branch information
Showing
2 changed files
with
76 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 24 additions & 18 deletions
42
src/test/java/org/jabref/logic/bst/util/BstTextPrefixerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
package org.jabref.logic.bst.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class BstTextPrefixerTest { | ||
|
||
@Test | ||
void prefix() { | ||
assertPrefix("i", "i"); | ||
assertPrefix("0I~ ", "0I~ "); | ||
assertPrefix("Hi Hi", "Hi Hi "); | ||
assertPrefix("{\\oe}", "{\\oe}"); | ||
assertPrefix("Hi {\\oe }H", "Hi {\\oe }Hi "); | ||
assertPrefix("Jonat", "Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin"); | ||
assertPrefix("{\\'e}", "{\\'e}"); | ||
assertPrefix("{\\'{E}}doua", "{\\'{E}}douard Masterly"); | ||
assertPrefix("Ulric", "Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot"); | ||
} | ||
|
||
private static void assertPrefix(final String string, final String string2) { | ||
assertEquals(string, BstTextPrefixer.textPrefix(5, string2)); | ||
public class BstTextPrefixerTest { | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"i, i", | ||
"0I~ , 0I~ ", | ||
"Hi Hi, Hi Hi ", | ||
"{\\oe}, {\\oe}", | ||
"Hi {\\oe }H, Hi {\\oe }Hi ", | ||
"Jonat, Jonathan Meyer and Charles Louis Xavier Joseph de la Vall{\\'e}e Poussin", | ||
"{\\'e}, {\\'e}", | ||
"{\\'{E}}doua, {\\'{E}}douard Masterly", | ||
"Ulric, Ulrich {\\\"{U}}nderwood and Ned {\\~N}et and Paul {\\={P}}ot", | ||
"abcd{e}, abcd{efg}hi", | ||
"ab{cd}e, ab{cd}efghi", | ||
"ab{cd}e, ab{cd}efghi{}", | ||
"Hi {{\\o}}, Hi {{\\oe }}Hi ", | ||
"Hi {\\{oe }}H, Hi {\\{oe }}Hi ", | ||
"Hi {\\\"oe }H, Hi {\\\"oe }Hi ", | ||
"Hi {\\{\\oe }}H, Hi {\\{\\oe }}Hi " | ||
}) | ||
void assertPrefix(final String expectedResult, final String toPrefixInput) { | ||
assertEquals(expectedResult, BstTextPrefixer.textPrefix(5, toPrefixInput)); | ||
} | ||
} |