---
cases:
  - note: "logic_op/comprehension: array, and as filter"
    experimental_keywords: true
    query: data.test.p = x
    modules:
      - |
        package test
        import future.keywords.and

        # One entry per x where both operands succeed.
        p := [x |
          x := input.xs[_]
          x > 0 and x < 10
        ]
    input:
      xs: [-1, 5, 12, 3]
    want_result:
      - x: [5, 3]
  - note: "logic_op/comprehension: array, or as filter"
    experimental_keywords: true
    query: data.test.p = x
    modules:
      - |
        package test
        import future.keywords.or

        p := [x |
          x := input.xs[_]
          x < 0 or x > 10
        ]
    input:
      xs: [-1, 5, 12, 3]
    want_result:
      - x: [-1, 12]
  - note: "logic_op/comprehension: set with and (dedup)"
    experimental_keywords: true
    query: data.test.p = x
    modules:
      - |
        package test
        import future.keywords.and

        # Set semantics dedupe even if multiple iterations match.
        p := {x |
          x := input.xs[_]
          x > 0 and x < 10
        }
    input:
      xs: [1, 1, 2, 2, 3, 3]
    sort_bindings: true
    want_result:
      - x: [1, 2, 3]
  - note: "logic_op/comprehension: object with or"
    experimental_keywords: true
    query: data.test.p = x
    modules:
      - |
        package test
        import future.keywords.or

        p := {k: v |
          v := input[k]
          v > 0 or v < -10
        }
    input:
      a: 5
      b: 0
      c: -20
      d: -1
    want_result:
      - x:
          a: 5
          c: -20
  - note: "logic_op/comprehension: nested comprehension with and"
    experimental_keywords: true
    query: data.test.p = x
    modules:
      - |
        package test
        import future.keywords.and

        p := [r |
          xs := input.matrix[_]
          r := [n |
            n := xs[_]
            n > 0 and n < 10
          ]
        ]
    input:
      matrix:
        - [1, -2, 5]
        - [12, 3, -4]
    want_result:
      - x: [[1, 5], [3]]
  - note: "logic_op/comprehension: walk-bound iteration with and as filter"
    experimental_keywords: true
    query: data.test.p = x
    modules:
      - |
        package test
        import future.keywords.and

        p := [v |
          walk(input, [_, v])
          is_string(v) and count(v) > 0
        ]
    input:
      a: "hello"
      b: ""
      c:
        d: "nested"
        e: 42
    sort_bindings: true
    want_result:
      - x: ["hello", "nested"]
  - note: "logic_op/comprehension: walk-bound iteration with or as filter"
    experimental_keywords: true
    query: data.test.p = x
    modules:
      - |
        package test
        import future.keywords.or

        p := [v |
          walk(input, [_, v])
          is_number(v) or { is_array(v); count(v) > 1 }
        ]
    input:
      a: 1
      b: "x"
      c: [10, 20, 30]
      d: [99]
    sort_bindings: true
    want_result:
      - x: [1, 10, 20, 30, 99, [10, 20, 30]]
