1 //===-- ArgsTest.cpp ------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "gtest/gtest.h"
10 #include "lldb/Interpreter/OptionArgParser.h"
12 using namespace lldb_private
;
14 TEST(OptionArgParserTest
, toBoolean
) {
17 OptionArgParser::ToBoolean(llvm::StringRef("true"), false, nullptr));
19 OptionArgParser::ToBoolean(llvm::StringRef("on"), false, nullptr));
21 OptionArgParser::ToBoolean(llvm::StringRef("yes"), false, nullptr));
22 EXPECT_TRUE(OptionArgParser::ToBoolean(llvm::StringRef("1"), false, nullptr));
25 OptionArgParser::ToBoolean(llvm::StringRef("true"), false, &success
));
28 OptionArgParser::ToBoolean(llvm::StringRef("on"), false, &success
));
31 OptionArgParser::ToBoolean(llvm::StringRef("yes"), false, &success
));
34 OptionArgParser::ToBoolean(llvm::StringRef("1"), false, &success
));
38 OptionArgParser::ToBoolean(llvm::StringRef("false"), true, nullptr));
40 OptionArgParser::ToBoolean(llvm::StringRef("off"), true, nullptr));
42 OptionArgParser::ToBoolean(llvm::StringRef("no"), true, nullptr));
43 EXPECT_FALSE(OptionArgParser::ToBoolean(llvm::StringRef("0"), true, nullptr));
46 OptionArgParser::ToBoolean(llvm::StringRef("false"), true, &success
));
49 OptionArgParser::ToBoolean(llvm::StringRef("off"), true, &success
));
52 OptionArgParser::ToBoolean(llvm::StringRef("no"), true, &success
));
55 OptionArgParser::ToBoolean(llvm::StringRef("0"), true, &success
));
59 OptionArgParser::ToBoolean(llvm::StringRef("10"), false, &success
));
60 EXPECT_FALSE(success
);
62 OptionArgParser::ToBoolean(llvm::StringRef("10"), true, &success
));
63 EXPECT_FALSE(success
);
64 EXPECT_TRUE(OptionArgParser::ToBoolean(llvm::StringRef(""), true, &success
));
65 EXPECT_FALSE(success
);
68 TEST(OptionArgParserTest
, toChar
) {
71 EXPECT_EQ('A', OptionArgParser::ToChar("A", 'B', nullptr));
72 EXPECT_EQ('B', OptionArgParser::ToChar("B", 'A', nullptr));
74 EXPECT_EQ('A', OptionArgParser::ToChar("A", 'B', &success
));
76 EXPECT_EQ('B', OptionArgParser::ToChar("B", 'A', &success
));
79 EXPECT_EQ('A', OptionArgParser::ToChar("", 'A', &success
));
80 EXPECT_FALSE(success
);
81 EXPECT_EQ('A', OptionArgParser::ToChar("ABC", 'A', &success
));
82 EXPECT_FALSE(success
);
85 TEST(OptionArgParserTest
, toScriptLanguage
) {
88 EXPECT_EQ(lldb::eScriptLanguageDefault
,
89 OptionArgParser::ToScriptLanguage(llvm::StringRef("default"),
90 lldb::eScriptLanguageNone
,
92 EXPECT_EQ(lldb::eScriptLanguagePython
,
93 OptionArgParser::ToScriptLanguage(
94 llvm::StringRef("python"), lldb::eScriptLanguageNone
, nullptr));
95 EXPECT_EQ(lldb::eScriptLanguageNone
,
96 OptionArgParser::ToScriptLanguage(
97 llvm::StringRef("none"), lldb::eScriptLanguagePython
, nullptr));
99 EXPECT_EQ(lldb::eScriptLanguageDefault
,
100 OptionArgParser::ToScriptLanguage(llvm::StringRef("default"),
101 lldb::eScriptLanguageNone
,
103 EXPECT_TRUE(success
);
104 EXPECT_EQ(lldb::eScriptLanguagePython
,
105 OptionArgParser::ToScriptLanguage(llvm::StringRef("python"),
106 lldb::eScriptLanguageNone
,
108 EXPECT_TRUE(success
);
109 EXPECT_EQ(lldb::eScriptLanguageNone
,
110 OptionArgParser::ToScriptLanguage(llvm::StringRef("none"),
111 lldb::eScriptLanguagePython
,
113 EXPECT_TRUE(success
);
115 EXPECT_EQ(lldb::eScriptLanguagePython
,
116 OptionArgParser::ToScriptLanguage(llvm::StringRef("invalid"),
117 lldb::eScriptLanguagePython
,
119 EXPECT_FALSE(success
);