blob: 7211f8ad7763330b84003ff93a146aa3125167a3 (
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.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* @author hmusum
*/
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());
}
}
|