3232#include " arrow/memory_pool.h"
3333#include " arrow/table.h"
3434#include " arrow/testing/gtest_util.h"
35+ #include " arrow/testing/matchers.h"
3536#include " arrow/testing/random.h"
3637#include " arrow/testing/util.h"
3738#include " arrow/type.h"
3839#include " arrow/type_traits.h"
40+ #include " arrow/util/logging.h"
3941#include " arrow/util/checked_cast.h"
4042#include " arrow/util/key_value_metadata.h"
4143
@@ -49,6 +51,66 @@ TEST(TestTypeId, AllTypeIds) {
4951 ASSERT_EQ (static_cast <int >(all_ids.size ()), Type::MAX_ID);
5052}
5153
54+ TEST (TestTypeSingleton, ParameterFreeTypes) {
55+ // Test successful cases - parameter-free types
56+ std::vector<std::pair<Type::type, std::shared_ptr<DataType>>> cases = {
57+ {Type::NA, null ()},
58+ {Type::BOOL, boolean ()},
59+ {Type::INT8, int8 ()},
60+ {Type::INT16, int16 ()},
61+ {Type::INT32, int32 ()},
62+ {Type::INT64, int64 ()},
63+ {Type::UINT8, uint8 ()},
64+ {Type::UINT16, uint16 ()},
65+ {Type::UINT32, uint32 ()},
66+ {Type::UINT64, uint64 ()},
67+ {Type::HALF_FLOAT, float16 ()},
68+ {Type::FLOAT, float32 ()},
69+ {Type::DOUBLE, float64 ()},
70+ {Type::STRING, utf8 ()},
71+ {Type::BINARY, binary ()},
72+ {Type::LARGE_STRING, large_utf8 ()},
73+ {Type::LARGE_BINARY, large_binary ()},
74+ {Type::DATE32, date32 ()},
75+ };
76+
77+ for (const auto & test_case : cases) {
78+ SCOPED_TRACE (" Testing type: " + std::to_string (static_cast <int >(test_case.first )));
79+ auto result = type_singleton (test_case.first );
80+ ASSERT_OK_AND_ASSIGN (auto type, result);
81+ ASSERT_TRUE (type->Equals (*test_case.second ))
82+ << " Failed on type " << test_case.first << " . Expected "
83+ << test_case.second ->ToString () << " but got " << type->ToString ();
84+ }
85+ }
86+
87+ TEST (TestTypeSingleton, ParameterizedTypes) {
88+ // Test error cases - parameterized types
89+ std::vector<Type::type> parameterized_types = {
90+ Type::TIMESTAMP, Type::TIME32, Type::TIME64,
91+ Type::DURATION, Type::FIXED_SIZE_BINARY, Type::DECIMAL128,
92+ Type::LIST, Type::LARGE_LIST, Type::FIXED_SIZE_LIST,
93+ Type::STRUCT, Type::DICTIONARY, Type::MAP,
94+ Type::EXTENSION
95+ };
96+
97+ for (const auto type_id : parameterized_types) {
98+ SCOPED_TRACE (" Testing type: " + std::to_string (static_cast <int >(type_id)));
99+ auto result = type_singleton (type_id);
100+ ASSERT_FALSE (result.ok ());
101+ const auto & status = result.status ();
102+ EXPECT_THAT (status.message (), testing::HasSubstr (" is not a parameter-free singleton type" ));
103+ }
104+ }
105+
106+ TEST (TestTypeSingleton, InvalidType) {
107+ // Test with an invalid type ID
108+ auto result = type_singleton (static_cast <Type::type>(9999 ));
109+ ASSERT_FALSE (result.ok ());
110+ const auto & status = result.status ();
111+ EXPECT_THAT (status.message (), testing::HasSubstr (" requires parameters or is not supported" ));
112+ }
113+
52114template <typename ReprFunc>
53115void CheckTypeIdReprs (ReprFunc&& repr_func, bool expect_uppercase) {
54116 std::unordered_set<std::string> unique_reprs;
0 commit comments