22 lines
729 B
GDScript
22 lines
729 B
GDScript
extends SceneTree
|
|
|
|
const DonationAmount := preload("res://scripts/ui/donation_amount.gd")
|
|
|
|
var failures := 0
|
|
|
|
|
|
func _initialize() -> void:
|
|
_assert(DonationAmount.parse_cents("5") == 500, "whole dollars should parse")
|
|
_assert(DonationAmount.parse_cents("$25.50") == 2550, "dollars and cents should parse")
|
|
_assert(DonationAmount.parse_cents("4.999") == -1, "more than two decimal places should fail")
|
|
_assert(DonationAmount.parse_cents("10000.01") == -1, "amounts above the cap should fail")
|
|
_assert(DonationAmount.parse_cents("abc") == -1, "non-numeric values should fail")
|
|
quit(1 if failures > 0 else 0)
|
|
|
|
|
|
func _assert(condition: bool, message: String) -> void:
|
|
if condition:
|
|
return
|
|
failures += 1
|
|
push_error(message)
|