From 3839133a88f7de3c424f934de88a67e32523efb0 Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Fri, 2 Feb 2024 15:57:27 +0100 Subject: [PATCH] Testing reading star formatted files with leading whitespaces --- modules/io/tests/test_star_parser.cc | 28 +++++++++++++++++++++ modules/io/tests/testfiles/ws-data-item.cif | 11 ++++++++ modules/io/tests/testfiles/ws_loop.cif | 9 +++++++ 3 files changed, 48 insertions(+) create mode 100644 modules/io/tests/testfiles/ws-data-item.cif create mode 100644 modules/io/tests/testfiles/ws_loop.cif diff --git a/modules/io/tests/test_star_parser.cc b/modules/io/tests/test_star_parser.cc index c97140079..62f47a6f9 100644 --- a/modules/io/tests/test_star_parser.cc +++ b/modules/io/tests/test_star_parser.cc @@ -287,6 +287,19 @@ BOOST_AUTO_TEST_CASE(star_data_item) BOOST_TEST_MESSAGE(" done."); } +BOOST_AUTO_TEST_CASE(star_ws_data_item) +{ + BOOST_TEST_MESSAGE(" Running star_ws_data_item tests..."); + std::ifstream s("testfiles/ws-data-item.cif"); + DataItemTestParser star_p(s); + BOOST_CHECK_NO_THROW(star_p.Parse()); + BOOST_CHECK_EQUAL(star_p.s1, "a"); + BOOST_CHECK_EQUAL(star_p.s2, "a b c"); + BOOST_CHECK_EQUAL(star_p.s3, "a\n b\nc"); + BOOST_CHECK_EQUAL(star_p.s4, "a'b"); + BOOST_TEST_MESSAGE(" done."); +} + BOOST_AUTO_TEST_CASE(format_diag_stream) { BOOST_TEST_MESSAGE(" Running format_diag_stream tests..."); @@ -359,6 +372,21 @@ BOOST_AUTO_TEST_CASE(star_loop) BOOST_TEST_MESSAGE(" done."); } +BOOST_AUTO_TEST_CASE(star_ws_loop) +{ + BOOST_TEST_MESSAGE(" Running star_ws_loop tests..."); + std::ifstream s("testfiles/ws_loop.cif"); + LoopTestParser star_p(s); + star_p.Parse(); + BOOST_CHECK_EQUAL(star_p.lines[0][0], "1"); + BOOST_CHECK_EQUAL(star_p.lines[0][1], "2"); + BOOST_CHECK_EQUAL(star_p.lines[0][2], "3"); + BOOST_CHECK_EQUAL(star_p.lines[1][0], "a"); + BOOST_CHECK_EQUAL(star_p.lines[1][1], "b"); + BOOST_CHECK_EQUAL(star_p.lines[1][2], "c"); + BOOST_TEST_MESSAGE(" done."); +} + BOOST_AUTO_TEST_CASE(star_items_as_row) { BOOST_TEST_MESSAGE(" Running star_items_as_row tests..."); diff --git a/modules/io/tests/testfiles/ws-data-item.cif b/modules/io/tests/testfiles/ws-data-item.cif new file mode 100644 index 000000000..bbcb35701 --- /dev/null +++ b/modules/io/tests/testfiles/ws-data-item.cif @@ -0,0 +1,11 @@ + # Intentinally comment with whitespaces, should not throw error +data_data-item + _data-item.s1 a +_data-item.s2 'a b c' +_data-item.s3 +; +a + b +c +; +_data-item.s4 'a'b' diff --git a/modules/io/tests/testfiles/ws_loop.cif b/modules/io/tests/testfiles/ws_loop.cif new file mode 100644 index 000000000..61aeabaf9 --- /dev/null +++ b/modules/io/tests/testfiles/ws_loop.cif @@ -0,0 +1,9 @@ +data_loop + +loop_ + _loop.s1 + _loop.s2 + _loop.s3 + 1 2 3 + # comment with leading whitespaces should be skipped + a b c -- GitLab