Debian Codegraph @

test/uk/me/parabola/imgfmt/app/srt/UnicodeKeyTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2014.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13 package uk.me.parabola.imgfmt.app.srt;
14
15 import java.text.Collator;
16
17 import uk.me.parabola.mkgmap.srt.SrtTextReader;
18
19 import org.junit.Before;
20 import org.junit.Test;
21
22 import static org.junit.Assert.*;
23
24 public class UnicodeKeyTest {
25
26 private Sort sort;
27
28 @Before
29 public void setUp() throws Exception {
30 sort = SrtTextReader.sortForCodepage(65001);
31
32 Collator collator = sort.getCollator();
33 collator.setStrength(Collator.TERTIARY);
34 }
35
36 @Test
37 public void testUnicodePresent() {
38 String description = sort.getDescription();
39 assertTrue(description.contains("Unicode"));
40 assertFalse(description.contains("Default"));
41 }
42
43 @Test
44 public void testEquals() {
45 String abc = "ABC\u0234\u1023";
46 SortKey<Object> key1 = sort.createSortKey(null, abc);
47 SortKey<Object> key2 = sort.createSortKey(null, abc);
48
49 assertEquals(0, key1.compareTo(key2));
50 }
51
52 @Test
53 public void testSimpleLessThan() {
54 assertEquals(-1, keyCompare("G", "Ò"));
55 assertEquals(-1, keyCompare("G", "Γ"));
56 }
57
58 @Test
59 public void testExpand() {
60 assertEquals(-1, keyCompare("!", "ß"));
61 assertEquals(-1, keyCompare("A:", "Ǣ"));
62 }
63
64 private int keyCompare(String s1, String s2) {
65 SortKey<Object> k1 = sort.createSortKey(null, s1);
66 SortKey<Object> k2 = sort.createSortKey(null, s2);
67 System.out.println("K1: " + k1);
68 System.out.println("K2: " + k2);
69
70 return k1.compareTo(k2);
71 }
72 }