001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.util; 015 016import org.junit.After; 017import org.junit.Ignore; 018import org.junit.Test; 019 020import java.text.DateFormatSymbols; 021import java.util.Locale; 022 023import static org.junit.Assert.assertTrue; 024import static org.junit.Assert.assertEquals; 025 026public class CharSequenceToRegexMapperTest { 027 static Locale KO_LOCALE = new Locale("ko", "KR"); 028 Locale oldLocale = Locale.getDefault(); 029 030 @After 031 public void tearDown() { 032 Locale.setDefault(oldLocale); 033 } 034 035 @Test 036 public void findMinMaxLengthsInSymbolsWithTrivialInputs() { 037 String[] symbols = new String[] { "a", "bb" }; 038 int[] results = CharSequenceToRegexMapper.findMinMaxLengthsInSymbols(symbols); 039 assertEquals(1, results[0]); 040 assertEquals(2, results[1]); 041 } 042 043 @Test 044 public void emptyStringValuesShouldBeIgnoredByFindMinMaxLengthsInSymbols() { 045 String[] symbols = new String[] { "aaa", "" }; 046 int[] results = CharSequenceToRegexMapper.findMinMaxLengthsInSymbols(symbols); 047 assertEquals(3, results[0]); 048 assertEquals(3, results[1]); 049 } 050 051 @Test 052 @Ignore 053 public void noneOfTheSymbolsAreOfZeroLengthForKorean() { 054 Locale.setDefault(KO_LOCALE); 055 noneOfTheSymbolsAreOfZeroLength(); 056 } 057 058 @Test 059 @Ignore 060 public void noneOfTheSymbolsAreOfZeroLengthForSwiss() { 061 Locale.setDefault(new Locale("fr", "CH")); 062 noneOfTheSymbolsAreOfZeroLength(); 063 } 064 065 private void noneOfTheSymbolsAreOfZeroLength() { 066 DateFormatSymbols dateFormatSymbols = DateFormatSymbols.getInstance(); 067 // checkEmptyString(dateFormatSymbols.getShortMonths(), "ShortMonths"); 068 // checkEmptyString(dateFormatSymbols.getMonths(), "Months"); 069 checkEmptyString(dateFormatSymbols.getShortWeekdays(), "ShortWeekdays"); 070 checkEmptyString(dateFormatSymbols.getWeekdays(), "Weekdays"); 071 checkEmptyString(dateFormatSymbols.getAmPmStrings(), "AmPmStrings"); 072 073 } 074 075 private void checkEmptyString(String[] symbolArray, String category) { 076 for (String s : symbolArray) { 077 System.out.println(category + " [" + s + "]"); 078 assertTrue(category + " contains empty strings", s.length() > 0); 079 } 080 } 081 082}