Skip to content

Conversation

aryasoni98
Copy link
Contributor

This PR resolves issue #1078 by adding comprehensive test coverage for the json_schema.rs file, specifically testing the public API build_json_schema() function.

Added Dependencies

  • Added expect-test = "1.5.0" to Cargo.toml for snapshot-based testing

Test Implementation

  • 31 comprehensive test cases covering all requirements:
    • 16 Basic type tests: All BasicValueType variants including Str, Bool, Int64, Float32, Float64, Bytes, Range, Uuid, Date, Time, LocalDateTime, OffsetDateTime, TimeDelta, Json, Vector, Union, and nullable types
    • 8 struct-type tests: Simple structs, optional fields, descriptions, nested structs, always-required options, and description extraction functionality
    • 3 Table type tests: All TableKind variants (UTable, KTable, LTable)
    • 4 Additional feature tests: Value extractor functionality, wrapper field extraction, format support options, and top-level object requirements

Key Features

  • Snapshot testing using expect-test crate as suggested in the issue
  • Complete API coverage of build_json_schema() function
  • All configuration options in ToJsonSchemaOptions tested
  • Edge cases and error conditions covered
  • Maintainable test structure with helper functions and clear naming

🧪 Test Results

running 31 tests
test result: ok. 31 passed; 0 failed; 0 ignored; 0 measured; 131 filtered out

📋 Issue Requirements Met

  • Add tests in json_schema.rs
  • Test on the public API build_json_schema()
  • Cover basic types (for types handled here)
  • Cover struct types
  • Cover table types
  • Use expect_test crate on output serialized to JSON (as suggested)

🔍 Testing Approach

The implementation uses the expect-test crate for snapshot testing, which:

  • Automatically captures the actual JSON schema output
  • Compares against expected values using expect! macro
  • Makes tests easier to write and maintain
  • Provides clear diff output when tests fail
  • Can be updated easily with UPDATE_EXPECT=1 environment variable

Closes #1078

This PR provides the comprehensive test coverage requested in the issue, ensuring the json_schema.rs functionality is thoroughly tested and maintainable going forward.

Resolved conflict in src/base/json_schema.rs by keeping both:
- Our comprehensive test suite (31 tests)
- The new test_description_concatenation test from main

All 32 tests now pass successfully.
Copy link
Member

@georgeh0 georgeh0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@georgeh0 georgeh0 merged commit 43c988f into cocoindex-io:main Oct 4, 2025
8 checks passed
@aryasoni98 aryasoni98 deleted the issue-1078 branch October 5, 2025 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add tests for json_schema.rs
3 participants