Clang Project

clang_source_code/unittests/Frontend/ParsedSourceLocationTest.cpp
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
9#include "clang/Frontend/CommandLineSourceLoc.h"
10#include "gtest/gtest.h"
11
12using namespace llvm;
13using namespace clang;
14
15namespace {
16
17TEST(ParsedSourceRange, ParseTest) {
18  auto Check = [](StringRef ValueStringRef Filenameunsigned BeginLine,
19                  unsigned BeginColumnunsigned EndLineunsigned EndColumn) {
20    Optional<ParsedSourceRangePSR = ParsedSourceRange::fromString(Value);
21    ASSERT_TRUE(PSR);
22    EXPECT_EQ(PSR->FileName, Filename);
23    EXPECT_EQ(PSR->Begin.first, BeginLine);
24    EXPECT_EQ(PSR->Begin.second, BeginColumn);
25    EXPECT_EQ(PSR->End.first, EndLine);
26    EXPECT_EQ(PSR->End.second, EndColumn);
27  };
28
29  Check("/Users/test/a-b.cpp:1:2""/Users/test/a-b.cpp"1212);
30  Check("/Users/test/a-b.cpp:1:2-3:4""/Users/test/a-b.cpp"1234);
31
32  Check("C:/Users/bob/a-b.cpp:1:2""C:/Users/bob/a-b.cpp"1212);
33  Check("C:/Users/bob/a-b.cpp:1:2-3:4""C:/Users/bob/a-b.cpp"1234);
34}
35
36// anonymous namespace
37