@@ -81,7 +81,7 @@ TEST(LiteralTest, IntCastTo) {
8181 auto long_result = int_literal.CastTo (iceberg::int64 ());
8282 ASSERT_THAT (long_result, IsOk ());
8383 EXPECT_EQ (long_result->type ()->type_id (), TypeId::kLong );
84- EXPECT_EQ (long_result->ToString (), " 42 " );
84+ EXPECT_EQ (std::get< int64_t >( long_result->value ()), 42L );
8585
8686 // Cast to Float
8787 auto float_result = int_literal.CastTo (iceberg::float32 ());
@@ -136,8 +136,8 @@ TEST(LiteralTest, LongCastTo) {
136136 EXPECT_EQ (double_result->type ()->type_id (), TypeId::kDouble );
137137}
138138
139+ // Test overflow cases
139140TEST (LiteralTest, LongCastToIntOverflow) {
140- // Test overflow cases
141141 auto max_long =
142142 Literal::Long (static_cast <int64_t >(std::numeric_limits<int32_t >::max ()) + 1 );
143143 auto min_long =
@@ -383,42 +383,17 @@ TEST(LiteralTest, DoubleZeroComparison) {
383383 EXPECT_EQ (neg_zero <=> pos_zero, std::partial_ordering::less);
384384}
385385
386- // Type promotion tests
387- TEST (LiteralSerializationTest, TypePromotion) {
388- // 4-byte int data can be deserialized as long
389- std::vector<uint8_t > int_data = {32 , 0 , 0 , 0 };
390- auto long_result = Literal::Deserialize (int_data, int64 ());
391- ASSERT_TRUE (long_result.has_value ());
392- EXPECT_EQ (long_result->type ()->type_id (), TypeId::kLong );
393- EXPECT_EQ (long_result->ToString (), " 32" );
394-
395- auto long_bytes = long_result->Serialize ();
396- ASSERT_TRUE (long_bytes.has_value ());
397- EXPECT_EQ (long_bytes->size (), 8 );
398-
399- // 4-byte float data can be deserialized as double
400- std::vector<uint8_t > float_data = {0 , 0 , 128 , 63 };
401- auto double_result = Literal::Deserialize (float_data, float64 ());
402- ASSERT_TRUE (double_result.has_value ());
403- EXPECT_EQ (double_result->type ()->type_id (), TypeId::kDouble );
404- EXPECT_EQ (double_result->ToString (), " 1.000000" );
405-
406- auto double_bytes = double_result->Serialize ();
407- ASSERT_TRUE (double_bytes.has_value ());
408- EXPECT_EQ (double_bytes->size (), 8 );
409- }
410-
411386struct LiteralRoundTripParam {
412387 std::string test_name;
413388 std::vector<uint8_t > input_bytes;
414389 Literal expected_literal;
415390 std::shared_ptr<PrimitiveType> type;
416391};
417392
418- class LiteralSerializationParamTest
419- : public ::testing::TestWithParam<LiteralRoundTripParam> { };
393+ class LiteralSerializationParam : public ::testing::TestWithParam<LiteralRoundTripParam> {
394+ };
420395
421- TEST_P (LiteralSerializationParamTest , RoundTrip) {
396+ TEST_P (LiteralSerializationParam , RoundTrip) {
422397 const auto & param = GetParam ();
423398
424399 // Deserialize from bytes
@@ -427,8 +402,7 @@ TEST_P(LiteralSerializationParamTest, RoundTrip) {
427402 << " Deserialization failed: " << literal_result.error ().message ;
428403
429404 // Check type and value
430- EXPECT_EQ (literal_result->type ()->type_id (), param.expected_literal .type ()->type_id ());
431- EXPECT_EQ (literal_result->ToString (), param.expected_literal .ToString ());
405+ EXPECT_EQ (*literal_result, param.expected_literal );
432406
433407 // Serialize back to bytes
434408 Result<std::vector<uint8_t >> bytes_result = literal_result->Serialize ();
@@ -440,12 +414,11 @@ TEST_P(LiteralSerializationParamTest, RoundTrip) {
440414 Result<Literal> final_literal = Literal::Deserialize (*bytes_result, param.type );
441415 ASSERT_TRUE (final_literal.has_value ())
442416 << " Final deserialization failed: " << final_literal.error ().message ;
443- EXPECT_EQ (final_literal->type ()->type_id (), param.expected_literal .type ()->type_id ());
444- EXPECT_EQ (final_literal->ToString (), param.expected_literal .ToString ());
417+ EXPECT_EQ (*final_literal, param.expected_literal );
445418}
446419
447420INSTANTIATE_TEST_SUITE_P (
448- BinarySerializationTests, LiteralSerializationParamTest ,
421+ BinarySerialization, LiteralSerializationParam ,
449422 ::testing::Values (
450423 // Basic types
451424 LiteralRoundTripParam{" BooleanTrue" , {1 }, Literal::Boolean (true ), boolean ()},
@@ -483,11 +456,11 @@ INSTANTIATE_TEST_SUITE_P(
483456 // TODO(Li Feiyang): Add tests for Date, Time, Timestamp, TimestampTz
484457 ),
485458
486- [](const testing::TestParamInfo<LiteralSerializationParamTest ::ParamType>& info) {
459+ [](const testing::TestParamInfo<LiteralSerializationParam ::ParamType>& info) {
487460 return info.param .test_name ;
488461 });
489462
490- TEST (LiteralSerializationEdgeCaseTest, EmptyStringSerialization ) {
463+ TEST (LiteralSerializationTest, EmptyString ) {
491464 auto empty_string = Literal::String (" " );
492465 auto empty_bytes = empty_string.Serialize ();
493466 ASSERT_TRUE (empty_bytes.has_value ());
@@ -497,4 +470,29 @@ TEST(LiteralSerializationEdgeCaseTest, EmptyStringSerialization) {
497470 EXPECT_THAT (deserialize_result, IsError (ErrorKind::kInvalidArgument ));
498471}
499472
473+ // Type promotion tests
474+ TEST (LiteralSerializationTest, TypePromotion) {
475+ // 4-byte int data can be deserialized as long
476+ std::vector<uint8_t > int_data = {32 , 0 , 0 , 0 };
477+ auto long_result = Literal::Deserialize (int_data, int64 ());
478+ ASSERT_TRUE (long_result.has_value ());
479+ EXPECT_EQ (long_result->type ()->type_id (), TypeId::kLong );
480+ EXPECT_EQ (std::get<int64_t >(long_result->value ()), 32L );
481+
482+ auto long_bytes = long_result->Serialize ();
483+ ASSERT_TRUE (long_bytes.has_value ());
484+ EXPECT_EQ (long_bytes->size (), 8 );
485+
486+ // 4-byte float data can be deserialized as double
487+ std::vector<uint8_t > float_data = {0 , 0 , 128 , 63 };
488+ auto double_result = Literal::Deserialize (float_data, float64 ());
489+ ASSERT_TRUE (double_result.has_value ());
490+ EXPECT_EQ (double_result->type ()->type_id (), TypeId::kDouble );
491+ EXPECT_EQ (std::get<double >(double_result->value ()), 1.0 );
492+
493+ auto double_bytes = double_result->Serialize ();
494+ ASSERT_TRUE (double_bytes.has_value ());
495+ EXPECT_EQ (double_bytes->size (), 8 );
496+ }
497+
500498} // namespace iceberg
0 commit comments