summaryrefslogtreecommitdiff
path: root/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd
diff options
context:
space:
mode:
authorradiohotline <radoihotline@disroot.rg>2026-08-25 16:33:56 +0300
committerradiohotline <radoihotline@disroot.rg>2026-08-25 16:33:56 +0300
commita89e744ed0e8c759caf041a580112365bbfe4303 (patch)
treedd61e320904176995727e86a857d00c90d4933ba /addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd
parent6d53d8cac78250dc888aa49d5f9d4175c6652feb (diff)
escoria updateHEADmain
Diffstat (limited to 'addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd')
-rw-r--r--addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd80
1 files changed, 80 insertions, 0 deletions
diff --git a/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd
new file mode 100644
index 0000000..9f578c4
--- /dev/null
+++ b/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd
@@ -0,0 +1,80 @@
+class_name GdUnitAssertImpl
+extends GdUnitAssert
+
+
+var _current :Variant
+var _current_failure_message :String = ""
+var _custom_failure_message :String = ""
+var _additional_failure_message: String = ""
+
+
+func _init(current :Variant) -> void:
+ _current = current
+ # save the actual assert instance on the current thread context
+ GdUnitThreadManager.get_current_context().set_assert(self)
+ GdAssertReports.reset_last_error_line_number()
+
+
+
+func failure_message() -> String:
+ return _current_failure_message
+
+
+func current_value() -> Variant:
+ return _current
+
+
+func report_success() -> GdUnitAssert:
+ GdAssertReports.report_success()
+ return self
+
+
+func report_error(failure :String, failure_line_number: int = -1) -> GdUnitAssert:
+ var line_number := failure_line_number if failure_line_number != -1 else GdUnitAssertions.get_line_number()
+ GdAssertReports.set_last_error_line_number(line_number)
+ _current_failure_message = GdAssertMessages.build_failure_message(failure, _additional_failure_message, _custom_failure_message)
+ GdAssertReports.report_error(_current_failure_message, line_number)
+ Engine.set_meta("GD_TEST_FAILURE", true)
+ return self
+
+
+func do_fail() -> GdUnitAssert:
+ return report_error(GdAssertMessages.error_not_implemented())
+
+
+func override_failure_message(message: String) -> GdUnitAssert:
+ _custom_failure_message = message
+ return self
+
+
+func append_failure_message(message: String) -> GdUnitAssert:
+ _additional_failure_message = message
+ return self
+
+
+func is_null() -> GdUnitAssert:
+ var current :Variant = current_value()
+ if current != null:
+ return report_error(GdAssertMessages.error_is_null(current))
+ return report_success()
+
+
+func is_not_null() -> GdUnitAssert:
+ var current :Variant = current_value()
+ if current == null:
+ return report_error(GdAssertMessages.error_is_not_null())
+ return report_success()
+
+
+func is_equal(expected: Variant) -> GdUnitAssert:
+ var current: Variant = current_value()
+ if not GdObjects.equals(current, expected):
+ return report_error(GdAssertMessages.error_equal(current, expected))
+ return report_success()
+
+
+func is_not_equal(expected: Variant) -> GdUnitAssert:
+ var current: Variant = current_value()
+ if GdObjects.equals(current, expected):
+ return report_error(GdAssertMessages.error_not_equal(current, expected))
+ return report_success()