summaryrefslogtreecommitdiffstats
path: root/config-lib/src/test/java/com/yahoo/config/StringNodeTest.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config-lib/src/test/java/com/yahoo/config/StringNodeTest.java
Publish
Diffstat (limited to 'config-lib/src/test/java/com/yahoo/config/StringNodeTest.java')
-rw-r--r--config-lib/src/test/java/com/yahoo/config/StringNodeTest.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/config-lib/src/test/java/com/yahoo/config/StringNodeTest.java b/config-lib/src/test/java/com/yahoo/config/StringNodeTest.java
new file mode 100644
index 00000000000..c0169a06559
--- /dev/null
+++ b/config-lib/src/test/java/com/yahoo/config/StringNodeTest.java
@@ -0,0 +1,46 @@
+// Copyright 2016 Yahoo Inc. 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 <a href="mailto:musum@yahoo-inc.com">Harald Musum</a>
+ * @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"));
+ }
+}