[Workflow] Try to fix code-formatter failing to find changes in some cases.
[llvm-project.git] / lldb / unittests / Interpreter / TestOptionValueFileColonLine.cpp
blob079c26bdd8ab7a9f2b62aa6a7fc31741ae6111d4
1 //===-- ArgsTest.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 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionValueFileColonLine.h"
10 #include "lldb/Utility/FileSpec.h"
11 #include "lldb/Utility/Status.h"
12 #include "gtest/gtest.h"
14 using namespace lldb_private;
16 void CheckSetting(const char *input, bool success, FileSpec path = {},
17 uint32_t line_number = LLDB_INVALID_LINE_NUMBER,
18 uint32_t column_number = LLDB_INVALID_COLUMN_NUMBER) {
20 OptionValueFileColonLine value;
21 Status error;
22 llvm::StringRef s_ref(input);
23 error = value.SetValueFromString(s_ref);
24 ASSERT_EQ(error.Success(), success);
26 // If we were meant to fail, we don't need to do more checks:
27 if (!success)
28 return;
30 ASSERT_EQ(value.GetLineNumber(), line_number);
31 ASSERT_EQ(value.GetColumnNumber(), column_number);
32 ASSERT_EQ(value.GetFileSpec(), path);
35 TEST(OptionValueFileColonLine, setFromString) {
36 OptionValueFileColonLine value;
37 Status error;
39 // Make sure a default constructed value is invalid:
40 ASSERT_EQ(value.GetLineNumber(),
41 static_cast<uint32_t>(LLDB_INVALID_LINE_NUMBER));
42 ASSERT_EQ(value.GetColumnNumber(),
43 static_cast<uint32_t>(LLDB_INVALID_COLUMN_NUMBER));
44 ASSERT_FALSE(value.GetFileSpec());
46 // Make sure it is an error to pass a specifier with no line number:
47 CheckSetting("foo.c", false);
49 // Now try with just a file & line:
50 CheckSetting("foo.c:12", true, FileSpec("foo.c"), 12);
51 CheckSetting("foo.c:12:20", true, FileSpec("foo.c"), 12, 20);
52 // Make sure a colon doesn't mess us up:
53 CheckSetting("foo:bar.c:12", true, FileSpec("foo:bar.c"), 12);
54 CheckSetting("foo:bar.c:12:20", true, FileSpec("foo:bar.c"), 12, 20);
55 // Try errors in the line number:
56 CheckSetting("foo.c:12c", false);
57 CheckSetting("foo.c:12:20c", false);