PC02-L01 · guided challenge

Usable email address

Check presence, null, and an empty string in the correct order.

Practical CEL4 test casesDocumented
What will I practise?

You can read an optional member safely and distinguish presence from usable content.

How is it checked?

Your one expression must produce the expected result for all four JSON inputs.

When am I done?

When all tests pass and you can explain every condition in your expression.

Word problem

A customer email is usable only when the member exists, is not null, and is not an empty string.

Exact requirements

  1. A missing member returns false without an access error.
  2. A present null returns false.
  3. A present empty string returns false.
  4. Any other string passes this rule.

Required result

Write one CEL expression. It must return the expected value and type for all four prepared JSON inputs. Do not change the inputs to make an incomplete expression pass.

Recommended procedure

  1. Translate each numbered requirement into one small boolean condition.
  2. Run the starter expression and inspect which cases fail.
  3. Add one condition at a time and run the complete suite again.
  4. Mark the challenge complete only when you can explain every operator and every boundary.

Solve the challenge · browser test suite

Write one expression that passes every case

Edit the CEL expression, then run it against all prepared JSON inputs. A solution is complete only when every case passes.

4 test cases

Hint: Check presence first. Because of &&, later parts run only when the member exists.

Tip: press Ctrl/⌘ + Enter to run all tests.
Filled emailNot run yet
Expected: true · bool
Show JSON input
{
  "customer": {
    "email": "maya@example.test"
  }
}
Missing memberNot run yet
Expected: false · bool
Show JSON input
{
  "customer": {}
}
Null valueNot run yet
Expected: false · bool
Show JSON input
{
  "customer": {
    "email": null
  }
}
Empty stringNot run yet
Expected: false · bool
Show JSON input
{
  "customer": {
    "email": ""
  }
}
Test result

Not run yet

The same expression runs against every case. Test data is fixed so that boundary and failure scenarios cannot be skipped.

Explained solution

Show the complete expression
has(customer.email) && customer.email != null && customer.email != ''

Why the solution works

  1. has(customer.email) asks about presence without reading the value.
  2. Short-circuit && protects the later member access.
  3. The null check runs before the string-content check.
  4. The final comparison rejects only the empty string.

What the test cases prove

  • Filled email: expected true (bool).
  • Missing member: expected false (bool).
  • Null value: expected false (bool).
  • Empty string: expected false (bool).

The cases are intentionally different. A solution that passes only the first case has not yet implemented the complete rule.

Common mistake

Do not optimise the expression for the first successful input. A requirement is implemented only when its positive case, negative case, and boundary case all produce the stated result.

Knowledge check

Can you point to the exact part of the solution that makes each false test case fail? If two different failures depend on the same condition, explain why.

Key takeaway

You can read an optional member safely and distinguish presence from usable content.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition for operators, types, macros, presence, strings, and time values used in this challenge.