View Javadoc

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