MCPcopy Create free account
hub / github.com/apache/arrow / TEST

Function TEST

cpp/src/arrow/json/converter_test.cc:44–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42// bool, null are trivial pass-throughs
43
44TEST(ConverterTest, Integers) {
45 for (auto int_type : {int8(), int16(), int32(), int64()}) {
46 ParseOptions options;
47 options.explicit_schema = schema({field("", int_type)});
48
49 std::string json_source = R"(
50 {"" : -0}
51 {"" : null}
52 {"" : -1}
53 {"" : 32}
54 {"" : -45}
55 {"" : 12}
56 {"" : -64}
57 {"" : 124}
58 )";
59
60 std::shared_ptr<StructArray> parse_array;
61 ASSERT_OK(ParseFromString(options, json_source, &parse_array));
62
63 // call to convert
64 ASSERT_OK_AND_ASSIGN(auto converted,
65 Convert(int_type, parse_array->GetFieldByName("")));
66
67 // assert equality
68 auto expected = ArrayFromJSON(int_type, R"([
69 -0, null, -1, 32, -45, 12, -64, 124])");
70
71 AssertArraysEqual(*expected, *converted);
72 }
73}
74
75TEST(ConverterTest, UnsignedIntegers) {
76 for (auto uint_type : {uint8(), uint16(), uint32(), uint64()}) {
77 ParseOptions options;
78 options.explicit_schema = schema({field("", uint_type)});
79
80 std::string json_source = R"(
81 {"" : 0}
82 {"" : null}
83 {"" : 1}
84 {"" : 32}
85 {"" : 45}
86 {"" : 12}
87 {"" : 64}
88 {"" : 124}
89 )";
90
91 std::shared_ptr<StructArray> parse_array;
92 ASSERT_OK(ParseFromString(options, json_source, &parse_array));
93
94 // call to convert
95 ASSERT_OK_AND_ASSIGN(auto converted,
96 Convert(uint_type, parse_array->GetFieldByName("")));
97
98 // assert equality
99 auto expected = ArrayFromJSON(uint_type, R"([
100 0, null, 1, 32, 45, 12, 64, 124])");
101

Callers

nothing calls this directly

Calls 12

ArrayFromJSONFunction · 0.85
AssertArraysEqualFunction · 0.85
decimal256Function · 0.85
ParseFromStringFunction · 0.70
ConvertFunction · 0.70
schemaFunction · 0.50
fieldFunction · 0.50
ASSERT_OK_AND_ASSIGNFunction · 0.50
timestampFunction · 0.50
decimal128Function · 0.50
GetFieldByNameMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected