diff --git a/tests/inifile/README b/tests/inifile/README new file mode 100644 index 00000000000..8236667d727 --- /dev/null +++ b/tests/inifile/README @@ -0,0 +1,4 @@ +Tests for the library `liblinuxcncini`. + +This is the library created from the files `src/libnml/inifile/inifile.*`. To +simplify the testing we utilize the application `inivar`. diff --git a/tests/inifile/comments/README b/tests/inifile/comments/README new file mode 100644 index 00000000000..b857ecf4e29 --- /dev/null +++ b/tests/inifile/comments/README @@ -0,0 +1,4 @@ +Test the INI parser with regards to comments, both inline and on it's own line. + +After 2.7.x, the INI parser in LinuxCNC does not support inline comments. +See: https://github.com/LinuxCNC/linuxcnc/issues/991 diff --git a/tests/inifile/comments/expected b/tests/inifile/comments/expected new file mode 100644 index 00000000000..8ac35c677db --- /dev/null +++ b/tests/inifile/comments/expected @@ -0,0 +1,4 @@ +value1 +value2 ; inline comment +value3 +value4 # another inline comment diff --git a/tests/inifile/comments/test.sh b/tests/inifile/comments/test.sh new file mode 100755 index 00000000000..7cc5014aec8 --- /dev/null +++ b/tests/inifile/comments/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +inivar -ini with_comments.ini -var key1 +inivar -ini with_comments.ini -var key2 +inivar -ini with_comments.ini -var key3 +inivar -ini with_comments.ini -var key4 diff --git a/tests/inifile/comments/with_comments.ini b/tests/inifile/comments/with_comments.ini new file mode 100644 index 00000000000..ec99f448e1b --- /dev/null +++ b/tests/inifile/comments/with_comments.ini @@ -0,0 +1,8 @@ +; This is a comment +[section1] +key1=value1 +; Another comment +key2=value2 ; inline comment +# different comment style +key3=value3 +key4=value4 # another inline comment diff --git a/tests/inifile/continuation_lines/continuation_lines.ini b/tests/inifile/continuation_lines/continuation_lines.ini new file mode 100644 index 00000000000..7174c3bec17 --- /dev/null +++ b/tests/inifile/continuation_lines/continuation_lines.ini @@ -0,0 +1,7 @@ +[section1] +key1=value1 +key2=value2 \ +value3 \ +value4 \ +value5 +key3=value6 diff --git a/tests/inifile/continuation_lines/expected b/tests/inifile/continuation_lines/expected new file mode 100644 index 00000000000..e549de8f7ba --- /dev/null +++ b/tests/inifile/continuation_lines/expected @@ -0,0 +1 @@ +value2 value3 value4 value5 diff --git a/tests/inifile/continuation_lines/test.sh b/tests/inifile/continuation_lines/test.sh new file mode 100755 index 00000000000..ad90138e5cd --- /dev/null +++ b/tests/inifile/continuation_lines/test.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +inivar -ini continuation_lines.ini -var key2 diff --git a/tests/inifile/duplicated_keys/duplicated_keys.ini b/tests/inifile/duplicated_keys/duplicated_keys.ini new file mode 100644 index 00000000000..5c5603fc241 --- /dev/null +++ b/tests/inifile/duplicated_keys/duplicated_keys.ini @@ -0,0 +1,7 @@ +[section1] +key1=value1 +key1=value2 + +[section2] +key1=value3 +key1=value4 diff --git a/tests/inifile/duplicated_keys/expected b/tests/inifile/duplicated_keys/expected new file mode 100644 index 00000000000..4618098064d --- /dev/null +++ b/tests/inifile/duplicated_keys/expected @@ -0,0 +1,4 @@ +value1 +value1 +value4 +value3 diff --git a/tests/inifile/duplicated_keys/test.sh b/tests/inifile/duplicated_keys/test.sh new file mode 100755 index 00000000000..2e72e3d8660 --- /dev/null +++ b/tests/inifile/duplicated_keys/test.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +inivar -ini duplicated_keys.ini -var key1 +inivar -ini duplicated_keys.ini -var key1 -sec section1 -num 1 +inivar -ini duplicated_keys.ini -var key1 -sec section2 -num 2 +inivar -ini duplicated_keys.ini -var key1 -num 3 diff --git a/tests/inifile/line_endings/README b/tests/inifile/line_endings/README new file mode 100644 index 00000000000..a301f3fc057 --- /dev/null +++ b/tests/inifile/line_endings/README @@ -0,0 +1,5 @@ +The INI parser in LinuxCNC handles UNIX line endings, '\n' and DOS '\r\n', with + a warning. The parser aborts when it encounters classic MAC OS line endings '\r'. + +The INI files is created in the test script, since several tools automatically +fixes the line endings. diff --git a/tests/inifile/line_endings/expected b/tests/inifile/line_endings/expected new file mode 100644 index 00000000000..1b030bc1649 --- /dev/null +++ b/tests/inifile/line_endings/expected @@ -0,0 +1,2 @@ +value1 +value1 diff --git a/tests/inifile/line_endings/test.sh b/tests/inifile/line_endings/test.sh new file mode 100755 index 00000000000..dbe5b0e7d59 --- /dev/null +++ b/tests/inifile/line_endings/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Manually create INI files with different line endings. +lf="[section1]\nkey1=value1\n" +cr="[section1]\rkey1=value1\r" +crlf="[section1]\r\nkey1=value1\r\n" + +echo -e "$lf" > "lf.ini" +echo -e "$cr" > "cr.ini" +echo -e "$crlf" > "crlf.ini" + +inivar -ini lf.ini -var key1 # Should be successful. +inivar -ini cr.ini -var key1 # Should fail. +inivar -ini crlf.ini -var key1 # Should be successful. + +rm -f lf.ini cr.ini crlf.ini diff --git a/tests/inifile/missing_values/expected b/tests/inifile/missing_values/expected new file mode 100644 index 00000000000..ef208405fde --- /dev/null +++ b/tests/inifile/missing_values/expected @@ -0,0 +1 @@ +value1 diff --git a/tests/inifile/missing_values/missing_section.ini b/tests/inifile/missing_values/missing_section.ini new file mode 100644 index 00000000000..5dec89adcc4 --- /dev/null +++ b/tests/inifile/missing_values/missing_section.ini @@ -0,0 +1 @@ +key1=value1 diff --git a/tests/inifile/missing_values/missing_value.ini b/tests/inifile/missing_values/missing_value.ini new file mode 100644 index 00000000000..02be8d71b08 --- /dev/null +++ b/tests/inifile/missing_values/missing_value.ini @@ -0,0 +1,2 @@ +[section1] +key1= diff --git a/tests/inifile/missing_values/test.sh b/tests/inifile/missing_values/test.sh new file mode 100755 index 00000000000..a585d2aac56 --- /dev/null +++ b/tests/inifile/missing_values/test.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +inivar -ini missing_section.ini -sec section1 -var key1 +inivar -ini missing_value.ini -var key1 +inivar -ini missing_section.ini -var key1 diff --git a/tests/inifile/python_bindings/expected b/tests/inifile/python_bindings/expected new file mode 100644 index 00000000000..bc0832a78c9 --- /dev/null +++ b/tests/inifile/python_bindings/expected @@ -0,0 +1,6 @@ +value1 +value2 +value3 +Did not find missing value +a long value +0.000001 diff --git a/tests/inifile/python_bindings/test b/tests/inifile/python_bindings/test new file mode 100755 index 00000000000..fe859dd97a3 --- /dev/null +++ b/tests/inifile/python_bindings/test @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + +import linuxcnc + +inifile = linuxcnc.ini("values.ini") + +missing_value = inifile.find("section1", "missing") +value_with_space = inifile.find("section1", "key3") +numbered_value = inifile.find("section1", "number") +list_of_values = inifile.findall("section2", "key1") + +for value in list_of_values: + print(value) +if missing_value is None: + print("Did not find missing value") +print(value_with_space) +print(numbered_value) diff --git a/tests/inifile/python_bindings/values.ini b/tests/inifile/python_bindings/values.ini new file mode 100644 index 00000000000..f12734e5b1f --- /dev/null +++ b/tests/inifile/python_bindings/values.ini @@ -0,0 +1,12 @@ +[section1] +key1=value1 +key2=value 2 +key3 = a long value +a long key = value4 +number = 0.000001 + +[section2] +key1=value1 +key1=value2 +key1=value3 +key4=value4 diff --git a/tests/inifile/values/expected b/tests/inifile/values/expected new file mode 100644 index 00000000000..1fb3ddb78ff --- /dev/null +++ b/tests/inifile/values/expected @@ -0,0 +1,5 @@ +value1 +value 2 +a long value +value4 +0.000001 diff --git a/tests/inifile/values/test.sh b/tests/inifile/values/test.sh new file mode 100755 index 00000000000..f2588a83164 --- /dev/null +++ b/tests/inifile/values/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +inivar -ini values.ini -var key1 +inivar -ini values.ini -var key2 +inivar -ini values.ini -var key3 +inivar -ini values.ini -var "a long key" +inivar -ini values.ini -var number diff --git a/tests/inifile/values/values.ini b/tests/inifile/values/values.ini new file mode 100644 index 00000000000..d9d17f4b9c1 --- /dev/null +++ b/tests/inifile/values/values.ini @@ -0,0 +1,6 @@ +[section1] +key1=value1 +key2=value 2 +key3 = a long value +a long key = value4 +number = 0.000001 diff --git a/tests/inifile/whitespace/expected b/tests/inifile/whitespace/expected new file mode 100644 index 00000000000..a805cfcc43a --- /dev/null +++ b/tests/inifile/whitespace/expected @@ -0,0 +1,5 @@ +value1 +value1 +value1 +value1 +value2 diff --git a/tests/inifile/whitespace/leading_whitespace.ini b/tests/inifile/whitespace/leading_whitespace.ini new file mode 100644 index 00000000000..2866f0d0e81 --- /dev/null +++ b/tests/inifile/whitespace/leading_whitespace.ini @@ -0,0 +1,2 @@ + [section1] + key1=value1 diff --git a/tests/inifile/whitespace/space_between_equal.ini b/tests/inifile/whitespace/space_between_equal.ini new file mode 100644 index 00000000000..ace67077f69 --- /dev/null +++ b/tests/inifile/whitespace/space_between_equal.ini @@ -0,0 +1,2 @@ +[section1] +key1 = value1 diff --git a/tests/inifile/whitespace/test.sh b/tests/inifile/whitespace/test.sh new file mode 100755 index 00000000000..df1a3f566a5 --- /dev/null +++ b/tests/inifile/whitespace/test.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Manually create INI file with trailing whitespace. +ini_content="[section1] \nkey1=value1\t\nkey2=value2 \n" +echo -e "$ini_content" > "trailing_whitespace.ini" + +inivar -ini leading_whitespace.ini -var key1 +inivar -ini leading_whitespace.ini -sec section1 -var key1 +inivar -ini space_between_equal.ini -var key1 +inivar -ini trailing_whitespace.ini -var key1 +inivar -ini trailing_whitespace.ini -var key2 + +rm -f trailing_whitespace.ini