blob: 5d606e1245412878ffe7d0078ebe9831e2a58da7 (
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
|
// 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.junit.Assert.assertEquals;
/**
* @author hmusum
* @since 5.1.7
*/
public class StringNodeTest {
@Test
public 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(expected = IllegalArgumentException.class)
public void testUnescapedQuotedStringExceptions() {
StringNode.unescapeQuotedString("foo\\");
}
@Test
public void testToString() {
StringNode n = new StringNode();
assertEquals("(null)", n.toString());
n.setValue("foo");
assertEquals("\"foo\"", n.toString());
}
@Test
public void testSetValue() {
StringNode n = new StringNode();
n.setValue("\"foo\"");
assertEquals("foo", n.getValue());
n.setValue("foo");
assertEquals("foo", n.getValue());
}
}
|