TestOptionArgParser.cpp
4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//===-- ArgsTest.cpp ------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
#include "lldb/Interpreter/OptionArgParser.h"
using namespace lldb_private;
TEST(OptionArgParserTest, toBoolean) {
bool success = false;
EXPECT_TRUE(
OptionArgParser::ToBoolean(llvm::StringRef("true"), false, nullptr));
EXPECT_TRUE(
OptionArgParser::ToBoolean(llvm::StringRef("on"), false, nullptr));
EXPECT_TRUE(
OptionArgParser::ToBoolean(llvm::StringRef("yes"), false, nullptr));
EXPECT_TRUE(OptionArgParser::ToBoolean(llvm::StringRef("1"), false, nullptr));
EXPECT_TRUE(
OptionArgParser::ToBoolean(llvm::StringRef("true"), false, &success));
EXPECT_TRUE(success);
EXPECT_TRUE(
OptionArgParser::ToBoolean(llvm::StringRef("on"), false, &success));
EXPECT_TRUE(success);
EXPECT_TRUE(
OptionArgParser::ToBoolean(llvm::StringRef("yes"), false, &success));
EXPECT_TRUE(success);
EXPECT_TRUE(
OptionArgParser::ToBoolean(llvm::StringRef("1"), false, &success));
EXPECT_TRUE(success);
EXPECT_FALSE(
OptionArgParser::ToBoolean(llvm::StringRef("false"), true, nullptr));
EXPECT_FALSE(
OptionArgParser::ToBoolean(llvm::StringRef("off"), true, nullptr));
EXPECT_FALSE(
OptionArgParser::ToBoolean(llvm::StringRef("no"), true, nullptr));
EXPECT_FALSE(OptionArgParser::ToBoolean(llvm::StringRef("0"), true, nullptr));
EXPECT_FALSE(
OptionArgParser::ToBoolean(llvm::StringRef("false"), true, &success));
EXPECT_TRUE(success);
EXPECT_FALSE(
OptionArgParser::ToBoolean(llvm::StringRef("off"), true, &success));
EXPECT_TRUE(success);
EXPECT_FALSE(
OptionArgParser::ToBoolean(llvm::StringRef("no"), true, &success));
EXPECT_TRUE(success);
EXPECT_FALSE(
OptionArgParser::ToBoolean(llvm::StringRef("0"), true, &success));
EXPECT_TRUE(success);
EXPECT_FALSE(
OptionArgParser::ToBoolean(llvm::StringRef("10"), false, &success));
EXPECT_FALSE(success);
EXPECT_TRUE(
OptionArgParser::ToBoolean(llvm::StringRef("10"), true, &success));
EXPECT_FALSE(success);
EXPECT_TRUE(OptionArgParser::ToBoolean(llvm::StringRef(""), true, &success));
EXPECT_FALSE(success);
}
TEST(OptionArgParserTest, toChar) {
bool success = false;
EXPECT_EQ('A', OptionArgParser::ToChar("A", 'B', nullptr));
EXPECT_EQ('B', OptionArgParser::ToChar("B", 'A', nullptr));
EXPECT_EQ('A', OptionArgParser::ToChar("A", 'B', &success));
EXPECT_TRUE(success);
EXPECT_EQ('B', OptionArgParser::ToChar("B", 'A', &success));
EXPECT_TRUE(success);
EXPECT_EQ('A', OptionArgParser::ToChar("", 'A', &success));
EXPECT_FALSE(success);
EXPECT_EQ('A', OptionArgParser::ToChar("ABC", 'A', &success));
EXPECT_FALSE(success);
}
TEST(OptionArgParserTest, toScriptLanguage) {
bool success = false;
EXPECT_EQ(lldb::eScriptLanguageDefault,
OptionArgParser::ToScriptLanguage(llvm::StringRef("default"),
lldb::eScriptLanguageNone,
nullptr));
EXPECT_EQ(lldb::eScriptLanguagePython,
OptionArgParser::ToScriptLanguage(
llvm::StringRef("python"), lldb::eScriptLanguageNone, nullptr));
EXPECT_EQ(lldb::eScriptLanguageNone,
OptionArgParser::ToScriptLanguage(
llvm::StringRef("none"), lldb::eScriptLanguagePython, nullptr));
EXPECT_EQ(lldb::eScriptLanguageDefault,
OptionArgParser::ToScriptLanguage(llvm::StringRef("default"),
lldb::eScriptLanguageNone,
&success));
EXPECT_TRUE(success);
EXPECT_EQ(lldb::eScriptLanguagePython,
OptionArgParser::ToScriptLanguage(llvm::StringRef("python"),
lldb::eScriptLanguageNone,
&success));
EXPECT_TRUE(success);
EXPECT_EQ(lldb::eScriptLanguageNone,
OptionArgParser::ToScriptLanguage(llvm::StringRef("none"),
lldb::eScriptLanguagePython,
&success));
EXPECT_TRUE(success);
EXPECT_EQ(lldb::eScriptLanguagePython,
OptionArgParser::ToScriptLanguage(llvm::StringRef("invalid"),
lldb::eScriptLanguagePython,
&success));
EXPECT_FALSE(success);
}