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.extensions.compactnotation;
    18
    19  import junit.framework.TestCase;
    20
    21  public class CompactConstructorTest extends TestCase {
    22
    23      public void testNoCompactData() {
    24          CompactConstructor flow = new CompactConstructor();
    25          assertNull(flow.getCompactData("scalar"));
    26          assertNull(flow.getCompactData("123"));
    27          assertNull(flow.getCompactData("(name=frame,title=My Frame)"));
    28          assertNull(flow.getCompactData("JFrame name=frame,title=My Frame)"));
    29          assertNull(flow.getCompactData("JFrame name=frame,title=My Frame"));
    30          assertNull(flow.getCompactData("JFrame(name=frame,title=My Frame"));
    31          assertNull(flow.getCompactData("JFrame(name=frame,title=My Frame)b"));
    32          assertNull(flow.getCompactData("JFrame(name=frame,title=My Frame) "));
    33          assertNull(flow.getCompactData("JFrame(name=)"));
    34          assertNull(flow.getCompactData("JFrame(=name)"));
    35      }
    36
    37      public void testGetCompactData1() {
    38          CompactConstructor flow = new CompactConstructor();
    39          CompactData data = flow.getCompactData("JFrame(name=frame)");
    40          assertNotNull(data);
    41          assertEquals("JFrame", data.getPrefix());
    42          assertEquals(1, data.getProperties().size());
    43          assertEquals("frame", data.getProperties().get("name"));
    44      }
    45
    46      public void testGetCompactData2() {
    47          CompactConstructor flow = new CompactConstructor();
    48          CompactData data = flow.getCompactData("Frame(name=frame,title=My Frame)");
    49          assertNotNull(data);
    50          assertEquals("Frame", data.getPrefix());
    51          assertEquals(2, data.getProperties().size());
    52          assertEquals("frame", data.getProperties().get("name"));
    53          assertEquals("My Frame", data.getProperties().get("title"));
    54
    55          assertNotNull(flow.getCompactData("JFrame ( name = frame , title = My Frame )"));
    56      }
    57
    58      public void testGetCompactData3() {
    59          CompactConstructor flow = new CompactConstructor();
    60          CompactData data = flow
    61                  .getCompactData("JFrame ( name = frame , title = My Frame, number= 123 )");
    62          assertNotNull(data);
    63          assertEquals("JFrame", data.getPrefix());
    64          assertEquals(3, data.getProperties().size());
    65          assertEquals("frame", data.getProperties().get("name"));
    66          assertEquals("My Frame", data.getProperties().get("title"));
    67          assertEquals("123", data.getProperties().get("number"));
    68      }
    69
    70      public void testGetCompactData4() {
    71          CompactConstructor flow = new CompactConstructor();
    72          CompactData data = flow.getCompactData("JFrame(title)");
    73          assertNotNull(data);
    74          assertEquals("JFrame", data.getPrefix());
    75          assertEquals(0, data.getProperties().size());
    76          assertEquals(1, data.getArguments().size());
    77          assertEquals("title", data.getArguments().get(0));
    78      }
    79
    80      public void testGetCompactData5() {
    81          CompactConstructor flow = new CompactConstructor();
    82          CompactData data = flow.getCompactData("JFrame(id123, title, name=foo, alignment=center)");
    83          assertNotNull(data);
    84          assertEquals("JFrame", data.getPrefix());
    85          assertEquals(2, data.getProperties().size());
    86          assertEquals(2, data.getArguments().size());
    87          assertEquals("id123", data.getArguments().get(0));
    88          assertEquals("title", data.getArguments().get(1));
    89      }
    90
    91      public void testGetCompactData6() {
    92          CompactConstructor flow = new CompactConstructor();
    93          CompactData data = flow.getCompactData("JFrame()");
    94          assertNotNull(data);
    95          assertEquals("JFrame", data.getPrefix());
    96          assertEquals(0, data.getProperties().size());
    97          assertEquals(0, data.getArguments().size());
    98      }
    99
    100     public void testGetCompactData7() {
    101         CompactConstructor flow = new CompactConstructor();
    102         CompactData data = flow.getCompactData("package.Container(name=parent, id=123)");
    103         assertNotNull(data);
    104         assertEquals("package.Container", data.getPrefix());
    105         assertEquals(2, data.getProperties().size());
    106         assertEquals(0, data.getArguments().size());
    107     }
    108
    109     public void testCompactDataToString() {
    110         CompactData data = new CompactData("foo");
    111         assertEquals("CompactData: foo {}", data.toString());
    112     }
    113 }