brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · dbaf9ee Raw
72 lines · cpp
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "ClientLauncher.h"10#include "llvm/ADT/StringRef.h"11#include "gtest/gtest.h"12#include <optional>13 14using namespace lldb_dap;15using namespace llvm;16 17TEST(ClientLauncherTest, GetClientFromVSCode) {18  std::optional<ClientLauncher::Client> result =19      ClientLauncher::GetClientFrom("vscode");20  ASSERT_TRUE(result.has_value());21  EXPECT_EQ(ClientLauncher::VSCode, result.value());22}23 24TEST(ClientLauncherTest, GetClientFromVSCodeUpperCase) {25  std::optional<ClientLauncher::Client> result =26      ClientLauncher::GetClientFrom("VSCODE");27  ASSERT_TRUE(result.has_value());28  EXPECT_EQ(ClientLauncher::VSCode, result.value());29}30 31TEST(ClientLauncherTest, GetClientFromVSCodeMixedCase) {32  std::optional<ClientLauncher::Client> result =33      ClientLauncher::GetClientFrom("VSCode");34  ASSERT_TRUE(result.has_value());35  EXPECT_EQ(ClientLauncher::VSCode, result.value());36}37 38TEST(ClientLauncherTest, GetClientFromInvalidString) {39  std::optional<ClientLauncher::Client> result =40      ClientLauncher::GetClientFrom("invalid");41  EXPECT_FALSE(result.has_value());42}43 44TEST(ClientLauncherTest, GetClientFromEmptyString) {45  std::optional<ClientLauncher::Client> result =46      ClientLauncher::GetClientFrom("");47  EXPECT_FALSE(result.has_value());48}49 50TEST(ClientLauncherTest, URLEncode) {51  EXPECT_EQ("", VSCodeLauncher::URLEncode(""));52  EXPECT_EQ(53      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~",54      VSCodeLauncher::URLEncode("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRST"55                                "UVWXYZ0123456789-_.~"));56  EXPECT_EQ("hello%20world", VSCodeLauncher::URLEncode("hello world"));57  EXPECT_EQ("hello%21%40%23%24", VSCodeLauncher::URLEncode("hello!@#$"));58  EXPECT_EQ("%2Fpath%2Fto%2Ffile", VSCodeLauncher::URLEncode("/path/to/file"));59  EXPECT_EQ("key%3Dvalue%26key2%3Dvalue2",60            VSCodeLauncher::URLEncode("key=value&key2=value2"));61  EXPECT_EQ("100%25complete", VSCodeLauncher::URLEncode("100%complete"));62  EXPECT_EQ("file_name%20with%20spaces%20%26%20special%21.txt",63            VSCodeLauncher::URLEncode("file_name with spaces & special!.txt"));64  EXPECT_EQ("%00%01%02",65            VSCodeLauncher::URLEncode(llvm::StringRef("\x00\x01\x02", 3)));66  EXPECT_EQ("test-file_name.txt~",67            VSCodeLauncher::URLEncode("test-file_name.txt~"));68 69  // UTF-8 encoded characters should be percent-encoded byte by byte.70  EXPECT_EQ("%C3%A9", VSCodeLauncher::URLEncode("é"));71}72