| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "lldb/Interpreter/OptionValueFileColonLine.h" |
| 10 | #include "lldb/Utility/FileSpec.h" |
| 11 | #include "lldb/Utility/Status.h" |
| 12 | #include "gtest/gtest.h" |
| 13 | |
| 14 | using namespace lldb_private; |
| 15 | |
| 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) { |
| 19 | |
| 20 | OptionValueFileColonLine value; |
| 21 | Status error; |
| 22 | llvm::StringRef s_ref(input); |
| 23 | error = value.SetValueFromString(value: s_ref); |
| 24 | ASSERT_EQ(error.Success(), success); |
| 25 | |
| 26 | // If we were meant to fail, we don't need to do more checks: |
| 27 | if (!success) |
| 28 | return; |
| 29 | |
| 30 | ASSERT_EQ(value.GetLineNumber(), line_number); |
| 31 | ASSERT_EQ(value.GetColumnNumber(), column_number); |
| 32 | ASSERT_EQ(value.GetFileSpec(), path); |
| 33 | } |
| 34 | |
| 35 | TEST(OptionValueFileColonLine, setFromString) { |
| 36 | OptionValueFileColonLine value; |
| 37 | Status error; |
| 38 | |
| 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()); |
| 45 | |
| 46 | // Make sure it is an error to pass a specifier with no line number: |
| 47 | CheckSetting(input: "foo.c" , success: false); |
| 48 | |
| 49 | // Now try with just a file & line: |
| 50 | CheckSetting(input: "foo.c:12" , success: true, path: FileSpec("foo.c" ), line_number: 12); |
| 51 | CheckSetting(input: "foo.c:12:20" , success: true, path: FileSpec("foo.c" ), line_number: 12, column_number: 20); |
| 52 | // Make sure a colon doesn't mess us up: |
| 53 | CheckSetting(input: "foo:bar.c:12" , success: true, path: FileSpec("foo:bar.c" ), line_number: 12); |
| 54 | CheckSetting(input: "foo:bar.c:12:20" , success: true, path: FileSpec("foo:bar.c" ), line_number: 12, column_number: 20); |
| 55 | // Try errors in the line number: |
| 56 | CheckSetting(input: "foo.c:12c" , success: false); |
| 57 | CheckSetting(input: "foo.c:12:20c" , success: false); |
| 58 | } |
| 59 | |