Skip to content

Conformance Examples 0.1.0 — Render: comparison-operators

lt-numbers

Rule (2) numeric: 1 < 2.

Template

{{ a < b }}

Context

{
    "a": 1,
    "b": 2
}

Output

true

lt-equal-numbers

Rule (2) numeric: 2 < 2 is false (strict).

Template

{{ a < b }}

Context

{
    "a": 2,
    "b": 2
}

Output

false

le-equal-numbers

Rule (2) numeric: 2 <= 2 is true (inclusive).

Template

{{ a <= b }}

Context

{
    "a": 2,
    "b": 2
}

Output

true

gt-numbers

Rule (2) numeric: 3 > 2.

Template

{{ a > b }}

Context

{
    "a": 3,
    "b": 2
}

Output

true

ge-equal-numbers

Rule (2) numeric: 2 >= 2 is true.

Template

{{ a >= b }}

Context

{
    "a": 2,
    "b": 2
}

Output

true

lt-int-vs-double

Rule (2) numeric: mixed integer/decimal numeric comparison via Double.

Template

{{ a < b }}

Context

{
    "a": 1,
    "b": 1.5
}

Output

true

lt-strings

Rule (1) string side: lexicographic ordering.

Template

{{ a < b }}

Context

{
    "a": "apple",
    "b": "banana"
}

Output

true

gt-strings

Rule (1) string side: lexicographic ordering.

Template

{{ a > b }}

Context

{
    "a": "z",
    "b": "a"
}

Output

true

lt-string-vs-number

Rule (1) wins over rule (2): when one side is a string, both render to strings. '9'.compareTo('10') > 0, so '9' < 10 is false.

Template

{{ a < b }}

Context

{
    "a": "9",
    "b": 10
}

Output

false

gt-string-vs-number

Mirror of lt-string-vs-number: '9' > 10 is true under string compare.

Template

{{ a > b }}

Context

{
    "a": "9",
    "b": 10
}

Output

true

lt-bool-vs-bool

Rule (3) fallback: no string operand, not both numeric; result is false and a KB-5004 ComparisonMismatch soft failure is reported.

Template

{{ a < b }}

Context

{
    "a": true,
    "b": false
}

Output

false

gt-null-vs-number

Rule (3) fallback: null operand without a string side; result is false and a KB-5004 ComparisonMismatch soft failure is reported.

Template

{{ a > b }}

Context

{
    "a": null,
    "b": 5
}

Output

false

ge-null-vs-null

Rule (3) fallback: ordered comparisons do not coalesce equal nulls to true; result is false and a KB-5004 ComparisonMismatch soft failure is reported.

Template

{{ a >= b }}

Context

{
    "a": null,
    "b": null
}

Output

false

ge-string-vs-null

Rule (1) string side wins: 'x'.compareTo('null') > 0, so 'x' >= null is true.

Template

{{ a >= b }}

Context

{
    "a": "x",
    "b": null
}

Output

true

lt-block-each-else

An #each whose expression resolves to a boolean (not array/object) renders the else arm.

Template

{{#each a < b }}body{{else}}else{{/each}}

Context

{
    "a": 1,
    "b": 2
}

Output

else

gt-in-if-block

Comparison operator inside an #if expression slot.

Template

{{#if count > 0 }}HAS{{else}}NONE{{/if}}

Context

{
    "count": 3
}

Output

HAS

le-block-with

LE operator inside a #with block.

Template

{{#with item }}{{#if /price <= 100 }}AFFORDABLE{{else}}EXPENSIVE{{/if}}{{/with}}

Context

{
    "item": {
        "price": 50
    }
}

Output

AFFORDABLE

gt-block-each-iteration

GT operator inside an #each block, filtering items.

Template

{{#each items }}{{#if /quantity > 0 }}(yes){{else}}(no){{/if}}{{/each}}

Context

{
    "items": [
        {
            "quantity": 1
        },
        {
            "quantity": 0
        },
        {
            "quantity": 5
        }
    ]
}

Output

(yes)(no)(yes)

ge-with-numeric

GE operator in an interpolation with numeric literals.

Template

{{ 100 >= 50 }}

Context

{}

Output

true

le-string-literal

LE operator comparing string literals lexicographically.

Template

{{ "apple" <= "banana" }}

Context

{}

Output

true

gt-larger-number

GT operator with first operand larger.

Template

{{ a > b }}

Context

{
    "a": 10,
    "b": 5
}

Output

true

le-smaller-number

LE operator with first operand smaller.

Template

{{ a <= b }}

Context

{
    "a": 3,
    "b": 8
}

Output

true

ge-boolean-operand-false-result

GE with boolean operand returns false (fallback rule) and reports a KB-5004 ComparisonMismatch soft failure.

Template

{{ a >= false }}

Context

{
    "a": true
}

Output

false

le-with-string-right

LE with string on the right side for branch coverage.

Template

{{ 5 <= "10" }}

Context

{}

Output

false

ge-with-string-right

GE with string on the right side for branch coverage.

Template

{{ "50" >= 100 }}

Context

{}

Output

true

ge-numbers-less-than

GE with numeric operands where first is less than second.

Template

{{ 5 >= 10 }}

Context

{}

Output

false

le-explicit-numeric-comparison

LE with explicit numeric context variables.

Template

{{ a <= b }}

Context

{
    "a": 100,
    "b": 200
}

Output

true

lt-with-identifier-null-fallback

LT with an unresolved identifier reports KB-5005 UnresolvedReference for the miss, then the resulting null participates in the Rule (3) fallback comparison and reports KB-5004 ComparisonMismatch; result is false.

Template

{{ missing < 5 }}

Context

{}

Output

false

lt-numeric-vs-null

Rule (3) fallback when one side is numeric and the other is JsonNull: no string side, only one side is numeric; result is false and a KB-5004 ComparisonMismatch soft failure is reported.

Template

{{ a < b }}

Context

{
    "a": 5,
    "b": null
}

Output

false

Source fixture: render/comparison-operators.json