Add test coverage for multi-line option value.
authorYousong Zhou <yszhou4tech@gmail.com>
Thu, 6 Nov 2014 20:21:48 +0000 (04:21 +0800)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 25 Nov 2014 10:47:58 +0000 (11:47 +0100)
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
14 files changed:
test/references/add_section.result
test/references/export.data
test/references/export.result
test/references/get_multiline.data [new file with mode: 0644]
test/references/import.data
test/references/import.result
test/references/set_existing_option.result
test/references/set_existing_option_multiline.result [new file with mode: 0644]
test/references/set_named_section.result
test/references/set_nonexisting_option.result
test/references/set_nonexisting_option_multiline.result [new file with mode: 0644]
test/references/set_parsing_multiline.data [new file with mode: 0644]
test/tests.d/020_get
test/tests.d/030_set

index c7daab63e455d17eaeef3c1ec958fa12a7cc0a41..37e0e7d9eee71684d2e6c444afd88f5f406660fc 100644 (file)
@@ -1 +1 @@
-+add.section=type
++add.section='type'
index c7e4d39c2c33fe2bbf0469ade052cbe942e23c8a..9e4d3c9ed6b6ac3fde91ee7ff3ca8bcb6a35a740 100644 (file)
@@ -3,4 +3,9 @@ config 'type' 'section'
        option 'opt' 'val'
        list 'list_opt' 'val0'
        list 'list_opt' 'val1'
-
+       option mul_line_opt_sq 'line 1
+line 2 \
+line 3'
+       option mul_line_opt_dq "\"Hello\, \
+World.\'
+"
index bc06655f4e7a3d17577b8fb4ede38d36992fcbc4..2fa5b48b7e0753f9a905c98f77dbee1656f908fe 100644 (file)
@@ -4,4 +4,9 @@ config type 'section'
        option opt 'val'
        list list_opt 'val0'
        list list_opt 'val1'
+       option mul_line_opt_sq 'line 1
+line 2 \
+line 3'
+       option mul_line_opt_dq '"Hello, World.'\''
+'
 
diff --git a/test/references/get_multiline.data b/test/references/get_multiline.data
new file mode 100644 (file)
index 0000000..bacb804
--- /dev/null
@@ -0,0 +1,5 @@
+config 'type' 'section'
+       # Cannot preserve trailling whitespace with assertEquals.
+       option opt "\"Hello, \
+World.
+\'"
index 6a9b7377b782807d551ade2ce27505d55ce42742..a7a21ef67af27311b3997973465f45cba82d7b50 100644 (file)
@@ -4,4 +4,9 @@ config 'type' 'section'
        option 'opt' 'val'
        list 'list_opt' 'val0'
        list 'list_opt' 'val1'
-
+       option mul_line_opt_sq \''line 1
+line 2 \
+line 3'\'
+       option mul_line_opt_dq "\"Hello, \
+World.\'
+"
index 47704b85d7bdf3342f4b9bbba0bb8ec05df37759..56eb96f57336c13ab13300748e878e50bc9efda1 100644 (file)
@@ -3,4 +3,9 @@ config type 'section'
        option opt 'val'
        list list_opt 'val0'
        list list_opt 'val1'
+       option mul_line_opt_sq ''\''line 1
+line 2 \
+line 3'\'''
+       option mul_line_opt_dq '"Hello, World.'\''
+'
 
index c88deea20598dcb62bab2d8d953b0e96f85aed17..902cff30b85a869a32a8583e916aa9abb0a5ecde 100644 (file)
@@ -1 +1 @@
-set.section.opt=val
+set.section.opt='val'
diff --git a/test/references/set_existing_option_multiline.result b/test/references/set_existing_option_multiline.result
new file mode 100644 (file)
index 0000000..85e1ada
--- /dev/null
@@ -0,0 +1,2 @@
+set.section.opt='Hello,\'\''
+World"'
index 2a4145b9060f86bada9d12615a944e3432a361a4..4ee5c2e3b104aa13d8c4dfd01e6993ce3c6040bc 100644 (file)
@@ -1 +1 @@
-set.section=named
+set.section='named'
index c88deea20598dcb62bab2d8d953b0e96f85aed17..902cff30b85a869a32a8583e916aa9abb0a5ecde 100644 (file)
@@ -1 +1 @@
-set.section.opt=val
+set.section.opt='val'
diff --git a/test/references/set_nonexisting_option_multiline.result b/test/references/set_nonexisting_option_multiline.result
new file mode 100644 (file)
index 0000000..85e1ada
--- /dev/null
@@ -0,0 +1,2 @@
+set.section.opt='Hello,\'\''
+World"'
diff --git a/test/references/set_parsing_multiline.data b/test/references/set_parsing_multiline.data
new file mode 100644 (file)
index 0000000..82b7231
--- /dev/null
@@ -0,0 +1,2 @@
+config 'type' 'section'
+       option 'opt'    'val'
index ad19264a83f0b3516255438bac0e7155c4c70d0d..7fd30ba3117c6697d603e8c884b00fe7da7e1f5b 100644 (file)
@@ -31,6 +31,15 @@ test_get_option()
        assertEquals 'val' "$value"
 }
 
+test_get_option_multiline()
+{
+       cp ${REF_DIR}/get_multiline.data ${CONFIG_DIR}/test
+       value="$($UCI get test.section.opt)"
+       echo "$value"
+       assertEquals '"Hello, World.
+'\''' "$value"
+}
+
 test_get_section()
 {
        cp ${REF_DIR}/get.data ${CONFIG_DIR}/test
index 9d2ff4b990e1e5e9c37123a22cd6eb1522418549..db3c259c2695f717354728189bd7ae5a8df43981 100644 (file)
@@ -22,9 +22,25 @@ test_set_nonexisting_option()
        assertSameFile ${REF_DIR}/set_nonexisting_option.result ${CHANGES_DIR}/set
 }
 
+test_set_nonexisting_option_multiline()
+{
+       cp ${REF_DIR}/set_nonexisting_option.data ${CONFIG_DIR}/set
+       ${UCI} set set.section.opt="Hello,\'
+World\""
+       assertSameFile ${REF_DIR}/set_nonexisting_option_multiline.result ${CHANGES_DIR}/set
+}
+
 test_set_existing_option()
 {
        cp ${REF_DIR}/set_existing_option.data ${CONFIG_DIR}/set
        ${UCI} set set.section.opt=val
        assertSameFile ${REF_DIR}/set_existing_option.result ${CHANGES_DIR}/set
 }
+
+test_set_existing_option_multiline()
+{
+       cp ${REF_DIR}/set_existing_option.data ${CONFIG_DIR}/set
+       ${UCI} set set.section.opt="Hello,\'
+World\""
+       assertSameFile ${REF_DIR}/set_existing_option_multiline.result ${CHANGES_DIR}/set
+}