Skip to content

Commit

Permalink
1. Add test for ListArray display
Browse files Browse the repository at this point in the history
2. Remove extra indentation applied to list and struct arrays
  • Loading branch information
sgilmore10 committed Oct 24, 2023
1 parent 1130aee commit 8ac0443
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 2 additions & 1 deletion matlab/src/cpp/arrow/matlab/array/proxy/array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ namespace arrow::matlab::array::proxy {
std::stringstream ss;
MATLAB_ERROR_IF_NOT_OK_WITH_CONTEXT(arrow::PrettyPrint(*array, opts, &ss), context, error::ARRAY_PRETTY_PRINT_FAILED);

const auto str_utf8 = ss.str();
const auto str_utf8 = opts.skip_new_lines ? " " + ss.str() : ss.str();

MATLAB_ASSIGN_OR_ERROR_WITH_CONTEXT(const auto str_utf16, arrow::util::UTF8StringToUTF16(str_utf8), context, error::UNICODE_CONVERSION_ERROR_ID);
auto str_mda = factory.createScalar(str_utf16);
context.outputs[0] = str_mda;
Expand Down
2 changes: 1 addition & 1 deletion matlab/src/matlab/+arrow/+array/Array.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
function displayScalarObject(obj)
disp(getHeader(obj));
if obj.NumElements > 0
disp(" " + toString(obj) + newline);
disp(toString(obj) + newline);
end
end
end
Expand Down
34 changes: 33 additions & 1 deletion matlab/test/arrow/array/tArrayDisplay.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function DisplayStructArray(testCase)
header = compose(" %s with %s elements and %s null values:" + newline, ...
classNameLink, numElementString, numNullString);

body = " -- is_valid: all not null" + newline + ...
body = " -- is_valid: all not null" + newline + ...
" -- child 0 type: double" + newline + ...
" [" + newline + ...
" 1," + newline + ...
Expand All @@ -289,6 +289,38 @@ function DisplayStructArray(testCase)
testCase.verifyEqual(actualDisplay, expectedDisplay);
end

function DisplayListArray(testCase)
import arrow.internal.test.display.makeLinkString

Offsets = arrow.array(int32([0, 2, 3]));
Values = arrow.array([1, 2, 3]);

listArray = arrow.array.ListArray.fromArrays(Offsets, Values); %#ok<NASGU>

classNameLink = makeLinkString(FullClassName="arrow.array.ListArray", ...
ClassName="ListArray", ...
BoldFont=true);

numElementString = getNumString(2);
numNullString = getNumString(0);
header = compose(" %s with %s elements and %s null values:" + newline, ...
classNameLink, numElementString, numNullString);

body = " [" + newline + ...
" [" + newline + ...
" 1," + newline + ...
" 2" + newline + ...
" ]," + newline + ...
" [" + newline + ...
" 3" + newline + ...
" ]" + newline + ...
" ]" + newline + newline;

expectedDisplay = char(strjoin([header body], newline));
actualDisplay = evalc('disp(listArray)');
testCase.verifyEqual(actualDisplay, expectedDisplay);
end

end

end
Expand Down

0 comments on commit 8ac0443

Please sign in to comment.