From: Yousong Zhou Date: Thu, 6 Nov 2014 20:21:48 +0000 (+0800) Subject: Add test coverage for multi-line option value. X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ba0c2435600f57c73f3d72edc4fb650b29191499;p=oweals%2Fuci.git Add test coverage for multi-line option value. Signed-off-by: Yousong Zhou --- diff --git a/test/references/add_section.result b/test/references/add_section.result index c7daab6..37e0e7d 100644 --- a/test/references/add_section.result +++ b/test/references/add_section.result @@ -1 +1 @@ -+add.section=type ++add.section='type' diff --git a/test/references/export.data b/test/references/export.data index c7e4d39..9e4d3c9 100644 --- a/test/references/export.data +++ b/test/references/export.data @@ -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.\' +" diff --git a/test/references/export.result b/test/references/export.result index bc06655..2fa5b48 100644 --- a/test/references/export.result +++ b/test/references/export.result @@ -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 index 0000000..bacb804 --- /dev/null +++ b/test/references/get_multiline.data @@ -0,0 +1,5 @@ +config 'type' 'section' + # Cannot preserve trailling whitespace with assertEquals. + option opt "\"Hello, \ +World. +\'" diff --git a/test/references/import.data b/test/references/import.data index 6a9b737..a7a21ef 100644 --- a/test/references/import.data +++ b/test/references/import.data @@ -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/import.result b/test/references/import.result index 47704b8..56eb96f 100644 --- a/test/references/import.result +++ b/test/references/import.result @@ -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.'\'' +' diff --git a/test/references/set_existing_option.result b/test/references/set_existing_option.result index c88deea..902cff3 100644 --- a/test/references/set_existing_option.result +++ b/test/references/set_existing_option.result @@ -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 index 0000000..85e1ada --- /dev/null +++ b/test/references/set_existing_option_multiline.result @@ -0,0 +1,2 @@ +set.section.opt='Hello,\'\'' +World"' diff --git a/test/references/set_named_section.result b/test/references/set_named_section.result index 2a4145b..4ee5c2e 100644 --- a/test/references/set_named_section.result +++ b/test/references/set_named_section.result @@ -1 +1 @@ -set.section=named +set.section='named' diff --git a/test/references/set_nonexisting_option.result b/test/references/set_nonexisting_option.result index c88deea..902cff3 100644 --- a/test/references/set_nonexisting_option.result +++ b/test/references/set_nonexisting_option.result @@ -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 index 0000000..85e1ada --- /dev/null +++ b/test/references/set_nonexisting_option_multiline.result @@ -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 index 0000000..82b7231 --- /dev/null +++ b/test/references/set_parsing_multiline.data @@ -0,0 +1,2 @@ +config 'type' 'section' + option 'opt' 'val' diff --git a/test/tests.d/020_get b/test/tests.d/020_get index ad19264..7fd30ba 100644 --- a/test/tests.d/020_get +++ b/test/tests.d/020_get @@ -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 diff --git a/test/tests.d/030_set b/test/tests.d/030_set index 9d2ff4b..db3c259 100644 --- a/test/tests.d/030_set +++ b/test/tests.d/030_set @@ -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 +}