assert Module
The assert module provides fail-fast assertions for tests and runtime contracts. When an assertion fails, Harneet terminates with a runtime error and does not execute subsequent lines.
Functions
Assert(condition, message?)
Asserts that a condition is true. If the condition is false, the program will terminate with a runtime error (fail-fast).
Parameters: - condition: The condition to check. - message (optional): A message to display if the assertion fails.
Example:
| Assert Condition | |
|---|---|
AssertEq(actual, expected, message?)
Asserts that two values are equal. If they are not, the program terminates with a runtime error.
Parameters: - actual: The actual value. - expected: The expected value. - message (optional): A message to display if the assertion fails.
Example:
| Assert Equal | |
|---|---|
AssertNe(actual, expected, message?)
Asserts that two values are not equal. If they are, the program terminates with a runtime error.
Parameters: - actual: The actual value. - expected: The expected value. - message (optional): A message to display if the assertion fails.
Example:
| Assert Not Equal | |
|---|---|
AssertIsNotNone(value, message?)
Asserts that a value is not None. If it is None, the program terminates with a runtime error.
Parameters: - value: The value to check against None. - message (optional): A message to display if the assertion fails.
Example:
| Assert Not None | |
|---|---|
AssertLengthIsNotZero(value, message?)
Asserts that the length of a value is not zero. Supported types: string, array. Fails fast on zero length.
Parameters: - value: String or array to check. - message (optional): A message to display if the assertion fails.
Example:
| Assert Length Not Zero | |
|---|---|
AssertLengthIsGreaterThan(value, min, message?)
Asserts that length(value) > min. Supported types: string, array. Fails fast if not strictly greater.
Parameters: - value: String or array to check. - min (integer): Minimum length threshold (exclusive). - message (optional): A message to display if the assertion fails.
Example:
| Assert Length Greater | |
|---|---|
AssertLengthIsLessThan(value, max, message?)
Asserts that length(value) < max. Supported types: string, array. Fails fast if not strictly less.
Parameters: - value: String or array to check. - max (integer): Maximum length threshold (exclusive). - message (optional): A message to display if the assertion fails.
Example:
| Assert Length Less | |
|---|---|
AssertIsAnInt(value, message?)
Asserts that value is an INTEGER. Fails fast on wrong type.
Parameters: - value: Value to check. - message (optional): A message to display if the assertion fails.
Example:
| Assert Is Int | |
|---|---|
AssertIsAString(value, message?)
Asserts that value is a STRING. Fails fast on wrong type.
Parameters: - value: Value to check. - message (optional): A message to display if the assertion fails.
Example:
| Assert Is String | |
|---|---|
AssertIsBool(value, message?)
Asserts that value is a BOOLEAN. Fails fast on wrong type.
Parameters: - value: Value to check. - message (optional): A message to display if the assertion fails.
Example: