Skip to content

Add shared expression engine tests (field paths, nesting, invalid paths) #118

@eerxuan

Description

@eerxuan

Summary

Add shared expression engine tests that cover parser/evaluator mechanics common to all operators. These should be tested once with a representative operator, not duplicated per-operator.

Per TEST_COVERAGE.md section 3, these are "Expression Engine Tests (under expressions/)" that test shared behavior.

Tests to Add

1. Field Path Resolution

File: expressions/test_field_path_resolution.py

  • Simple: $a on {a: 1}
  • Nested object: $a.b on {a: {b: 1}}
  • Deep nested: $a.b.c.d on {a: {b: {c: {d: 1}}}}
  • Array index: $a.0.b on {a: [{b: 1}, {b: 2}]}
  • Composite array traversal: $a.b on {a: [{b: 1}, {b: 2}]}
  • Nested arrays: $a.b on {a: [[{b: 1}], [{b: 2}]]}
  • Non-existent path: $missing → null
  • Non-existent nested: $x.y.0 on {}

2. Expression Nesting

File: expressions/test_expression_nesting.py

  • Expression in object: {a: {$abs: -1}}
  • Expression in array: [{$abs: -1}]
  • Nested expressions: {$add: [{$abs: "$x"}, {$abs: "$y"}]}
  • Deep nesting: {$add: [1, {$abs: {$ceil: {$sqrt: "$x"}}}]}
  • Complex mixed: {a: [{$add: [1, {$abs: "$x"}]}, {b: {$ceil: "$y"}}]}

3. Invalid Field Paths

File: expressions/test_invalid_field_paths.py

  • Empty path: $
  • Empty component: $a..b
  • Trailing dot: $a.
  • Null bytes in path
  • $$ prefix errors (undefined variables)
  • Dollar prefix in field name: $invalid

Tasks

  • Add test_field_path_resolution.py
  • Add test_expression_nesting.py
  • Add test_invalid_field_paths.py
  • Add smoke tests for field path resolution

Test Location

documentdb_tests/compatibility/tests/core/operator/expressions/

Notes

  • Use a representative operator (e.g., $add or $project) — these test the expression engine, not operator-specific logic
  • Per-operator tests should NOT duplicate these; they should only test operator-specific behavior (type acceptance, $missing handling, argument count, etc.)
  • Some per-operator tests currently include invalid field path tests — those can be migrated here over time

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions