@@ -430,3 +430,53 @@ TYPED_TEST(RepeatTests, Repeat) {
430430 RunRepeatTest<TypeParam>(t.ncopies , t.input , t.output );
431431 }
432432}
433+
434+ // Test SPLIT()
435+ template <typename CHAR>
436+ using SplitFunction = std::function<std::size_t (const CHAR *, std::size_t ,
437+ const CHAR *, std::size_t , std::size_t , bool , const char *, int )>;
438+ using SplitFunctions = CharTypedFunctions<SplitFunction>;
439+ template <typename CHAR> struct SplitTests : public ::testing::Test {};
440+ TYPED_TEST_SUITE (SplitTests, CharacterTypes, );
441+
442+ struct SplitTestCase {
443+ const char *x, *y;
444+ std::size_t pos;
445+ bool back;
446+ std::size_t expect;
447+ };
448+
449+ template <typename CHAR>
450+ void RunSplitTests (const std::vector<SplitTestCase> &testCases,
451+ const SplitFunction<CHAR> &function) {
452+ for (const auto &t : testCases) {
453+ // Convert default character to desired kind
454+ std::size_t xLen{std::strlen (t.x )}, yLen{std::strlen (t.y )};
455+ std::basic_string<CHAR> x{t.x , t.x + xLen};
456+ std::basic_string<CHAR> y{t.y , t.y + yLen};
457+ auto got{function (x.data (), xLen, y.data (), yLen, t.pos , t.back , " " , 0 )};
458+ ASSERT_EQ (got, t.expect )
459+ << " SPLIT('" << t.x << " ','" << t.y << " ',pos=" << t.pos
460+ << " ,back=" << t.back << " ) for CHARACTER(kind=" << sizeof (CHAR)
461+ << " ): got " << got << " , expected " << t.expect ;
462+ }
463+ }
464+
465+ TYPED_TEST (SplitTests, Split) {
466+ static SplitFunctions functions{
467+ RTNAME (Split1), RTNAME (Split2), RTNAME (Split4)};
468+ static std::vector<SplitTestCase> testcases{
469+ {" one,last example," , " , " , 0 , false , 1 },
470+ {" one,last example," , " , " , 1 , false , 5 },
471+ {" one,last example," , " , " , 5 , false , 10 },
472+ {" one,last example," , " , " , 10 , false , 18 },
473+ {" one,last example," , " , " , 18 , false , 19 },
474+ {" one,last example," , " , " , 19 , true , 18 },
475+ {" one,last example," , " , " , 18 , true , 10 },
476+ {" one,last example," , " , " , 10 , true , 5 },
477+ {" one,last example," , " , " , 5 , true , 1 },
478+ {" one,last example," , " , " , 1 , true , 0 },
479+ };
480+ RunSplitTests<TypeParam>(
481+ testcases, std::get<SplitFunction<TypeParam>>(functions));
482+ }
0 commit comments