1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.core.util;
15
16 import org.junit.jupiter.api.AfterEach;
17 import org.junit.jupiter.api.Assertions;
18 import org.junit.jupiter.api.Disabled;
19 import org.junit.jupiter.api.Test;
20
21 import java.text.DateFormatSymbols;
22 import java.util.Locale;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25
26 public class CharSequenceToRegexMapperTest {
27 static Locale KO_LOCALE = new Locale("ko", "KR");
28 Locale oldLocale = Locale.getDefault();
29
30 @AfterEach
31 public void tearDown() {
32 Locale.setDefault(oldLocale);
33 }
34
35 @Test
36 public void findMinMaxLengthsInSymbolsWithTrivialInputs() {
37 String[] symbols = new String[] { "a", "bb" };
38 int[] results = CharSequenceToRegexMapper.findMinMaxLengthsInSymbols(symbols);
39 assertEquals(1, results[0]);
40 assertEquals(2, results[1]);
41 }
42
43 @Test
44 public void emptyStringValuesShouldBeIgnoredByFindMinMaxLengthsInSymbols() {
45 String[] symbols = new String[] { "aaa", "" };
46 int[] results = CharSequenceToRegexMapper.findMinMaxLengthsInSymbols(symbols);
47 assertEquals(3, results[0]);
48 assertEquals(3, results[1]);
49 }
50
51 @Test
52 @Disabled
53 public void noneOfTheSymbolsAreOfZeroLengthForKorean() {
54 Locale.setDefault(KO_LOCALE);
55 noneOfTheSymbolsAreOfZeroLength();
56 }
57
58 @Test
59 @Disabled
60 public void noneOfTheSymbolsAreOfZeroLengthForSwiss() {
61 Locale.setDefault(new Locale("fr", "CH"));
62 noneOfTheSymbolsAreOfZeroLength();
63 }
64
65 private void noneOfTheSymbolsAreOfZeroLength() {
66 DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance();
67
68
69 checkEmptyString(dateFormatSymbols.getShortWeekdays(), "ShortWeekdays");
70 checkEmptyString(dateFormatSymbols.getWeekdays(), "Weekdays");
71 checkEmptyString(dateFormatSymbols.getAmPmStrings(), "AmPmStrings");
72
73 }
74
75 private void checkEmptyString(String[] symbolArray, String category) {
76 for (String s : symbolArray) {
77 System.out.println(category + " [" + s + "]");
78 Assertions.assertTrue(s.length() > 0, category + " contains empty strings");
79 }
80 }
81
82 }