From 2cf9d2f22a73a1a21c4dcbe9d66193f0e6ce09e1 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Wed, 5 Jun 2024 00:15:21 +0200 Subject: [PATCH] Added test case for common::id_t --- tests/CMakeLists.txt | 1 + tests/test_types.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 tests/test_types.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 862b36cd..8a106be2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -84,6 +84,7 @@ if(APPLE) endif(APPLE) set(TEST_NAMES + test_types test_util test_model test_cases diff --git a/tests/test_types.cc b/tests/test_types.cc new file mode 100644 index 00000000..439973ab --- /dev/null +++ b/tests/test_types.cc @@ -0,0 +1,43 @@ +/** + * @file tests/test_types.cc + * + * Copyright (c) 2021-2024 Bartek Kryza + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN + +#include "common/types.h" + +#include "doctest/doctest.h" + +TEST_CASE("Test common::id_t") +{ + using namespace clanguml; + + common::id_t empty{}; + + REQUIRE(empty.is_global()); + REQUIRE_EQ(empty.value(), 0); + + common::id_t local_id{(int64_t)100}; + REQUIRE_EQ(local_id.ast_local_value(), 100); + REQUIRE_EQ(local_id.value(), 100); + REQUIRE(!local_id.is_global()); + + common::id_t global_id{(uint64_t)100}; + REQUIRE_EQ(global_id.value(), 100); + REQUIRE(global_id.is_global()); + + REQUIRE(local_id != global_id); +} \ No newline at end of file