Class MatchOperator.CoreOperator

java.lang.Object
com.intuit.karate.MatchOperator.CoreOperator
All Implemented Interfaces:
MatchOperator
Enclosing interface:
MatchOperator

public static class MatchOperator.CoreOperator extends Object implements MatchOperator
  • Method Details

    • execute

      public boolean execute(MatchOperation operation)
      Specified by:
      execute in interface MatchOperator
    • macroOperator

      protected MatchOperator macroOperator(MatchOperator specifiedOperator)
      The operator specified by the user (^, ^+, ...) is provided as the specifiedOperator parameter. However, when using one of Contains Family operators, it may require some adjustments.

      Example:

      
       def actual = [{ a: 1, b: 'x' }, { a: 2, b: 'y' }]
       def part = { a: 1 }
       match actual contains '#(^part)'
       
      In this example, specifiedOperator is Contains. However:
      • The specified operator (^) is applied when processing the list.
      • Child operators are applied when processing objects within the list.
      According to childOperator(Match.Value), Contains' child operator is Equals. As a result, the code attempts to match { a: 1, b: 'x' } equals { a: 1 }, which fails.

      What we actually want is to preserve both Contains operators:

      • The one from the match instruction.
      • The one implied by the macro logic.
      This method achieves that by creating a custom operator that effectively applies two Contains operations.

      Note: If a third level of matching is required (e.g., the objects in actual contain other objects), it would fall back to the child operator of the child operator, which is Equals. This differs from the legacy implementation, which would enforce a deep Contains, potentially triggering issue #2515.

      That said, Contains Deep may still be specified explicitly by the user, for example, to handle nested structures like objects within objects within lists.

    • toString

      public String toString()
      Overrides:
      toString in class Object