25
25
#include < memory>
26
26
#include < sstream>
27
27
#include < string>
28
+ #include < string_view>
28
29
#include < vector>
29
30
30
31
#include " arrow/array.h"
@@ -47,37 +48,37 @@ class TestPrettyPrint : public ::testing::Test {
47
48
};
48
49
49
50
template <typename T>
50
- void CheckStream (const T& obj, const PrettyPrintOptions& options, const char * expected) {
51
+ void CheckStream (const T& obj, const PrettyPrintOptions& options,
52
+ std::string_view expected) {
51
53
std::ostringstream sink;
52
54
ASSERT_OK (PrettyPrint (obj, options, &sink));
53
55
std::string result = sink.str ();
54
- ASSERT_EQ (std::string ( expected, strlen (expected)) , result);
56
+ ASSERT_EQ (expected, result);
55
57
}
56
58
57
- void CheckArray (const Array& arr, const PrettyPrintOptions& options, const char * expected,
58
- bool check_operator = true ) {
59
+ void CheckArray (const Array& arr, const PrettyPrintOptions& options,
60
+ std::string_view expected, bool check_operator = true ) {
59
61
ARROW_SCOPED_TRACE (" For datatype: " , arr.type ()->ToString ());
60
62
CheckStream (arr, options, expected);
61
63
62
- if (options.indent == 0 && check_operator) {
64
+ if (options.indent == 0 && options. element_size_limit == 100 && check_operator) {
63
65
std::stringstream ss;
64
66
ss << arr;
65
- std::string result = std::string (expected, strlen (expected));
66
- ASSERT_EQ (result, ss.str ());
67
+ ASSERT_EQ (expected, ss.str ());
67
68
}
68
69
}
69
70
70
71
template <typename T>
71
- void Check (const T& obj, const PrettyPrintOptions& options, const char * expected) {
72
+ void Check (const T& obj, const PrettyPrintOptions& options, std::string_view expected) {
72
73
std::string result;
73
74
ASSERT_OK (PrettyPrint (obj, options, &result));
74
- ASSERT_EQ (std::string ( expected, strlen (expected)) , result);
75
+ ASSERT_EQ (expected, result);
75
76
}
76
77
77
78
template <typename TYPE, typename C_TYPE>
78
79
void CheckPrimitive (const std::shared_ptr<DataType>& type,
79
80
const PrettyPrintOptions& options, const std::vector<bool >& is_valid,
80
- const std::vector<C_TYPE>& values, const char * expected,
81
+ const std::vector<C_TYPE>& values, std::string_view expected,
81
82
bool check_operator = true ) {
82
83
std::shared_ptr<Array> array;
83
84
ArrayFromVector<TYPE, C_TYPE>(type, is_valid, values, &array);
@@ -86,7 +87,7 @@ void CheckPrimitive(const std::shared_ptr<DataType>& type,
86
87
87
88
template <typename TYPE, typename C_TYPE>
88
89
void CheckPrimitive (const PrettyPrintOptions& options, const std::vector<bool >& is_valid,
89
- const std::vector<C_TYPE>& values, const char * expected,
90
+ const std::vector<C_TYPE>& values, std::string_view expected,
90
91
bool check_operator = true ) {
91
92
CheckPrimitive<TYPE, C_TYPE>(TypeTraits<TYPE>::type_singleton (), options, is_valid,
92
93
values, expected, check_operator);
@@ -158,12 +159,12 @@ TEST_F(TestPrettyPrint, PrimitiveType) {
158
159
])expected" ;
159
160
CheckPrimitive<DoubleType, double >({2 , 10 }, is_valid, values2, ex2_in2);
160
161
161
- std::vector<std::string> values3 = {" foo" , " bar" , " " , " baz " , " " };
162
+ std::vector<std::string> values3 = {" foo" , " bar" , " " , " a longer string " , " " };
162
163
static const char * ex3 = R"expected( [
163
164
"foo",
164
165
"bar",
165
166
null,
166
- "baz ",
167
+ "a longer string ",
167
168
null
168
169
])expected" ;
169
170
CheckPrimitive<StringType, std::string>({0 , 10 }, is_valid, values3, ex3);
@@ -172,19 +173,19 @@ TEST_F(TestPrettyPrint, PrimitiveType) {
172
173
"foo",
173
174
"bar",
174
175
null,
175
- "baz ",
176
+ "a longer string ",
176
177
null
177
178
])expected" ;
178
179
CheckPrimitive<StringType, std::string>({2 , 10 }, is_valid, values3, ex3_in2);
179
180
CheckPrimitive<LargeStringType, std::string>({2 , 10 }, is_valid, values3, ex3_in2);
180
181
181
182
PrettyPrintOptions options{2 , 10 };
182
- options.element_size_limit = 2 ;
183
+ options.element_size_limit = 8 ;
183
184
static const char * ex3_in3 = R"expected( [
184
- " (... 3 chars omitted) ",
185
- " (... 3 chars omitted) ",
185
+ "foo ",
186
+ "bar ",
186
187
null,
187
- " (... 3 chars omitted)",
188
+ "a long (... 9 chars omitted)",
188
189
null
189
190
])expected" ;
190
191
CheckPrimitive<StringType, std::string>(options, is_valid, values3, ex3_in3);
@@ -1139,6 +1140,12 @@ TEST_F(TestPrettyPrint, DecimalTypes) {
1139
1140
1140
1141
static const char * ex = " [\n 123.4567,\n 456.7891,\n null\n ]" ;
1141
1142
CheckArray (*array, {0 }, ex);
1143
+
1144
+ auto options = PrettyPrintOptions ();
1145
+ options.element_size_limit = 3 ;
1146
+ static const char * ex_2 =
1147
+ " [\n 123 (... 5 chars omitted),\n 456 (... 5 chars omitted),\n null\n ]" ;
1148
+ CheckArray (*array, options, ex_2);
1142
1149
}
1143
1150
}
1144
1151
0 commit comments