1bc0a9a17SJim Ingham //===-- ArgsTest.cpp ------------------------------------------------------===//
2bc0a9a17SJim Ingham //
3bc0a9a17SJim Ingham // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4bc0a9a17SJim Ingham // See https://llvm.org/LICENSE.txt for license information.
5bc0a9a17SJim Ingham // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6bc0a9a17SJim Ingham //
7bc0a9a17SJim Ingham //===----------------------------------------------------------------------===//
8bc0a9a17SJim Ingham
9bc0a9a17SJim Ingham #include "lldb/Interpreter/OptionValueFileColonLine.h"
10bc0a9a17SJim Ingham #include "lldb/Utility/FileSpec.h"
11bc0a9a17SJim Ingham #include "lldb/Utility/Status.h"
12bc0a9a17SJim Ingham #include "gtest/gtest.h"
13bc0a9a17SJim Ingham
14bc0a9a17SJim Ingham using namespace lldb_private;
15bc0a9a17SJim Ingham
CheckSetting(const char * input,bool success,FileSpec path={},uint32_t line_number=LLDB_INVALID_LINE_NUMBER,uint32_t column_number=LLDB_INVALID_COLUMN_NUMBER)16*cb592679SJonas Devlieghere void CheckSetting(const char *input, bool success, FileSpec path = {},
17138244f0SJonas Devlieghere uint32_t line_number = LLDB_INVALID_LINE_NUMBER,
18138244f0SJonas Devlieghere uint32_t column_number = LLDB_INVALID_COLUMN_NUMBER) {
19bc0a9a17SJim Ingham
20bc0a9a17SJim Ingham OptionValueFileColonLine value;
21bc0a9a17SJim Ingham Status error;
22bc0a9a17SJim Ingham llvm::StringRef s_ref(input);
23bc0a9a17SJim Ingham error = value.SetValueFromString(s_ref);
24bc0a9a17SJim Ingham ASSERT_EQ(error.Success(), success);
25bc0a9a17SJim Ingham
26bc0a9a17SJim Ingham // If we were meant to fail, we don't need to do more checks:
27bc0a9a17SJim Ingham if (!success)
28bc0a9a17SJim Ingham return;
29bc0a9a17SJim Ingham
30bc0a9a17SJim Ingham ASSERT_EQ(value.GetLineNumber(), line_number);
31bc0a9a17SJim Ingham ASSERT_EQ(value.GetColumnNumber(), column_number);
32*cb592679SJonas Devlieghere ASSERT_EQ(value.GetFileSpec(), path);
33bc0a9a17SJim Ingham }
34bc0a9a17SJim Ingham
TEST(OptionValueFileColonLine,setFromString)35bc0a9a17SJim Ingham TEST(OptionValueFileColonLine, setFromString) {
36bc0a9a17SJim Ingham OptionValueFileColonLine value;
37bc0a9a17SJim Ingham Status error;
38bc0a9a17SJim Ingham
39bc0a9a17SJim Ingham // Make sure a default constructed value is invalid:
40138244f0SJonas Devlieghere ASSERT_EQ(value.GetLineNumber(),
41138244f0SJonas Devlieghere static_cast<uint32_t>(LLDB_INVALID_LINE_NUMBER));
42138244f0SJonas Devlieghere ASSERT_EQ(value.GetColumnNumber(),
43138244f0SJonas Devlieghere static_cast<uint32_t>(LLDB_INVALID_COLUMN_NUMBER));
44bc0a9a17SJim Ingham ASSERT_FALSE(value.GetFileSpec());
45bc0a9a17SJim Ingham
46bc0a9a17SJim Ingham // Make sure it is an error to pass a specifier with no line number:
47bc0a9a17SJim Ingham CheckSetting("foo.c", false);
48bc0a9a17SJim Ingham
49bc0a9a17SJim Ingham // Now try with just a file & line:
50*cb592679SJonas Devlieghere CheckSetting("foo.c:12", true, FileSpec("foo.c"), 12);
51*cb592679SJonas Devlieghere CheckSetting("foo.c:12:20", true, FileSpec("foo.c"), 12, 20);
52bc0a9a17SJim Ingham // Make sure a colon doesn't mess us up:
53*cb592679SJonas Devlieghere CheckSetting("foo:bar.c:12", true, FileSpec("foo:bar.c"), 12);
54*cb592679SJonas Devlieghere CheckSetting("foo:bar.c:12:20", true, FileSpec("foo:bar.c"), 12, 20);
55bc0a9a17SJim Ingham // Try errors in the line number:
56bc0a9a17SJim Ingham CheckSetting("foo.c:12c", false);
57bc0a9a17SJim Ingham CheckSetting("foo.c:12:20c", false);
58bc0a9a17SJim Ingham }
59