ParsedSourceLocationTest.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //===- unittests/Frontend/ParsedSourceLocationTest.cpp - ------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "clang/Frontend/CommandLineSourceLoc.h"
  10. #include "gtest/gtest.h"
  11. using namespace llvm;
  12. using namespace clang;
  13. namespace {
  14. TEST(ParsedSourceRange, ParseTest) {
  15. auto Check = [](StringRef Value, StringRef Filename, unsigned BeginLine,
  16. unsigned BeginColumn, unsigned EndLine, unsigned EndColumn) {
  17. Optional<ParsedSourceRange> PSR = ParsedSourceRange::fromString(Value);
  18. ASSERT_TRUE(PSR);
  19. EXPECT_EQ(PSR->FileName, Filename);
  20. EXPECT_EQ(PSR->Begin.first, BeginLine);
  21. EXPECT_EQ(PSR->Begin.second, BeginColumn);
  22. EXPECT_EQ(PSR->End.first, EndLine);
  23. EXPECT_EQ(PSR->End.second, EndColumn);
  24. };
  25. Check("/Users/test/a-b.cpp:1:2", "/Users/test/a-b.cpp", 1, 2, 1, 2);
  26. Check("/Users/test/a-b.cpp:1:2-3:4", "/Users/test/a-b.cpp", 1, 2, 3, 4);
  27. Check("C:/Users/bob/a-b.cpp:1:2", "C:/Users/bob/a-b.cpp", 1, 2, 1, 2);
  28. Check("C:/Users/bob/a-b.cpp:1:2-3:4", "C:/Users/bob/a-b.cpp", 1, 2, 3, 4);
  29. }
  30. } // anonymous namespace