rhai/src/tests.rs

70 lines
2.0 KiB
Rust
Raw Normal View History

2021-09-07 16:12:04 +02:00
//! Module containing unit tests.
#![cfg(test)]
/// This test is to make sure no code changes increase the sizes of critical data structures.
#[test]
fn check_struct_sizes() {
use crate::*;
use std::mem::size_of;
2022-09-22 11:20:57 +02:00
const IS_32_BIT: bool = cfg!(target_pointer_width = "32");
2021-09-07 16:12:04 +02:00
const PACKED: bool = cfg!(all(
target_pointer_width = "32",
feature = "only_i32",
2022-01-12 04:01:03 +01:00
any(feature = "no_float", feature = "f32_float")
2021-09-07 16:12:04 +02:00
));
assert_eq!(size_of::<Dynamic>(), if PACKED { 8 } else { 16 });
assert_eq!(size_of::<Option<Dynamic>>(), if PACKED { 8 } else { 16 });
2021-12-03 04:16:35 +01:00
assert_eq!(
size_of::<Position>(),
if cfg!(feature = "no_position") { 0 } else { 4 }
);
2022-09-22 11:20:57 +02:00
assert_eq!(
size_of::<tokenizer::Token>(),
if IS_32_BIT { 8 } else { 16 }
2022-09-22 11:20:57 +02:00
);
2022-01-12 04:01:03 +01:00
assert_eq!(size_of::<ast::Expr>(), if PACKED { 12 } else { 16 });
assert_eq!(size_of::<Option<ast::Expr>>(), if PACKED { 12 } else { 16 });
2022-09-22 11:20:57 +02:00
assert_eq!(size_of::<ast::Stmt>(), if IS_32_BIT { 12 } else { 16 });
assert_eq!(
size_of::<Option<ast::Stmt>>(),
if IS_32_BIT { 12 } else { 16 }
);
assert_eq!(
size_of::<CallableFunction>(),
if IS_32_BIT { 12 } else { 24 }
);
assert_eq!(
size_of::<module::FuncInfo>(),
if IS_32_BIT { 16 } else { 32 }
);
2022-01-12 04:01:03 +01:00
#[cfg(target_pointer_width = "64")]
{
2022-02-28 07:00:55 +01:00
assert_eq!(size_of::<Scope>(), 536);
assert_eq!(
size_of::<FnPtr>(),
if cfg!(feature = "no_function") {
64
} else {
72
}
);
2022-01-12 04:01:03 +01:00
assert_eq!(size_of::<LexError>(), 56);
assert_eq!(
size_of::<ParseError>(),
if cfg!(feature = "no_position") { 8 } else { 16 }
);
2022-11-04 12:18:56 +01:00
assert_eq!(size_of::<EvalAltResult>(), 64);
2022-01-12 04:01:03 +01:00
assert_eq!(
size_of::<NativeCallContext>(),
if cfg!(feature = "no_position") {
2022-11-10 04:49:10 +01:00
48
} else {
2022-11-10 04:49:10 +01:00
56
2022-01-12 04:01:03 +01:00
}
);
}
2021-09-07 16:12:04 +02:00
}