ParsedSourceLocationTest.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //===- unittests/Frontend/ParsedSourceLocationTest.cpp - ------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "clang/Frontend/CommandLineSourceLoc.h"
  9. #include "gtest/gtest.h"
  10. using namespace llvm;
  11. using namespace clang;
  12. namespace {
  13. TEST(ParsedSourceRange, ParseTest) {
  14. auto Check = [](StringRef Value, StringRef Filename, unsigned BeginLine,
  15. unsigned BeginColumn, unsigned EndLine, unsigned EndColumn) {
  16. Optional<ParsedSourceRange> PSR = ParsedSourceRange::fromString(Value);
  17. ASSERT_TRUE(PSR);
  18. EXPECT_EQ(PSR->FileName, Filename);
  19. EXPECT_EQ(PSR->Begin.first, BeginLine);
  20. EXPECT_EQ(PSR->Begin.second, BeginColumn);
  21. EXPECT_EQ(PSR->End.first, EndLine);
  22. EXPECT_EQ(PSR->End.second, EndColumn);
  23. };
  24. Check("/Users/test/a-b.cpp:1:2", "/Users/test/a-b.cpp", 1, 2, 1, 2);
  25. Check("/Users/test/a-b.cpp:1:2-3:4", "/Users/test/a-b.cpp", 1, 2, 3, 4);
  26. Check("C:/Users/bob/a-b.cpp:1:2", "C:/Users/bob/a-b.cpp", 1, 2, 1, 2);
  27. Check("C:/Users/bob/a-b.cpp:1:2-3:4", "C:/Users/bob/a-b.cpp", 1, 2, 3, 4);
  28. }
  29. } // anonymous namespace