1 //===-- PlatformDarwinTest.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 "gtest/gtest.h"
10
11 #include "Plugins/Platform/MacOSX/PlatformDarwin.h"
12
13 #include "llvm/ADT/StringRef.h"
14
15 #include <tuple>
16
17 using namespace lldb;
18 using namespace lldb_private;
19
20 struct PlatformDarwinTester : public PlatformDarwin {
21 public:
22 using PlatformDarwin::FindComponentInPath;
23 };
24
TEST(PlatformDarwinTest,TestParseVersionBuildDir)25 TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
26 llvm::VersionTuple V;
27 llvm::StringRef D;
28
29 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("1.2.3 (test1)");
30 EXPECT_EQ(llvm::VersionTuple(1, 2, 3), V);
31 EXPECT_EQ("test1", D);
32
33 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("2.3 (test2)");
34 EXPECT_EQ(llvm::VersionTuple(2, 3), V);
35 EXPECT_EQ("test2", D);
36
37 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3 (test3)");
38 EXPECT_EQ(llvm::VersionTuple(3), V);
39 EXPECT_EQ("test3", D);
40
41 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("1.2.3 (test");
42 EXPECT_EQ(llvm::VersionTuple(1, 2, 3), V);
43 EXPECT_EQ("test", D);
44
45 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("2.3.4 test");
46 EXPECT_EQ(llvm::VersionTuple(2, 3, 4), V);
47 EXPECT_EQ("", D);
48
49 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3.4.5");
50 EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V);
51 }
52
TEST(PlatformDarwinTest,FindComponentInPath)53 TEST(PlatformDarwinTest, FindComponentInPath) {
54 EXPECT_EQ("/path/to/foo",
55 PlatformDarwinTester::FindComponentInPath("/path/to/foo/", "foo"));
56
57 EXPECT_EQ("/path/to/foo",
58 PlatformDarwinTester::FindComponentInPath("/path/to/foo", "foo"));
59
60 EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath(
61 "/path/to/foobar", "foo"));
62
63 EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath(
64 "/path/to/foobar", "bar"));
65
66 EXPECT_EQ("",
67 PlatformDarwinTester::FindComponentInPath("/path/to/foo", "bar"));
68 }
69