1 /* 2 * Copyright (C) 2010 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.base; 18 19 import com.google.common.annotations.GwtCompatible; 20 21 import junit.framework.TestCase; 22 23 /** 24 * Unit test for {@link Ascii}. 25 * 26 * @author Craig Berry 27 */ 28 @GwtCompatible 29 public class AsciiTest extends TestCase { 30 31 /** 32 * The Unicode points {@code 00c1} and {@code 00e1} are the upper- and 33 * lowercase forms of A-with-acute-accent, {@code } and {@code }. 34 */ 35 private static final String IGNORED = 36 "`10-=~!@#$%^&*()_+[]\\{}|;':\",./<>?'\u00c1\u00e1\n"; 37 private static final String LOWER = "abcdefghijklmnopqrstuvwxyz"; 38 private static final String UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 39 40 public void testToLowerCase() { 41 assertEquals(LOWER, Ascii.toLowerCase(UPPER)); 42 assertEquals(LOWER, Ascii.toLowerCase(LOWER)); 43 assertEquals(IGNORED, Ascii.toUpperCase(IGNORED)); 44 } 45 46 public void testToUpperCase() { 47 assertEquals(UPPER, Ascii.toUpperCase(LOWER)); 48 assertEquals(UPPER, Ascii.toUpperCase(UPPER)); 49 assertEquals(IGNORED, Ascii.toUpperCase(IGNORED)); 50 } 51 52 public void testCharsIgnored() { 53 for (char c : IGNORED.toCharArray()) { 54 String str = String.valueOf(c); 55 assertTrue(str, c == Ascii.toLowerCase(c)); 56 assertTrue(str, c == Ascii.toUpperCase(c)); 57 assertFalse(str, Ascii.isLowerCase(c)); 58 assertFalse(str, Ascii.isUpperCase(c)); 59 } 60 } 61 62 public void testCharsLower() { 63 for (char c : LOWER.toCharArray()) { 64 String str = String.valueOf(c); 65 assertTrue(str, c == Ascii.toLowerCase(c)); 66 assertFalse(str, c == Ascii.toUpperCase(c)); 67 assertTrue(str, Ascii.isLowerCase(c)); 68 assertFalse(str, Ascii.isUpperCase(c)); 69 } 70 } 71 72 public void testCharsUpper() { 73 for (char c : UPPER.toCharArray()) { 74 String str = String.valueOf(c); 75 assertFalse(str, c == Ascii.toLowerCase(c)); 76 assertTrue(str, c == Ascii.toUpperCase(c)); 77 assertFalse(str, Ascii.isLowerCase(c)); 78 assertTrue(str, Ascii.isUpperCase(c)); 79 } 80 } 81 } 82