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.issue132; 17 18 import java.io.StringReader; 19 import java.util.ArrayList; 20 import java.util.List; 21 22 import junit.framework.TestCase; 23 24 import org.yaml.snakeyaml.Yaml; 25 import org.yaml.snakeyaml.events.Event; 26 import org.yaml.snakeyaml.events.ScalarEvent; 27 import org.yaml.snakeyaml.nodes.Node; 28 29 /** 30 * to test http://code.google.com/p/snakeyaml/issues/detail?id=132 31 */ 32 public class ScalarEventTagTest extends TestCase { 33 public void testLoad() { 34 Yaml yaml = new Yaml(); 35 Iterable<Event> parsed = yaml.parse(new StringReader("5")); 36 List<Event> events = new ArrayList<Event>(5); 37 for (Event event : parsed) { 38 events.add(event); 39 // System.out.println(event); 40 } 41 String tag = ((ScalarEvent) events.get(2)).getTag(); 42 assertNull("The tag should not be specified: " + tag, tag); 43 } 44 45 public void testDump() { 46 Yaml yaml = new Yaml(); 47 Node intNode = yaml.represent(7); 48 assertEquals("tag:yaml.org,2002:int", intNode.getTag().toString()); 49 // System.out.println(intNode); 50 List<Event> intEvents = yaml.serialize(intNode); 51 String tag = ((ScalarEvent) intEvents.get(2)).getTag(); 52 assertEquals("Without the tag emitter would not know how to emit '7'", 53 "tag:yaml.org,2002:int", tag); 54 // 55 Node strNode = yaml.represent("7"); 56 assertEquals("tag:yaml.org,2002:str", strNode.getTag().toString()); 57 // System.out.println(strNode); 58 } 59 } 60