Skip to content

Commit

Permalink
Add ArrayCustomOpenCloseDelimiter and `ChunkedArrayCustomOpenCloseD…
Browse files Browse the repository at this point in the history
…elimiter` tests.
  • Loading branch information
kevingurney committed Oct 10, 2023
1 parent 874d05d commit 2b7aece
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions cpp/src/arrow/pretty_print_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,25 @@ TEST_F(TestPrettyPrint, ArrayCustomElementDelimiter) {
}
}

TEST_F(TestPrettyPrint, ArrayCustomOpenCloseDelimiter) {
PrettyPrintOptions options{};
// Use a custom opening Array delimiter of "{", rather than the default "]".
options.array_delimiters.open = "{";
// Use a custom closing Array delimiter of "}", rather than the default "]".
options.array_delimiters.close = "}";

std::vector<bool> is_valid = {true, true, false, true, false};
std::vector<int32_t> values = {1, 2, 3, 4, 5};
static const char* expected = R"expected({
1,
2,
null,
4,
null
})expected";
CheckPrimitive<Int32Type, int32_t>(options, is_valid, values, expected, false);
}

TEST_F(TestPrettyPrint, Int8) {
static const char* expected = R"expected([
0,
Expand Down Expand Up @@ -1131,6 +1150,60 @@ TEST_F(TestPrettyPrint, ChunkedArrayCustomElementDelimiter) {
}
}

TEST_F(TestPrettyPrint, ChunkedArrayCustomOpenCloseDelimiter) {
PrettyPrintOptions options{};
// Use a custom opening Array delimiter of "{", rather than the default "]".
options.array_delimiters.open = "{";
// Use a custom closing Array delimiter of "}", rather than the default "]".
options.array_delimiters.close = "}";
// Use a custom opening ChunkedArray delimiter of "<", rather than the default "]".
options.chunked_array_delimiters.open = "<";
// Use a custom closing ChunkedArray delimiter of ">", rather than the default "]".
options.chunked_array_delimiters.close = ">";

const auto chunk = ArrayFromJSON(int32(), "[1, 2, null, 4, null]");

// ChunkedArray with 1 chunk
{
const ChunkedArray chunked_array(chunk);

static const char* expected = R"expected(<
{
1,
2,
null,
4,
null
}
>)expected";
CheckStream(chunked_array, options, expected);
}

// ChunkedArray with 2 chunks
{
const ChunkedArray chunked_array({chunk, chunk});

static const char* expected = R"expected(<
{
1,
2,
null,
4,
null
},
{
1,
2,
null,
4,
null
}
>)expected";

CheckStream(chunked_array, options, expected);
}
}

TEST_F(TestPrettyPrint, TablePrimitive) {
std::shared_ptr<Field> int_field = field("column", int32());
auto array = ArrayFromJSON(int_field->type(), "[0, 1, null, 3, null]");
Expand Down

0 comments on commit 2b7aece

Please sign in to comment.