¶
luxe
API (2025.1.2
)¶
luxe: assert
module¶
Assert¶
import "luxe: assert" for Assert
Simple assertions.
An assertion is a statement in code that is a strict rule. They prevent code from behaving in unexpected ways, by asserting that the code is acting in the way you intended. This can catch a lot of bugs, because it can enforce correct usage of code.
For example, if your function does not allow null for an argument, that is something you can assert. Then the user of your code knows that they've used your API incorrectly and can correct the issue.
An assertion calls
Fiber.abort()
, ending execution (unless handled higher up).
- is_true(condition:
Bool
) - is_true(condition:
Bool
, message:String
) - is_false(condition:
Bool
) - is_false(condition:
Bool
, message:String
) - not_null(value:
Any
) - not_null(value:
Any
, message:String
) - is_null(value:
Any
) - is_null(value:
Any
, message:String
) - equal(one:
Any
, other:Any
) - equal(one:
Any
, other:Any
, message:String
)
Bool
)
¶None
Assert that a particular condition is true.
//In this code, we expect that the player //should never be here if they are not flying. Assert.is_true(player.flying)
Bool
, message: String
)
¶None
Assert that a particular condition is true, and display a message on abort.
//In this code, we expect that the player //should never be here if they are not flying. Assert.is_true(player.flying, "Expected player to be in a flying state")
Bool
)
¶None
Assert that a particular condition is false.
Assert.is_false(player.flying)
Bool
, message: String
)
¶None
Assert that a particular condition is false, and display a message on abort.
Assert.is_false(player.flying, "Expected player NOT to be in a flying state")
Any
)
¶None
Assert that a particular statement is not null.
//We require a valid player in this code Assert.not_null(player)
Any
, message: String
)
¶None
Assert that a particular statement is not null.
Assert.not_null(player, "A valid player is required")
Any
)
¶None
Assert that a particular statement is null.
//We assume the player is not holding something. Assert.is_null(player.item_in_hand)
Any
, message: String
)
¶None
Assert that a particular statement is null, and display a message on abort.
Assert.is_null(player.item_in_hand, "Player must not have an item in hand when calling this")
Any
, other: Any
)
¶None
Assert that a two values are the same. (mind that this uses a regular ==, which counts references with the same values as different and can be overridden)
Assert.equal(account.name, player.name)
Any
, other: Any
, message: String
)
¶None
Assert that a two values are the same, and display a message on abort. (mind that this uses a regular ==, which counts references with the same values as different and can be overridden)
Assert.equal(account.name, player.name, "account and player should always have the same name")