1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-02 19:32:25 +01:00

Add test: builtin_mappings_are_lazily_evaluated

This commit is contained in:
cyqsimon
2023-11-06 12:57:15 +08:00
parent e30161ac3c
commit 586c804b1e
3 changed files with 48 additions and 0 deletions

View File

@@ -128,6 +128,9 @@ impl<'a> SyntaxMapping<'a> {
#[cfg(test)]
mod tests {
use once_cell::sync::Lazy;
use rusty_fork::rusty_fork_test;
use super::*;
#[test]
fn builtin_mappings_work() {
@@ -148,6 +151,31 @@ mod tests {
let _mappings = map.builtin_mappings().collect::<Vec<_>>();
}
// lazy initialisation test needs to be run on a separate instance because
// it will race with other tests
// see: https://github.com/rust-lang/rust/issues/47506
rusty_fork_test! {
#[test]
fn builtin_mappings_are_lazily_evaluated() {
let map = SyntaxMapping::new();
assert!(BUILTIN_MAPPINGS
.iter()
.all(|(matcher, _)| Lazy::get(matcher).is_none()));
// calling `builtin_mappings` should not trigger evaluation
let mappings_iter = map.builtin_mappings();
assert!(BUILTIN_MAPPINGS
.iter()
.all(|(matcher, _)| Lazy::get(matcher).is_none()));
let _mappings: Vec<_> = mappings_iter.collect();
assert!(BUILTIN_MAPPINGS
.iter()
.all(|(matcher, _)| Lazy::get(matcher).is_some()));
}
}
#[test]
fn builtin_mappings_matcher_only_compile_once() {
let map = SyntaxMapping::new();