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

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon May 31 04:47:22 PDT 2021


rovka created this revision.
rovka added reviewers: klausler, jeanPerier.
rovka added a project: Flang.
Herald added a subscriber: jdoerfert.
rovka requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

These should already pass with the current implementation.


Repository:
  rG LLVM Github Monorepo

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
@@ -389,3 +389,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.348779.patch
Type: text/x-patch
Size: 1648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20210531/e3d7276a/attachment.bin>


More information about the flang-commits mailing list