LCOV - code coverage report
Current view: top level - backend/engine/semantic/functions - array_funcs_test.cc (source / functions) Coverage Total Hit
Test: _coverage_report.dat Lines: 100.0 % 38 38
Test Date: 2026-07-02 21:01:18 Functions: 100.0 % 5 5

            Line data    Source code
       1              : #include "backend/engine/semantic/functions/array_funcs.h"
       2              : 
       3              : #include <vector>
       4              : 
       5              : #include "backend/engine/semantic/value.h"
       6              : #include "googlesql/public/type.h"
       7              : #include "googlesql/public/types/array_type.h"
       8              : #include "googlesql/public/value.h"
       9              : #include "gtest/gtest.h"
      10              : 
      11              : namespace bigquery_emulator {
      12              : namespace backend {
      13              : namespace engine {
      14              : namespace semantic {
      15              : namespace functions {
      16              : namespace {
      17              : 
      18              : using ::googlesql::Value;
      19              : 
      20            4 : const ::googlesql::ArrayType* Int64ArrayType() {
      21            4 :   return ::googlesql::types::Int64ArrayType();
      22            4 : }
      23              : 
      24              : }  // namespace
      25              : 
      26            1 : TEST(ArrayFuncsTest, GenerateArrayBasic) {
      27            1 :   const ::googlesql::Type* ret = Int64ArrayType();
      28            1 :   auto got = GenerateArray({Value::Int64(1), Value::Int64(5)}, ret);
      29            1 :   ASSERT_TRUE(got.ok());
      30            1 :   ASSERT_EQ(got->num_elements(), 5);
      31            1 :   EXPECT_EQ(got->element(0).int64_value(), 1);
      32            1 :   EXPECT_EQ(got->element(4).int64_value(), 5);
      33            1 : }
      34              : 
      35            1 : TEST(ArrayFuncsTest, GenerateArrayDoubleElements) {
      36            1 :   const ::googlesql::Type* ret = ::googlesql::types::DoubleArrayType();
      37            1 :   auto got = GenerateArray({Value::Int64(1), Value::Int64(3)}, ret);
      38            2 :   ASSERT_TRUE(got.ok()) << got.status();
      39            1 :   ASSERT_EQ(got->num_elements(), 3);
      40            1 :   EXPECT_DOUBLE_EQ(got->element(0).double_value(), 1.0);
      41            1 :   EXPECT_DOUBLE_EQ(got->element(2).double_value(), 3.0);
      42            1 : }
      43              : 
      44            1 : TEST(ArrayFuncsTest, ArrayConcatMerges) {
      45            1 :   const ::googlesql::Type* ret = Int64ArrayType();
      46            1 :   Value a = Value::Array(ret->AsArray(), {Value::Int64(1), Value::Int64(2)});
      47            1 :   Value b = Value::Array(ret->AsArray(), {Value::Int64(3)});
      48            1 :   auto got = ArrayConcat({a, b}, ret);
      49            1 :   ASSERT_TRUE(got.ok());
      50            1 :   ASSERT_EQ(got->num_elements(), 3);
      51            1 :   EXPECT_EQ(got->element(2).int64_value(), 3);
      52            1 : }
      53              : 
      54            1 : TEST(ArrayFuncsTest, ArrayLengthAndReverse) {
      55            1 :   Value a = Value::Array(Int64ArrayType(),
      56            1 :                          {Value::Int64(1), Value::Int64(2), Value::Int64(3)});
      57            1 :   auto len = ArrayLength({a});
      58            1 :   ASSERT_TRUE(len.ok());
      59            1 :   EXPECT_EQ(len->int64_value(), 3);
      60            1 :   auto rev = ArrayReverse({a}, Int64ArrayType());
      61            1 :   ASSERT_TRUE(rev.ok());
      62            1 :   EXPECT_EQ(rev->element(0).int64_value(), 3);
      63            1 : }
      64              : 
      65              : }  // namespace functions
      66              : }  // namespace semantic
      67              : }  // namespace engine
      68              : }  // namespace backend
      69              : }  // namespace bigquery_emulator
        

Generated by: LCOV version 2.0-1