Skip to content

Conformance Examples 0.1.0 — Transforms: transform-contains

contains-string-substring-match

String input contains the substring argument.

Template

{{ phrase | contains: "world" }}

Context

{
    "phrase": "hello world"
}

Output

true

contains-string-substring-miss

String input does not contain the substring argument.

Template

{{ phrase | contains: "xyz" }}

Context

{
    "phrase": "hello world"
}

Output

false

contains-array-element-string-match

Array input contains the string argument as an element.

Template

{{ items | contains: "b" }}

Context

{
    "items": [
        "a",
        "b",
        "c"
    ]
}

Output

true

contains-array-element-asString-match

Array element 2 (numeric) asString-equals argument "2" so match is true.

Template

{{ items | contains: "2" }}

Context

{
    "items": [
        1,
        2,
        3
    ]
}

Output

true

contains-array-element-miss

Array input does not contain the argument.

Template

{{ items | contains: "z" }}

Context

{
    "items": [
        "a",
        "b",
        "c"
    ]
}

Output

false

contains-empty-array-is-false

An empty array never contains anything.

Template

{{ items | contains: "anything" }}

Context

{
    "items": []
}

Output

false

contains-null-input-coerced

Null input coerces to the literal string "null", which contains "ull".

Template

{{ missing | contains: "ull" }}

Context

{}

Output

true

contains-numeric-input-coerced

Numeric input coerces to its rendered string form, then substring check.

Template

{{ value | contains: "23" }}

Context

{
    "value": 12345
}

Output

true

contains-object-input-coerced

Object input coerces to its compact JSON form, then substring check matches.

Template

{{ user | contains: "alice" }}

Context

{
    "user": {
        "name": "alice"
    }
}

Output

true

contains-chained-after-upcase

Chaining contains after upcase: "HELLO" contains "ELL".

Template

{{ phrase | upcase | contains: "ELL" }}

Context

{
    "phrase": "hello"
}

Output

true

contains-chained-before-upcase

Chaining contains before upcase: "true" upcases to "TRUE".

Template

{{ phrase | contains: "ell" | upcase }}

Context

{
    "phrase": "hello"
}

Output

TRUE

Source fixture: transforms/transform-contains.json