Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix LOGBACK-971 CharSequenceToRegexMapper#findMinMaxLengthsInSymbols(…
…) always returns min=0
- Loading branch information
Showing
3 changed files
with
78 additions
and
2 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
72 changes: 72 additions & 0 deletions
72
logback-core/src/test/java/ch/qos/logback/core/util/CharSequenceToRegexMapperTest.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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package ch.qos.logback.core.util; | ||
|
||
import org.junit.After; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
import java.text.DateFormatSymbols; | ||
import java.util.Locale; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
|
||
public class CharSequenceToRegexMapperTest { | ||
static Locale KO_LOCALE = new Locale("ko", "KR"); | ||
Locale oldLocale = Locale.getDefault(); | ||
|
||
@After | ||
public void tearDown() { | ||
Locale.setDefault(oldLocale); | ||
} | ||
|
||
@Test | ||
public void findMinMaxLengthsInSymbolsWithTrivialInputs() { | ||
String[] symbols = new String[]{"a", "bb"}; | ||
int[] results = CharSequenceToRegexMapper.findMinMaxLengthsInSymbols(symbols); | ||
assertEquals(1, results[0]); | ||
assertEquals(2, results[1]); | ||
} | ||
|
||
@Test | ||
public void emptyStringValuesShouldBeIgnoredByFindMinMaxLengthsInSymbols() { | ||
String[] symbols = new String[]{"aaa", ""}; | ||
int[] results = CharSequenceToRegexMapper.findMinMaxLengthsInSymbols(symbols); | ||
assertEquals(3, results[0]); | ||
assertEquals(3, results[1]); | ||
} | ||
|
||
|
||
@Test | ||
@Ignore | ||
public void noneOfTheSymbolsAreOfZeroLengthForKorean() { | ||
Locale.setDefault(KO_LOCALE); | ||
noneOfTheSymbolsAreOfZeroLength(); | ||
} | ||
|
||
@Test | ||
@Ignore | ||
public void noneOfTheSymbolsAreOfZeroLengthForSwiss() { | ||
Locale.setDefault(new Locale("fr", "CH")); | ||
noneOfTheSymbolsAreOfZeroLength(); | ||
} | ||
|
||
private void noneOfTheSymbolsAreOfZeroLength() { | ||
DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(); | ||
//checkEmptyString(dateFormatSymbols.getShortMonths(), "ShortMonths"); | ||
//checkEmptyString(dateFormatSymbols.getMonths(), "Months"); | ||
checkEmptyString(dateFormatSymbols.getShortWeekdays(), "ShortWeekdays"); | ||
checkEmptyString(dateFormatSymbols.getWeekdays(), "Weekdays"); | ||
checkEmptyString(dateFormatSymbols.getAmPmStrings(), "AmPmStrings"); | ||
|
||
} | ||
|
||
private void checkEmptyString(String[] symbolArray, String category) { | ||
for (String s : symbolArray) { | ||
System.out.println(category + " [" + s + "]"); | ||
assertTrue(category + " contains empty strings", s.length() > 0); | ||
} | ||
} | ||
|
||
|
||
} |
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