Balázs Benics fcd230adc6
[clang][ssaf][NFC] Move SSAF from Analysis/Scalable/ to ScalableStaticAnalysisFramework/ (#186156)
- Rename `clang/{include,lib,unittests}/Analysis/Scalable/` to
`clang/{include,lib,unittests}/ScalableStaticAnalysisFramework/Core/`
- Update header-guards with their new paths
- Rename the library `clangAnalysisScalable` to
`clangScalableStaticAnalysisFrameworkCore`
- Add a new `Clang_ScalableStaticAnalysisFramework` module to
`module.modulemap`
- Update GN build files, GitHub PR labeler, and documentation
- Harmonise license comments
- Add a missing header-guard
2026-03-13 11:50:07 +00:00

101 lines
2.8 KiB
C++

//===- EntityIdTest.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 "clang/ScalableStaticAnalysisFramework/Core/Model/EntityId.h"
#include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityIdTable.h"
#include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityName.h"
#include "clang/ScalableStaticAnalysisFramework/Core/Support/FormatProviders.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
#include <cctype>
namespace clang::ssaf {
namespace {
static bool isNonNegativeInteger(llvm::StringRef S) {
return !S.empty() &&
llvm::all_of(S, [](unsigned char C) { return std::isdigit(C); });
}
TEST(EntityIdTest, Equality) {
EntityIdTable Table;
EntityName Entity1("c:@F@foo", "", {});
EntityName Entity2("c:@F@bar", "", {});
EntityId Id1 = Table.getId(Entity1);
EntityId Id2 = Table.getId(Entity2);
EntityId Id1Copy = Table.getId(Entity1);
EXPECT_EQ(Id1, Id1Copy);
EXPECT_FALSE(Id1 != Id1Copy);
EXPECT_FALSE(Id1 < Id1Copy);
EXPECT_FALSE(Id1Copy < Id1);
EXPECT_NE(Id1, Id2);
EXPECT_FALSE(Id1 == Id2);
EXPECT_TRUE(Id1 < Id2 || Id2 < Id1);
}
TEST(EntityIdTest, LessThan) {
EntityIdTable Table;
EntityName Entity1("c:@F@aaa", "", {});
EntityName Entity2("c:@F@bbb", "", {});
EntityId Id1 = Table.getId(Entity1);
EntityId Id2 = Table.getId(Entity2);
EXPECT_TRUE(Id1 < Id2 || Id2 < Id1);
}
TEST(EntityIdTest, Transitivity) {
EntityIdTable Table;
EntityName Entity1("c:@F@xxx", "", {});
EntityName Entity2("c:@F@yyy", "", {});
EntityName Entity3("c:@F@zzz", "", {});
EntityId Ids[3] = {Table.getId(Entity1), Table.getId(Entity2),
Table.getId(Entity3)};
std::sort(Ids, Ids + 3);
EXPECT_TRUE(Ids[0] < Ids[1] && Ids[1] < Ids[2]);
}
TEST(EntityIdTest, FormatProvider) {
EntityIdTable Table;
EntityName Entity("c:@F@foo", "", {});
EntityId Id = Table.getId(Entity);
std::string S = llvm::formatv("{0}", Id).str();
llvm::StringRef Ref(S);
ASSERT_TRUE(Ref.consume_front("EntityId("));
ASSERT_TRUE(Ref.consume_back(")"));
EXPECT_TRUE(isNonNegativeInteger(Ref));
}
TEST(EntityIdTest, StreamOutput) {
EntityIdTable Table;
EntityName Entity("c:@F@foo", "", {});
EntityId Id = Table.getId(Entity);
std::string S;
llvm::raw_string_ostream(S) << Id;
llvm::StringRef Ref(S);
ASSERT_TRUE(Ref.consume_front("EntityId("));
ASSERT_TRUE(Ref.consume_back(")"));
EXPECT_TRUE(isNonNegativeInteger(Ref));
}
} // namespace
} // namespace clang::ssaf