for_range_test.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 "migrate_cpp/cpp_refactoring/for_range.h"
  5. #include "migrate_cpp/cpp_refactoring/matcher_test_base.h"
  6. namespace Carbon::Testing {
  7. namespace {
  8. class ForRangeTest : public MatcherTestBase<ForRangeFactory> {};
  9. TEST_F(ForRangeTest, Basic) {
  10. constexpr char Before[] = R"cpp(
  11. void Foo() {
  12. int items[] = {1};
  13. for (int i : items) {
  14. }
  15. }
  16. )cpp";
  17. constexpr char After[] = R"(
  18. void Foo() {
  19. int items[] = {1};
  20. for (int i in items) {
  21. }
  22. }
  23. )";
  24. ExpectReplacement(Before, After);
  25. }
  26. TEST_F(ForRangeTest, NoSpace) {
  27. // Do not mark `cpp` so that clang-format won't "fix" the `:` spacing.
  28. constexpr char Before[] = R"(
  29. void Foo() {
  30. int items[] = {1};
  31. for (int i:items) {
  32. }
  33. }
  34. )";
  35. constexpr char After[] = R"(
  36. void Foo() {
  37. int items[] = {1};
  38. for (int i in items) {
  39. }
  40. }
  41. )";
  42. ExpectReplacement(Before, After);
  43. }
  44. } // namespace
  45. } // namespace Carbon::Testing