summaryrefslogtreecommitdiffstats
path: root/config-lib/src/test/java/com/yahoo/config/StringNodeTest.java
blob: d0baf8d1837593a121dac519ca2c0b078ee8abae (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
47
48
// 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.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

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

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

    @Test
    void testUnescapedQuotedStringExceptions() {
        assertThrows(IllegalArgumentException.class, () -> {
            StringNode.unescapeQuotedString("foo\\");
        });
    }

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

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