Strict module

The Strict module of the Assert package supplies assertions that compare values as if the comparison had been written directly in twinBASIC code, with two exceptions: string comparisons are case-sensitive (regardless of the project’s Option Compare setting), and object default members are not evaluated. Strict matches the language’s normal equality semantics for numbers and primitives, plus guarantees a case-sensitive string compare and reference-style equality on objects.

Comparison semantics

The four equality assertions in this module — AreEqual, AreNotEqual, SequenceEquals, and NotSequenceEquals — apply the rules listed below. The remaining assertions are unaffected.

  • String comparisons are case-sensitive (regardless of the project’s Option Compare setting).
  • Object references are compared by identity (the Is operator); default-member values are not retrieved.
  • All other comparisons are evaluated as if the operands had been written either side of = in twinBASIC code — numeric promotions apply (5 equals 5.0), vbNullString and "" are both empty strings, and so on.
  • Null is never equal to anything, not even to itself — use IsNull / IsNotNull to test for it.
' Pass under Strict (would fail under Exact):
Strict.AreEqual 5, 5.0           ' twinBASIC promotes 5 to 5.0 before comparing
Strict.AreEqual vbNullString, "" ' both empty strings under twinBASIC equality

' Still fails — Strict comparisons are case-sensitive:
Strict.AreEqual "Hello", "hello"

Diagnostic outcome

Succeed

Records that the test reached this point without failure.

Syntax: Strict.Succeed

A test procedure that returns without any assertion having failed is reported as passing implicitly, so calling Succeed explicitly is rarely necessary. It is occasionally useful in branches that would otherwise look ambiguous about their outcome — for example, the body of a loop that should reach the end.

Fail

Unconditionally records a test failure.

Syntax: Strict.Fail [ Message ]

Message
optional A String describing the failure, recorded together with the source location of the call.

Fail marks code paths that should be unreachable in a passing test — most often after a call that is expected to raise an error, in a branch that runs when the call returned normally instead.

On Error Resume Next
target.SomethingThatShouldRaise
If Err.Number = 0 Then Strict.Fail "expected an error, got success"

Inconclusive

Records the test as inconclusive — neither a pass nor a failure.

Syntax: Strict.Inconclusive [ Message ]

Message
optional A String describing why the result is inconclusive.

Inconclusive records that a precondition for the test could not be established and the assertion logic that follows would be meaningless. A common case is a setup step that failed to find a required external resource — a test database, a configured network endpoint — where the test itself is neither passing nor failing on its own merits.

Equality

AreEqual

Asserts that Actual is equal to Expected.

Syntax: Strict.AreEqual Expected, Actual [, Message ]

Expected
required A Variant holding the expected value.
Actual
required A Variant holding the value produced by the code under test.
Message
optional A String included in the failure record if the comparison fails.

The comparison follows this module’s comparison semantics — strings are compared case-sensitively, object references are compared by identity, and everything else uses normal twinBASIC equality (so numeric promotions apply and vbNullString matches ""). If either operand is Null, the assertion fails — Null is never equal to anything; use IsNull to test for Null explicitly.

AreNotEqual

Asserts that Actual is not equal to Expected.

Syntax: Strict.AreNotEqual Expected, Actual [, Message ]

Expected
required A Variant holding a value that Actual must differ from.
Actual
required A Variant holding the value produced by the code under test.
Message
optional A String included in the failure record if the values are equal.

The comparison follows this module’s comparison semantics — strings are compared case-sensitively, object references are compared by identity, and everything else uses normal twinBASIC equality. If either operand is Null, the assertion passes — Null is never equal to anything, including another Null.

Strict.AreNotEqual "Hello", "hello"  ' passes — strings are compared case-sensitively
Strict.AreNotEqual 1, 2              ' passes — different numeric values

' Under Strict, numeric promotions apply, so these would fail (the values are equal):
' Strict.AreNotEqual 5, 5.0           ' fails — 5 and 5.0 are equal under twinBASIC equality
' Strict.AreNotEqual "", vbNullString  ' fails — both are the empty string

AreSame

Asserts that Actual and Expected refer to the same object — equivalent to Expected Is Actual.

Syntax: Strict.AreSame Expected, Actual [, Message ]

Expected
required A Variant holding the expected object reference.
Actual
required A Variant holding the reference produced by the code under test.
Message
optional A String included in the failure record if the references differ.

Reference identity is independent of the module’s other comparison rules — AreSame always uses the Is operator, never default-member equality. To compare values rather than references, use AreEqual.

AreNotSame

Asserts that Actual and Expected refer to different objects — equivalent to Expected IsNot Actual.

Syntax: Strict.AreNotSame Expected, Actual [, Message ]

Expected
required A Variant holding a reference that Actual must differ from.
Actual
required A Variant holding the reference produced by the code under test.
Message
optional A String included in the failure record if the references are the same.

Reference identity is independent of the module’s other comparison rules — AreNotSame always uses the IsNot operator, never default-member equality. To compare values rather than references, use AreNotEqual.

