firebase_rs_sdk/util/
assert.rs

1use crate::util::CONSTANTS;
2
3/// Panic with a Firebase-styled internal assertion message when the condition is false.
4pub fn assert(condition: bool, message: impl AsRef<str>) {
5    if !condition {
6        panic!("{}", assertion_error(message));
7    }
8}
9
10/// Build the string used when throwing assertion errors to keep parity with the JS SDK.
11pub fn assertion_error(message: impl AsRef<str>) -> String {
12    format!(
13        "Firebase ({}) INTERNAL ASSERT FAILED: {}",
14        CONSTANTS.sdk_version,
15        message.as_ref()
16    )
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    #[should_panic(expected = "INTERNAL ASSERT FAILED")]
25    fn assert_panics_on_false() {
26        assert(false, "should panic");
27    }
28
29    #[test]
30    fn assertion_error_formats_message() {
31        let err = assertion_error("boom");
32        assert!(err.contains("Firebase"));
33        assert!(err.contains("boom"));
34    }
35}