aboutsummaryrefslogtreecommitdiffstats
path: root/config-lib/src/test/java/com/yahoo/config/StringNodeTest.java
blob: 05b9361865c324be1102bde616e9f285a73e53a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config;

import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
 * @author hmusum
 * @since 5.1.7
 */
public class StringNodeTest {

    @Test
    public void testUnescapeQuotedString() {
        String a = "\"Hei\"";
        assertThat(StringNode.unescapeQuotedString(a), is("Hei"));
        assertThat(StringNode.unescapeQuotedString("foo\"bar\""), is("foo\"bar\""));
        assertThat(StringNode.unescapeQuotedString("foo\\\"bar\\\""), is("foo\"bar\""));
        assertThat(StringNode.unescapeQuotedString("a\\rb\\tc\\fd"), is("a\rb\tc\fd"));
        assertThat(StringNode.unescapeQuotedString("\\x55"), is("U"));
    }

    @Test(expected = IllegalArgumentException.class)
    public void testUnescapedQuotedStringExceptions() {
        StringNode.unescapeQuotedString("foo\\");
    }

    @Test
    public void testToString() {
        StringNode n = new StringNode();
        assertThat(n.toString(), is("(null)"));
        n.setValue("foo");
        assertThat(n.toString(), is("\"foo\""));
    }

    @Test
    public void testSetValue() {
        StringNode n = new StringNode();
        n.setValue("\"foo\"");
        assertThat(n.getValue(), is("foo"));
        n.setValue("foo");
        assertThat(n.getValue(), is("foo"));
    }
}