[LoongArch] Mark ISD::FNEG as legal
[llvm-project.git] / lldb / unittests / Utility / OptionsWithRawTest.cpp
blobe7b159b8d4003308c5252aed1545119b5cf98480
1 //===-- OptionsWithRawTest.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 "gtest/gtest.h"
11 #include "lldb/Utility/Args.h"
12 #include "lldb/Utility/StringList.h"
14 using namespace lldb_private;
16 TEST(OptionsWithRawTest, EmptyInput) {
17 // An empty string is just an empty suffix without any arguments.
18 OptionsWithRaw args("");
19 ASSERT_FALSE(args.HasArgs());
20 ASSERT_STREQ(args.GetRawPart().c_str(), "");
23 TEST(OptionsWithRawTest, SingleWhitespaceInput) {
24 // Only whitespace is just a suffix.
25 OptionsWithRaw args(" ");
26 ASSERT_FALSE(args.HasArgs());
27 ASSERT_STREQ(args.GetRawPart().c_str(), " ");
30 TEST(OptionsWithRawTest, WhitespaceInput) {
31 // Only whitespace is just a suffix.
32 OptionsWithRaw args(" ");
33 ASSERT_FALSE(args.HasArgs());
34 ASSERT_STREQ(args.GetRawPart().c_str(), " ");
37 TEST(OptionsWithRawTest, ArgsButNoDelimiter) {
38 // This counts as a suffix because there is no -- at the end.
39 OptionsWithRaw args("-foo bar");
40 ASSERT_FALSE(args.HasArgs());
41 ASSERT_STREQ(args.GetRawPart().c_str(), "-foo bar");
44 TEST(OptionsWithRawTest, ArgsButNoLeadingDash) {
45 // No leading dash means we have no arguments.
46 OptionsWithRaw args("foo bar --");
47 ASSERT_FALSE(args.HasArgs());
48 ASSERT_STREQ(args.GetRawPart().c_str(), "foo bar --");
51 TEST(OptionsWithRawTest, QuotedSuffix) {
52 // We need to have a way to escape the -- to make it usable as an argument.
53 OptionsWithRaw args("-foo \"--\" bar");
54 ASSERT_FALSE(args.HasArgs());
55 ASSERT_STREQ(args.GetRawPart().c_str(), "-foo \"--\" bar");
58 TEST(OptionsWithRawTest, EmptySuffix) {
59 // An empty suffix with arguments.
60 OptionsWithRaw args("-foo --");
61 ASSERT_TRUE(args.HasArgs());
62 ASSERT_EQ(args.GetArgString(), "-foo ");
63 ASSERT_EQ(args.GetArgStringWithDelimiter(), "-foo --");
65 auto ref = args.GetArgs().GetArgumentArrayRef();
66 ASSERT_EQ(1u, ref.size());
67 EXPECT_STREQ("-foo", ref[0]);
69 ASSERT_STREQ(args.GetRawPart().c_str(), "");
72 TEST(OptionsWithRawTest, EmptySuffixSingleWhitespace) {
73 // A single whitespace also countas as an empty suffix (because that usually
74 // separates the suffix from the double dash.
75 OptionsWithRaw args("-foo -- ");
76 ASSERT_TRUE(args.HasArgs());
77 ASSERT_EQ(args.GetArgString(), "-foo ");
78 ASSERT_EQ(args.GetArgStringWithDelimiter(), "-foo -- ");
80 auto ref = args.GetArgs().GetArgumentArrayRef();
81 ASSERT_EQ(1u, ref.size());
82 EXPECT_STREQ("-foo", ref[0]);
84 ASSERT_STREQ(args.GetRawPart().c_str(), "");
87 TEST(OptionsWithRawTest, WhitespaceSuffix) {
88 // A single whtiespace character as a suffix.
89 OptionsWithRaw args("-foo -- ");
90 ASSERT_TRUE(args.HasArgs());
91 ASSERT_EQ(args.GetArgString(), "-foo ");
92 ASSERT_EQ(args.GetArgStringWithDelimiter(), "-foo -- ");
94 auto ref = args.GetArgs().GetArgumentArrayRef();
95 ASSERT_EQ(1u, ref.size());
96 EXPECT_STREQ("-foo", ref[0]);
98 ASSERT_STREQ(args.GetRawPart().c_str(), " ");
101 TEST(OptionsWithRawTest, LeadingSpaceArgs) {
102 // Whitespace before the first dash needs to be ignored.
103 OptionsWithRaw args(" -foo -- bar");
104 ASSERT_TRUE(args.HasArgs());
105 ASSERT_EQ(args.GetArgString(), " -foo ");
106 ASSERT_EQ(args.GetArgStringWithDelimiter(), " -foo -- ");
108 auto ref = args.GetArgs().GetArgumentArrayRef();
109 ASSERT_EQ(1u, ref.size());
110 EXPECT_STREQ("-foo", ref[0]);
112 ASSERT_STREQ(args.GetRawPart().c_str(), "bar");
115 TEST(OptionsWithRawTest, SingleWordSuffix) {
116 // A single word as a suffix.
117 OptionsWithRaw args("-foo -- bar");
118 ASSERT_TRUE(args.HasArgs());
119 ASSERT_EQ(args.GetArgString(), "-foo ");
120 ASSERT_EQ(args.GetArgStringWithDelimiter(), "-foo -- ");
122 auto ref = args.GetArgs().GetArgumentArrayRef();
123 ASSERT_EQ(1u, ref.size());
124 EXPECT_STREQ("-foo", ref[0]);
126 ASSERT_STREQ(args.GetRawPart().c_str(), "bar");
129 TEST(OptionsWithRawTest, MultiWordSuffix) {
130 // Multiple words as a suffix.
131 OptionsWithRaw args("-foo -- bar baz");
132 ASSERT_TRUE(args.HasArgs());
133 ASSERT_EQ(args.GetArgString(), "-foo ");
134 ASSERT_EQ(args.GetArgStringWithDelimiter(), "-foo -- ");
136 auto ref = args.GetArgs().GetArgumentArrayRef();
137 ASSERT_EQ(1u, ref.size());
138 EXPECT_STREQ("-foo", ref[0]);
140 ASSERT_STREQ(args.GetRawPart().c_str(), "bar baz");
143 TEST(OptionsWithRawTest, UnterminatedQuote) {
144 // A quote character in the suffix shouldn't influence the parsing.
145 OptionsWithRaw args("-foo -- bar \" ");
146 ASSERT_TRUE(args.HasArgs());
147 ASSERT_EQ(args.GetArgString(), "-foo ");
148 ASSERT_EQ(args.GetArgStringWithDelimiter(), "-foo -- ");
150 auto ref = args.GetArgs().GetArgumentArrayRef();
151 ASSERT_EQ(1u, ref.size());
152 EXPECT_STREQ("-foo", ref[0]);
154 ASSERT_STREQ(args.GetRawPart().c_str(), "bar \" ");
157 TEST(OptionsWithRawTest, TerminatedQuote) {
158 // A part of the suffix is quoted, which shouldn't influence the parsing.
159 OptionsWithRaw args("-foo -- bar \"a\" ");
160 ASSERT_TRUE(args.HasArgs());
161 ASSERT_EQ(args.GetArgString(), "-foo ");
162 ASSERT_EQ(args.GetArgStringWithDelimiter(), "-foo -- ");
164 auto ref = args.GetArgs().GetArgumentArrayRef();
165 ASSERT_EQ(1u, ref.size());
166 EXPECT_STREQ("-foo", ref[0]);
168 ASSERT_STREQ(args.GetRawPart().c_str(), "bar \"a\" ");
171 TEST(OptionsWithRawTest, EmptyArgsOnlySuffix) {
172 // Empty argument list, but we have a suffix.
173 OptionsWithRaw args("-- bar");
174 ASSERT_TRUE(args.HasArgs());
175 ASSERT_EQ(args.GetArgString(), "");
176 ASSERT_EQ(args.GetArgStringWithDelimiter(), "-- ");
178 auto ref = args.GetArgs().GetArgumentArrayRef();
179 ASSERT_EQ(0u, ref.size());
181 ASSERT_STREQ(args.GetRawPart().c_str(), "bar");