Skip to main content

Test accepted and rejected cases

Create accepted and rejected cases for an order-ID pattern, then change the pattern to inspect a failing test.

Define the intended format​

This guide uses ORD- followed by four ASCII digits. Select JavaScript, remove all flags, and use:

^ORD-[0-9]{4}$

Add positive and negative cases​

  1. Open Unit Tests.
  2. Select Add unit test for each row.
  3. Set Assertion target to regex.
  4. Select the expected result in Assertion.
InputCriterionPurpose
ORD-0042does matchOrdinary accepted value
ORD-9999does matchFour digits
ORD-42does not matchToo few digits
ORD-00000does not matchToo many digits
XORD-0001does not matchExtra prefix
Empty inputdoes not matchMissing value
  1. Select Run tests.
  2. Verify that all expectations pass.

If the list hides some results, select Show all tests in Unit test actions.

Inspect a failing test​

  1. Change {4} to {2,4}.
  2. Run the same tests.
  3. Inspect the failure for ORD-42.
  4. Restore {4}.
  5. Run the tests again.

The negative case fails because the changed pattern accepts two-digit IDs. Restoring {4} restores the required format.

Include a line-ending boundary​

Without m, the JavaScript pattern rejects ORD-0042\n. Enabling m permits a match on the first line. Here, \n represents an actual newline, rather than two typed characters.

Keep m disabled for this identifier field. A full-match comparison can also guard against a later flag change. The classification guide provides an executable version of that additional check.

Choose tests or multiple strings​

Unit tests record expected outcomes and are included in Free. Multiple test strings show how one pattern behaves across separate editable inputs and require Pro.

On Free, you can inspect inputs one at a time or keep pass/fail expectations in unit tests. A saved workspace preserves the unit tests for later changes.