[flang-commits] [PATCH] D103402: [flang] Add tests for REPEAT. NFC

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Jun 2 01:29:22 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG5f25145306e7: [flang] Add tests for REPEAT. NFC (authored by rovka).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103402/new/

https://reviews.llvm.org/D103402

Files:
  flang/unittests/RuntimeGTest/CharacterTest.cpp


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103402.349193.patch
Type: text/x-patch
Size: 1648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210602/02568223/attachment.bin>


More information about the flang-commits mailing list