Index: flang/unittests/RuntimeGTest/CharacterTest.cpp =================================================================== --- flang/unittests/RuntimeGTest/CharacterTest.cpp +++ flang/unittests/RuntimeGTest/CharacterTest.cpp @@ -389,3 +389,42 @@ RunSearchTests( "VERIFY", tests, std::get>(functions)); } + +// Test REPEAT() +template struct RepeatTests : public ::testing::Test {}; +TYPED_TEST_SUITE(RepeatTests, CharacterTypes, ); + +struct RepeatTestCase { + std::size_t ncopies; + const char *input, *output; +}; + +template +void RunRepeatTest( + std::size_t ncopies, const char *inputRaw, const char *outputRaw) { + OwningPtr input{CreateDescriptor({}, {inputRaw})}; + ASSERT_NE(input, nullptr); + ASSERT_TRUE(input->IsAllocated()); + + StaticDescriptor<1> outputStaticDescriptor; + Descriptor &output{outputStaticDescriptor.descriptor()}; + + RTNAME(Repeat)(output, *input, ncopies); + std::basic_string got{ + output.OffsetElement(), output.ElementBytes() / sizeof(CHAR)}; + std::basic_string expect{outputRaw, outputRaw + std::strlen(outputRaw)}; + ASSERT_EQ(got, expect) << "'" << inputRaw << "' * " << ncopies + << "' for CHARACTER(kind=" << sizeof(CHAR) << ")"; +} + +TYPED_TEST(RepeatTests, Repeat) { + static std::vector testcases{ + {1, "just one copy", "just one copy"}, + {5, "copy.", "copy.copy.copy.copy.copy."}, + {0, "no copies", ""}, + }; + + for (const auto &t : testcases) { + RunRepeatTest(t.ncopies, t.input, t.output); + } +}