paleolimbot commented on code in PR #26:
URL: https://github.com/apache/arrow-nanoarrow/pull/26#discussion_r951532556


##########
src/nanoarrow/array_view_test.cc:
##########
@@ -354,3 +360,101 @@ TEST(ArrayTest, ArrayViewTestFixedSizeListArray) {
   schema.release(&schema);
   array.release(&array);
 }
+
+void TestGetFromNumericArrayView(const std::shared_ptr<DataType>& data_type) {
+  struct ArrowArray array;
+  struct ArrowSchema schema;
+  struct ArrowArrayView array_view;
+  struct ArrowError error;
+
+  // Array with nulls
+  auto arrow_array = ArrayFromJSON(data_type, "[1, null, null, 4]");
+  ARROW_EXPECT_OK(ExportArray(*arrow_array, &array, &schema));
+  ASSERT_EQ(ArrowArrayViewInitFromSchema(&array_view, &schema, &error), 
NANOARROW_OK);
+  ASSERT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), NANOARROW_OK);
+
+  EXPECT_EQ(ArrowArrayViewIsNull(&array_view, 2), 1);
+  EXPECT_EQ(ArrowArrayViewIsNull(&array_view, 3), 0);
+
+  EXPECT_EQ(ArrowArrayViewGetIntUnsafe(&array_view, 3), 4);
+  EXPECT_EQ(ArrowArrayViewGetUIntUnsafe(&array_view, 3), 4);
+  EXPECT_EQ(ArrowArrayViewGetDoubleUnsafe(&array_view, 3), 4.0);
+
+  auto string_view = ArrowArrayViewGetStringUnsafe(&array_view, 0);
+  EXPECT_EQ(string_view.data, nullptr);
+  EXPECT_EQ(string_view.n_bytes, 0);
+  auto buffer_view = ArrowArrayViewGetBytesUnsafe(&array_view, 0);
+  EXPECT_EQ(buffer_view.data.data, nullptr);
+  EXPECT_EQ(buffer_view.n_bytes, 0);
+
+  ArrowArrayViewReset(&array_view);
+  array.release(&array);
+  schema.release(&schema);
+
+  // Array without nulls (Arrow does not allocate the validity buffer)
+  arrow_array = ArrayFromJSON(data_type, "[1, 2]");
+  ARROW_EXPECT_OK(ExportArray(*arrow_array, &array, &schema));
+  ASSERT_EQ(ArrowArrayViewInitFromSchema(&array_view, &schema, &error), 
NANOARROW_OK);
+  ASSERT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), NANOARROW_OK);
+
+  // We're trying to test behavior with no validity buffer, so make sure 
that's true
+  ASSERT_EQ(array_view.buffer_views[0].data.data, nullptr);
+
+  EXPECT_EQ(ArrowArrayViewIsNull(&array_view, 0), 0);
+  EXPECT_EQ(ArrowArrayViewIsNull(&array_view, 1), 0);
+
+  EXPECT_EQ(ArrowArrayViewGetIntUnsafe(&array_view, 0), 1);
+  EXPECT_EQ(ArrowArrayViewGetUIntUnsafe(&array_view, 1), 2);
+
+  ArrowArrayViewReset(&array_view);
+  array.release(&array);
+  schema.release(&schema);
+}
+
+TEST(ArrayViewTest, ArrayViewTestGetNumeric) {

Review Comment:
   There are a few tests with some repetition here, some avoidable, some not. 
I'm a poor candidate to do refactoring because I don't know what tools are 
available to help. I'm also not worried about the maintainability of the tests, 
though...for the most part they're all pretty valid things that a user of the 
library might type.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to