From e30161ac3cb2a67b300572e2dc1a18141631d3cb Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Mon, 6 Nov 2023 11:18:20 +0800 Subject: [PATCH] Add test: `builtin_mappings_matcher_only_compile_once` --- src/syntax_mapping.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/syntax_mapping.rs b/src/syntax_mapping.rs index a7923a5c..e523f85e 100644 --- a/src/syntax_mapping.rs +++ b/src/syntax_mapping.rs @@ -148,6 +148,23 @@ mod tests { let _mappings = map.builtin_mappings().collect::>(); } + #[test] + fn builtin_mappings_matcher_only_compile_once() { + let map = SyntaxMapping::new(); + + let two_iterations: Vec<_> = (0..2) + .map(|_| { + // addresses of every matcher + map.builtin_mappings() + .map(|(matcher, _)| matcher as *const _ as usize) + .collect::>() + }) + .collect(); + + // if the matchers are only compiled once, their address should remain the same + assert_eq!(two_iterations[0], two_iterations[1]); + } + #[test] fn custom_mappings_work() { let mut map = SyntaxMapping::new();