From 88cedc27849316273997e25bd749ef070fea1fb9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 31 May 2020 10:36:44 -0400 Subject: [PATCH] add a bunch of tests for utils::strmatch() --- unittest/utils/test_utils.cpp | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index 33fd8a9d78..0ae469f085 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -126,3 +126,59 @@ TEST(Utils, is_double_with_neg_d_exponential) { TEST(Utils, signed_double_and_d_exponential) { ASSERT_FALSE(utils::is_double("-10D-22")); } + +TEST(Utils, strmatch_beg) { + ASSERT_TRUE(utils::strmatch("rigid/small/omp","^rigid")); +} + +TEST(Utils, strmatch_mid1) { + ASSERT_TRUE(utils::strmatch("rigid/small/omp","small")); +} + +TEST(Utils, strmatch_mid2) { + ASSERT_TRUE(utils::strmatch("rigid/small/omp","omp")); +} + +TEST(Utils, strmatch_end) { + ASSERT_TRUE(utils::strmatch("rigid/small/omp","/omp$")); +} + +TEST(Utils, no_strmatch_beg) { + ASSERT_FALSE(utils::strmatch("rigid/small/omp","^small")); +} + +TEST(Utils, no_strmatch_mid) { + ASSERT_FALSE(utils::strmatch("rigid/small/omp","none")); +} + +TEST(Utils, no_strmatch_end) { + ASSERT_FALSE(utils::strmatch("rigid/small/omp","/opt$")); +} + +TEST(Utils, strmatch_whole_line) { + ASSERT_TRUE(utils::strmatch("ITEM: UNITS\n","^\\s*ITEM: UNITS\\s*$")); +} + +TEST(Utils, no_strmatch_whole_line) { + ASSERT_FALSE(utils::strmatch("ITEM: UNITS\n","^\\s*ITEM: UNIT\\s*$")); +} + +TEST(Utils, strmatch_integer_in_line) { + ASSERT_TRUE(utils::strmatch(" 5 angles\n","^\\s*\\d+\\s+angles\\s")); +} + +TEST(Utils, strmatch_float_in_line) { + ASSERT_TRUE(utils::strmatch(" 5.0 angles\n","^\\s*\\f+\\s+angles\\s")); +} + +TEST(Utils, strmatch_int_as_float_in_line) { + ASSERT_TRUE(utils::strmatch(" 5 angles\n","^\\s*\\f+\\s+angles\\s")); +} + +TEST(Utils, strmatch_char_range) { + ASSERT_TRUE(utils::strmatch("rigid","^[ip-s]+gid")); +} + +TEST(Utils, strmatch_opt_range) { + ASSERT_TRUE(utils::strmatch("rigid","^[0-9]*[p-s]igid")); +}