Debian Codegraph @

test/com/google/javascript/jscomp/XtbMessageBundleTest.java

raw symbols SCIP
1 /*
2 * Copyright 2006 The Closure Compiler 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.javascript.jscomp;
18
19 import static com.google.common.base.Charsets.UTF_8;
20
21 import junit.framework.TestCase;
22
23 import java.io.ByteArrayInputStream;
24 import java.io.InputStream;
25
26 /**
27 * Tests {@link XtbMessageBundle}.
28 *
29 */
30 public class XtbMessageBundleTest extends TestCase {
31
32 private final static String PROJECT_ID = "TestProject";
33
34 private static final String XTB =
35 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
36 + "<!DOCTYPE translationbundle SYSTEM"
37 + " \"translationbundle.dtd\">\n"
38 + "<translationbundle lang=\"zh-HK\">\n"
39 + "<translation id=\"7639678437384034548\">descargar</translation>\n"
40 + "<translation id=\"2398375912250604550\">Se han\nignorado"
41 + " <ph name=\"NUM\"/> conversaciones.</translation>\n"
42 + "<translation id=\"6323937743550839320\"><ph name=\"P_START\"/>Si,"
43 + " puede <ph name=\"LINK_START_1_3\"/>hacer"
44 + " clic<ph name=\"LINK_END_1_3\"/>"
45 + " para utilizar.<ph name=\"P_END\"/><ph name=\"P_START\"/>Esperamos"
46 + " poder ampliar.<ph name=\"P_END\"/></translation>\n"
47 + "<translation id=\"3945720239421293834\"></translation>\n"
48 + "</translationbundle>";
49
50 public void test() {
51 InputStream stream = new ByteArrayInputStream(XTB.getBytes(UTF_8));
52 XtbMessageBundle bundle = new XtbMessageBundle(
53 stream, PROJECT_ID);
54
55 JsMessage message = bundle.getMessage("7639678437384034548");
56 assertEquals("descargar", message.toString());
57
58 message = bundle.getMessage("2398375912250604550");
59 assertEquals("Se han\nignorado {$num} conversaciones.",
60 message.toString());
61
62 message = bundle.getMessage("6323937743550839320");
63 assertEquals("{$pStart}Si, puede {$linkStart_1_3}hacer "
64 + "clic{$linkEnd_1_3} para utilizar.{$pEnd}{$pStart}Esperamos "
65 + "poder ampliar.{$pEnd}",
66 message.toString());
67
68 message = bundle.getMessage("3945720239421293834");
69 assertEquals("", message.toString());
70 assertFalse(message.parts().isEmpty());
71 }
72 }