CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
158 lines
5.6 KiB
C++
158 lines
5.6 KiB
C++
//===-- ObjCLanguageTest.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 "Plugins/Language/ObjC/ObjCLanguage.h"
|
|
#include "lldb/lldb-enumerations.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
#include <optional>
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
using namespace lldb_private;
|
|
|
|
TEST(ObjCLanguage, MethodNameParsing) {
|
|
struct TestCase {
|
|
llvm::StringRef input;
|
|
llvm::StringRef full_name_sans_category;
|
|
llvm::StringRef class_name;
|
|
llvm::StringRef class_name_with_category;
|
|
llvm::StringRef category;
|
|
llvm::StringRef selector;
|
|
};
|
|
|
|
TestCase strict_cases[] = {
|
|
{"-[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
|
|
{"+[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
|
|
{"-[MyClass(my_category) mySelector:]", "-[MyClass mySelector:]",
|
|
"MyClass", "MyClass(my_category)", "my_category", "mySelector:"},
|
|
{"+[MyClass(my_category) mySelector:]", "+[MyClass mySelector:]",
|
|
"MyClass", "MyClass(my_category)", "my_category", "mySelector:"},
|
|
};
|
|
|
|
TestCase lax_cases[] = {
|
|
{"[MyClass mySelector:]", "", "MyClass", "MyClass", "", "mySelector:"},
|
|
{"[MyClass(my_category) mySelector:]", "[MyClass mySelector:]", "MyClass",
|
|
"MyClass(my_category)", "my_category", "mySelector:"},
|
|
};
|
|
|
|
// First, be strict
|
|
for (const auto &test : strict_cases) {
|
|
std::optional<const ObjCLanguage::ObjCMethodName> method =
|
|
ObjCLanguage::ObjCMethodName::Create(test.input, /*strict = */ true);
|
|
EXPECT_TRUE(method.has_value());
|
|
EXPECT_EQ(test.full_name_sans_category,
|
|
method->GetFullNameWithoutCategory());
|
|
EXPECT_EQ(test.class_name, method->GetClassName());
|
|
EXPECT_EQ(test.class_name_with_category,
|
|
method->GetClassNameWithCategory());
|
|
EXPECT_EQ(test.category, method->GetCategory());
|
|
EXPECT_EQ(test.selector, method->GetSelector());
|
|
}
|
|
|
|
// We should make sure strict parsing does not accept lax cases
|
|
for (const auto &test : lax_cases) {
|
|
std::optional<const ObjCLanguage::ObjCMethodName> method =
|
|
ObjCLanguage::ObjCMethodName::Create(test.input, /*strict = */ true);
|
|
EXPECT_FALSE(method.has_value());
|
|
}
|
|
|
|
// All strict cases should work when not lax
|
|
for (const auto &test : strict_cases) {
|
|
std::optional<const ObjCLanguage::ObjCMethodName> method =
|
|
ObjCLanguage::ObjCMethodName::Create(test.input, /*strict = */ false);
|
|
EXPECT_TRUE(method.has_value());
|
|
EXPECT_EQ(test.full_name_sans_category,
|
|
method->GetFullNameWithoutCategory());
|
|
EXPECT_EQ(test.class_name, method->GetClassName());
|
|
EXPECT_EQ(test.class_name_with_category,
|
|
method->GetClassNameWithCategory());
|
|
EXPECT_EQ(test.category, method->GetCategory());
|
|
EXPECT_EQ(test.selector, method->GetSelector());
|
|
}
|
|
|
|
// Make sure non-strict parsing works
|
|
for (const auto &test : lax_cases) {
|
|
std::optional<const ObjCLanguage::ObjCMethodName> method =
|
|
ObjCLanguage::ObjCMethodName::Create(test.input, /*strict = */ false);
|
|
EXPECT_TRUE(method.has_value());
|
|
EXPECT_EQ(test.full_name_sans_category,
|
|
method->GetFullNameWithoutCategory());
|
|
EXPECT_EQ(test.class_name, method->GetClassName());
|
|
EXPECT_EQ(test.class_name_with_category,
|
|
method->GetClassNameWithCategory());
|
|
EXPECT_EQ(test.category, method->GetCategory());
|
|
EXPECT_EQ(test.selector, method->GetSelector());
|
|
}
|
|
}
|
|
|
|
TEST(ObjCLanguage, InvalidMethodNameParsing) {
|
|
// Tests that we correctly reject malformed function names
|
|
|
|
llvm::StringRef test_cases[] = {"+[Uh oh!",
|
|
"-[Definitely not...",
|
|
"[Nice try ] :)",
|
|
"+MaybeIfYouSquintYourEyes]",
|
|
"?[Tricky]",
|
|
"+[]",
|
|
"-[]",
|
|
"[]"};
|
|
|
|
for (const auto &name : test_cases) {
|
|
std::optional<const ObjCLanguage::ObjCMethodName> strict_method =
|
|
ObjCLanguage::ObjCMethodName::Create(name, /*strict = */ false);
|
|
EXPECT_FALSE(strict_method.has_value());
|
|
|
|
std::optional<const ObjCLanguage::ObjCMethodName> lax_method =
|
|
ObjCLanguage::ObjCMethodName::Create(name, /*strict = */ false);
|
|
EXPECT_FALSE(lax_method.has_value());
|
|
}
|
|
}
|
|
|
|
struct ObjCMethodTestCase {
|
|
llvm::StringRef name;
|
|
bool is_valid;
|
|
};
|
|
|
|
struct ObjCMethodNameTextFiture
|
|
: public testing::TestWithParam<ObjCMethodTestCase> {};
|
|
|
|
static ObjCMethodTestCase g_objc_method_name_test_cases[] = {
|
|
{"", false},
|
|
{"+[Uh oh!", false},
|
|
{"-[Definitely not...", false},
|
|
{"[Nice try ] :)", false},
|
|
{"+MaybeIfYouSquintYourEyes]", false},
|
|
{"?[Tricky]", false},
|
|
{"[]", false},
|
|
{"-[a", false},
|
|
{"+[a", false},
|
|
{"-]a]", false},
|
|
{"+]a]", false},
|
|
|
|
// FIXME: should these count as valid?
|
|
{"+[]", true},
|
|
{"-[]", true},
|
|
{"-[[]", true},
|
|
{"+[[]", true},
|
|
{"+[a ]", true},
|
|
{"-[a ]", true},
|
|
|
|
// Valid names
|
|
{"+[a a]", true},
|
|
{"-[a a]", true},
|
|
};
|
|
|
|
TEST_P(ObjCMethodNameTextFiture, TestIsPossibleObjCMethodName) {
|
|
// Tests ObjCLanguage::IsPossibleObjCMethodName
|
|
auto [name, expect_valid] = GetParam();
|
|
EXPECT_EQ(ObjCLanguage::IsPossibleObjCMethodName(name), expect_valid);
|
|
}
|
|
|
|
INSTANTIATE_TEST_SUITE_P(ObjCMethodNameTests, ObjCMethodNameTextFiture,
|
|
testing::ValuesIn(g_objc_method_name_test_cases));
|