metaprogramming_test.cpp 834 B

1234567891011121314151617181920212223242526272829303132
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "common/metaprogramming.h"
  5. #include <gtest/gtest.h>
  6. #include <string>
  7. #include "llvm/Support/raw_ostream.h"
  8. namespace Carbon::Testing {
  9. namespace {
  10. TEST(MetaProgrammingTest, RequiresBasic) {
  11. bool result = Requires<int, int>([](int a, int b) { return a + b; });
  12. EXPECT_TRUE(result);
  13. }
  14. struct TypeWithPrint {
  15. void Print(llvm::raw_ostream& os) const { os << "Test"; }
  16. };
  17. TEST(MetaProgrammingTest, RequiresPrintMethod) {
  18. bool result = Requires<const TypeWithPrint, llvm::raw_ostream>(
  19. [](auto&& t, auto&& out) -> decltype(t.Print(out)) {});
  20. EXPECT_TRUE(result);
  21. }
  22. } // namespace
  23. } // namespace Carbon::Testing