| 42 | // bool, null are trivial pass-throughs |
| 43 | |
| 44 | TEST(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 | |
| 75 | TEST(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 |
nothing calls this directly
no test coverage detected