Dim a As New Collection
Dim b As New Collection
Strict.AreNotSame a, b   ' passes — a and b are distinct object instances
Strict.AreNotSame a, a   ' fails — same reference

Boolean

IsTrue

Asserts that Condition evaluates to True.

Syntax: Strict.IsTrue Condition [, Message ]

Condition
required A Variant holding the condition to test. The value is interpreted as a Boolean — zero is False, any non-zero value is True.
Message
optional A String included in the failure record if the condition is False.

If Condition is Null, the assertion fails.

IsFalse

Asserts that Condition evaluates to False.

Syntax: Strict.IsFalse Condition [, Message ]

Condition
required A Variant holding the condition to test. Zero is False, any non-zero value is True.
Message
optional A String included in the failure record if the condition is True.

If Condition is Null, the assertion fails — Null is neither True nor False.

Reference and value state

IsNothing

Asserts that Value is the Nothing object reference.

Syntax: Strict.IsNothing Value [, Message ]

Value
required A Variant holding the object reference to test.
Message
optional A String included in the failure record if Value refers to an object.

This is the object-reference test, equivalent to Value Is Nothing. To check for the Null value of a Variant instead, use IsNull.

IsNotNothing

Asserts that Value refers to an object — i.e. is not the Nothing reference.

Syntax: Strict.IsNotNothing Value [, Message ]

Value
required A Variant holding the object reference to test.
Message
optional A String included in the failure record if Value is Nothing.

This is the complement of IsNothing, equivalent to Value IsNot Nothing. Use this assertion to confirm that a factory call, a lookup, or any other expression that is expected to return an object did not return Nothing.

Dim result As Widget
Set result = factory.CreateWidget("blue")
Strict.IsNotNothing result   ' fails if CreateWidget returned Nothing

To check for the Null value of a Variant rather than an unset object reference, use IsNotNull.

IsNull

Asserts that Value is the Null value of a Variant.

Syntax: Strict.IsNull Value [, Message ]

Value
required A Variant holding the value to test.
Message
optional A String included in the failure record if Value is not Null.

Equivalent to checking IsNull(Value) = True. To check for the Nothing object reference instead, use IsNothing.

IsNotNull

Asserts that Value is not the Null value of a Variant.

Syntax: Strict.IsNotNull Value [, Message ]

Value
required A Variant holding the value to test.
Message
optional A String included in the failure record if Value is Null.

IsNotNull is the inverse of IsNull: it passes when IsNull(Value) would return False, and fails when IsNull(Value) would return True. Because Null is never considered equal to anything — including itself — AreNotEqual(Null, value) is not a reliable way to assert the absence of Null; IsNotNull is the correct assertion for that purpose. To check for the Nothing object reference instead, use IsNotNothing.

Sub TestQueryResult()
    Dim result As Variant
    result = db.ReadField("Name")

    ' Assert the field was present and not null before inspecting its value.
    Strict.IsNotNull result, "expected a non-null Name field"
    Strict.AreEqual "Alice", result
End Sub

Sequence

SequenceEquals

Asserts that Actual and Expected contain the same number of elements, in the same order, with each pair of elements equal under this module’s comparison semantics.

Syntax: Strict.SequenceEquals Expected, Actual [, FailMessage ]

Expected
required A Variant holding an array, Collection, or other enumerable value.
Actual
required A Variant holding the sequence produced by the code under test.
FailMessage
optional A String included in the failure record if the sequences differ.

Both arguments must support iteration via For Each. The assertion fails on the first mismatched pair, on a length difference, or if one side is empty while the other is not. Element comparison uses the same per-pair rules as AreEqual, so string elements are compared case-sensitively while numbers compare under normal twinBASIC equality.

NotSequenceEquals

Asserts that Actual and Expected differ — they contain a different number of elements, or at least one pair of corresponding elements differs under this module’s comparison semantics.

Syntax: Strict.NotSequenceEquals Expected, Actual [, FailMessage ]

Expected
required A Variant holding an array, Collection, or other enumerable value.
Actual
required A Variant holding the sequence produced by the code under test.
FailMessage
optional A String included in the failure record if the sequences are equal.

Both arguments must support iteration via For Each. The assertion passes when the two sequences have a different element count, or when any corresponding element pair differs under this module’s comparison rules — strings are compared case-sensitively, numeric values are compared with normal twinBASIC equality (so 5 equals 5.0), and object references are compared by identity. NotSequenceEquals is the inverse of SequenceEquals: if SequenceEquals would pass, NotSequenceEquals fails, and vice versa.

Dim expected(0 To 1) As String
expected(0) = "alpha"
expected(1) = "beta"

Dim actual(0 To 1) As String
actual(0) = "alpha"
actual(1) = "Beta"   ' differs in case

Strict.NotSequenceEquals expected, actual   ' passes — "beta" <> "Beta" under case-sensitive comparison

See Also

  • Exact – the strictest comparison flavour: datatypes must match and conversions never happen
  • Permissive – like Strict, but with case-insensitive string comparisons and default-member object equality
  • Assert package – overview of all three modules and the comparison-semantics table