foundry_config/inline/
mod.rsuse crate::Config;
use alloy_primitives::map::HashMap;
use std::sync::LazyLock;
mod conf_parser;
pub use conf_parser::*;
mod error;
pub use error::*;
mod natspec;
pub use natspec::*;
pub const INLINE_CONFIG_FUZZ_KEY: &str = "fuzz";
pub const INLINE_CONFIG_INVARIANT_KEY: &str = "invariant";
const INLINE_CONFIG_PREFIX: &str = "forge-config";
static INLINE_CONFIG_PREFIX_SELECTED_PROFILE: LazyLock<String> = LazyLock::new(|| {
let selected_profile = Config::selected_profile().to_string();
format!("{INLINE_CONFIG_PREFIX}:{selected_profile}.")
});
#[derive(Clone, Debug, Default)]
pub struct InlineConfig<T> {
contract_level: HashMap<String, T>,
fn_level: HashMap<(String, String), T>,
}
impl<T> InlineConfig<T> {
pub fn get(&self, contract_id: &str, fn_name: &str) -> Option<&T> {
let key = (contract_id.to_string(), fn_name.to_string());
self.fn_level.get(&key).or_else(|| self.contract_level.get(contract_id))
}
pub fn insert_contract(&mut self, contract_id: impl Into<String>, config: T) {
self.contract_level.insert(contract_id.into(), config);
}
pub fn insert_fn<C, F>(&mut self, contract_id: C, fn_name: F, config: T)
where
C: Into<String>,
F: Into<String>,
{
let key = (contract_id.into(), fn_name.into());
self.fn_level.insert(key, config);
}
}
pub(crate) fn remove_whitespaces(s: &str) -> String {
s.chars().filter(|c| !c.is_whitespace()).collect()
}