• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2008, http://www.snakeyaml.org
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 package org.yaml.snakeyaml.issues.issue137;
17 
18 import java.io.UnsupportedEncodingException;
19 
20 import junit.framework.TestCase;
21 
22 import org.yaml.snakeyaml.Yaml;
23 
24 /**
25  * http://java.sun.com/developer/technicalArticles/Intl/Supplementary/
26  */
27 public class SupplementaryCharactersTest extends TestCase {
28 
testSupplementaryCharacter()29     public void testSupplementaryCharacter() {
30         Yaml yaml = new Yaml();
31         String parsed = (String) yaml.load("\"\\U0001f648\"");
32         assertEquals("\ud83d\ude48", parsed);
33         // System.out.println(data);
34     }
35 
testBasicMultilingualPlane()36     public void testBasicMultilingualPlane() {
37         Yaml yaml = new Yaml();
38         String parsed = (String) yaml.load("\"\\U00000041\"");
39         assertEquals("A", parsed);
40     }
41 
42     /**
43      * Supplementary Characters are dumped as binary
44      */
testDumpSupplementaryCharacter()45     public void testDumpSupplementaryCharacter() throws UnsupportedEncodingException {
46         String supplementary = "\ud83d\ude48";
47         Yaml yaml = new Yaml();
48         String output = yaml.dump(supplementary);
49         assertEquals("!!binary |-\n  8J+ZiA==\n", output);
50         byte[] binary = (byte[]) yaml.load(output);
51         String binString = new String(binary, "UTF-8");
52         assertEquals(supplementary, binString);
53     }
54 
testLoadSupplementaryCharacter()55     public void testLoadSupplementaryCharacter() {
56         try {
57             new Yaml().load("\"\ud83d\ude48\"\n");
58             fail("Are Supplementary Characters printable ?");
59         } catch (Exception e) {
60             assertEquals("special characters are not allowed", e.getMessage());
61         }
62     }
63 }
64