Record Class TestDirective

java.lang.Object
java.lang.Record
org.ek9lang.compiler.directives.TestDirective
Record Components:
token - Source location of the directive
requirement - Optional requirement id this test anchors (null = unanchored)
group - Optional group name for sequential execution (null = parallel)
lineNumber - The line number the directive applies to (the program declaration line)
All Implemented Interfaces:
Directive

public record TestDirective(IToken token, String requirement, String group, int lineNumber) extends Record implements Directive
Test directive for marking programs as tests, and optionally anchoring one to a requirement.
  @Test                                    - parallel, unanchored
  @Test: "database"                        - execution group, unanchored
  @Test: "REQ:fraud-screening"             - anchored, parallel
  @Test: "REQ:fraud-screening": "database" - anchored and grouped

The two parts are told apart by their content, not their position

A requirement id has the shape <PREFIX>:<slug> and so contains a colon; an execution group may not contain one. That makes the classification total and order-independent, and it is what closes an otherwise silent failure: a mistyped prefix such as "RREQ:foo" would otherwise be a perfectly legal group name, dropping the requirement anchor with no diagnostic anywhere. Any colon-bearing part is therefore treated as an anchor attempt, and a malformed one is a compile error rather than a quiet degradation to a group.

Zero of the 622 @Test usages in the corpus contain a colon, so this rule was enforceable from the day it landed with no migration.

The two fields also travel across phases on separate squirrelled keys. The group rides TEST_DIRECTIVE, which TestRunner reads as the sequential execution group; packing a requirement id into it would silently reschedule every anchored test into a group named after its requirement.

  • Constructor Details

    • TestDirective

      public TestDirective(IToken token, String requirement, String group, int lineNumber)
      Creates an instance of a TestDirective record class.
      Parameters:
      token - the value for the token record component
      requirement - the value for the requirement record component
      group - the value for the group record component
      lineNumber - the value for the lineNumber record component
  • Method Details

    • type

      public DirectiveType type()
      Description copied from interface: Directive
      What s the type of the directive.
      Specified by:
      type in interface Directive
    • isForPhase

      public boolean isForPhase(CompilationPhase phase)
      Description copied from interface: Directive
      Is it for the particular compiler phase.
      Specified by:
      isForPhase in interface Directive
    • getAppliesToLineNumber

      public int getAppliesToLineNumber()
      Description copied from interface: Directive
      Which line number does this directive apply to.
      Specified by:
      getAppliesToLineNumber in interface Directive
    • getDirectiveToken

      public IToken getDirectiveToken()
      Description copied from interface: Directive
      Provide a token from the source, by default if not possible supply synthetic.
      Specified by:
      getDirectiveToken in interface Directive
    • hasGroup

      public boolean hasGroup()
      Check if this test has a group for sequential execution.
    • hasRequirement

      public boolean hasRequirement()
      Check if this test anchors a requirement.

      An unanchored test is entirely legitimate and carries no requirement by design - a unit test over a shared primitive is not "about" any one requirement.

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • token

      public IToken token()
      Returns the value of the token record component.
      Returns:
      the value of the token record component
    • requirement

      public String requirement()
      Returns the value of the requirement record component.
      Returns:
      the value of the requirement record component
    • group

      public String group()
      Returns the value of the group record component.
      Returns:
      the value of the group record component
    • lineNumber

      public int lineNumber()
      Returns the value of the lineNumber record component.
      Returns:
      the value of the lineNumber record component