1 /** 2 * Copyright (c) 2008, SnakeYAML 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package org.yaml.snakeyaml.json; 15 16 import java.util.Map; 17 import junit.framework.TestCase; 18 import org.yaml.snakeyaml.Yaml; 19 20 public class JsonTest extends TestCase { 21 22 private final Yaml loader = new Yaml(); 23 24 testLooksLikeJson()25 public void testLooksLikeJson() { 26 Map<String, Integer> map = loader.load("{a: 1}"); 27 assertEquals(Integer.valueOf(1), map.get("a")); 28 } 29 testSpaceAfterColon()30 public void testSpaceAfterColon() { 31 Map<String, Integer> map = loader.load("{\"a\": 1}"); 32 assertEquals(Integer.valueOf(1), map.get("a")); 33 } 34 testNoSpace()35 public void testNoSpace() { 36 Map<String, Integer> map = loader.load("{\"a\":1}"); 37 assertEquals(Integer.valueOf(1), map.get("a")); 38 } 39 testNoSpaceBothDoubleQuoted()40 public void testNoSpaceBothDoubleQuoted() { 41 Map<String, Integer> map = loader.load("{\"a\":\"1\"}"); 42 assertEquals("1", map.get("a")); 43 } 44 testNoSpaceSingleQouted()45 public void testNoSpaceSingleQouted() { 46 Map<String, Integer> map = loader.load("{'a':1}"); 47 assertEquals(Integer.valueOf(1), map.get("a")); 48 } 49 testManyValues()50 public void testManyValues() { 51 Map<String, Object> map = loader.load("{\"a\":1,\"b\":true,\"c\":\"foo\"}"); 52 assertEquals(3, map.size()); 53 assertEquals(Integer.valueOf(1), map.get("a")); 54 assertTrue((Boolean) map.get("b")); 55 assertEquals("foo", map.get("c")); 56 } 57 testConstructNull()58 public void testConstructNull() { 59 Map<String, Object> map = loader.load("{a: null}"); 60 assertEquals(1, map.size()); 61 assertNull(map.get("a")); 62 } 63 testConstructNullFromEmpty()64 public void testConstructNullFromEmpty() { 65 Map<String, Object> map = loader.load("{a: }"); 66 assertEquals(1, map.size()); 67 assertNull(map.get("a")); 68 } 69 testConstructBoolean()70 public void testConstructBoolean() { 71 Map<String, Object> map = loader.load("{a: true}"); 72 assertEquals(1, map.size()); 73 assertEquals(Boolean.TRUE, map.get("a")); 74 } 75 } 76