View Javadoc

1   /**
2    * Copyright (c) 2008-2012, 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.tokens;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import junit.framework.TestCase;
22  
23  import org.yaml.snakeyaml.error.Mark;
24  import org.yaml.snakeyaml.tokens.Token.ID;
25  
26  public class DirectiveTokenTest extends TestCase {
27  
28      public void testGetArguments() {
29          Mark mark = new Mark("test1", 0, 0, 0, "*The first line.\nThe last line.", 0);
30          DirectiveToken<Integer> token = new DirectiveToken<Integer>("YAML", null, mark, mark);
31          assertEquals("name=YAML", token.getArguments());
32      }
33  
34      public void testInvalidList() {
35          Mark mark = new Mark("test1", 0, 0, 0, "*The first line.\nThe last line.", 0);
36          List<Integer> list = new ArrayList<Integer>();
37          list.add(new Integer(1));
38          try {
39              new DirectiveToken<Integer>("YAML", list, mark, mark);
40              fail("List must have 2 values.");
41          } catch (Exception e) {
42              assertEquals("Two strings must be provided instead of 1", e.getMessage());
43          }
44      }
45  
46      public void testTag() {
47          Mark mark = new Mark("test1", 0, 0, 0, "*The first line.\nThe last line.", 0);
48          List<String> list = new ArrayList<String>();
49          list.add("!foo");
50          list.add("!bar");
51          DirectiveToken<String> token = new DirectiveToken<String>("TAG", list, mark, mark);
52          assertEquals("name=TAG, value=[!foo, !bar]", token.getArguments());
53      }
54  
55      public void testList() {
56          Mark mark = new Mark("test1", 0, 0, 0, "*The first line.\nThe last line.", 0);
57          List<Integer> list = new ArrayList<Integer>();
58          list.add(new Integer(1));
59          list.add(new Integer(1));
60          DirectiveToken<Integer> token = new DirectiveToken<Integer>("YAML", list, mark, mark);
61          assertEquals("name=YAML, value=[1, 1]", token.getArguments());
62      }
63  
64      public void testGetTokenId() {
65          Mark mark = new Mark("test1", 0, 0, 0, "*The first line.\nThe last line.", 0);
66          DirectiveToken<Integer> token = new DirectiveToken<Integer>("YAML", null, mark, mark);
67          assertEquals(ID.Directive, token.getTokenId());
68      }
69  }