use std::collections::HashMap;
use std::fmt;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
#[cfg(feature = "serde_json")]
use serde_json::Value as JsonValue;
use tabnas::{
ActionError, Context, GrammarError, GrammarSpec, ImperativeLexMatcher, Lexer, Options, Plugin,
PluginError, Rule, RuleState, Tabnas, Tin, Token, Value,
};
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
mod readme_examples {}
pub const VERSION: &str = "0.3.15";
pub const DEFAULT_LEX_ORDER: f64 = 4.5e6;
pub const DEFAULT_TOKEN: &str = "#HV";
pub const INVALID_TEXT: &str = "invalid_text";
pub const INVALID_ESCAPE: &str = "invalid_escape";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HooverError(pub String);
impl fmt::Display for HooverError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.0)
}
}
impl std::error::Error for HooverError {}
impl From<PluginError> for HooverError {
fn from(error: PluginError) -> Self {
Self(error.0)
}
}
impl From<GrammarError> for HooverError {
fn from(error: GrammarError) -> Self {
Self(error.0)
}
}
impl From<HooverError> for PluginError {
fn from(error: HooverError) -> Self {
Self(error.0)
}
}
pub type ActionFn = Arc<dyn Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Send + Sync>;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct HooverRuleFilter {
pub include: Option<Vec<String>>,
pub exclude: Option<Vec<String>>,
}
impl HooverRuleFilter {
pub fn include(names: &[&str]) -> Self {
Self {
include: Some(names.iter().map(|name| (*name).to_string()).collect()),
exclude: None,
}
}
pub fn exclude(names: &[&str]) -> Self {
Self {
include: None,
exclude: Some(names.iter().map(|name| (*name).to_string()).collect()),
}
}
fn passes(&self, name: &str, match_rule: &mut Option<bool>) {
let listed = |list: &[String]| list.iter().any(|entry| entry == name);
if let Some(include) = &self.include {
and_into(match_rule, listed(include));
}
if let Some(exclude) = &self.exclude {
and_into(match_rule, !listed(exclude));
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct HooverRuleSpec {
pub parent: Option<HooverRuleFilter>,
pub current: Option<HooverRuleFilter>,
pub state: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub enum Consume {
#[default]
All,
Never,
Only(Vec<String>),
}
impl Consume {
fn applies_to(&self, delimiter: &str) -> bool {
match self {
Consume::All => true,
Consume::Never => false,
Consume::Only(list) => list.iter().any(|entry| entry == delimiter),
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct StartSpec {
pub fixed: Option<Vec<String>>,
pub consume: Consume,
pub rule: Option<HooverRuleSpec>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct EndSpec {
pub fixed: Vec<String>,
pub consume: Consume,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Block {
pub name: String,
pub start: Option<StartSpec>,
pub end: EndSpec,
pub token: Option<String>,
pub escape_char: Option<char>,
pub escape: HashMap<String, String>,
pub allow_unknown_escape: Option<bool>,
pub preserve_escape_char: bool,
pub trim: bool,
}
impl Block {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
..Self::default()
}
}
pub fn delimited(name: impl Into<String>, start: &str, end: &str) -> Self {
Self::new(name).with_start(&[start]).with_end(&[end])
}
pub fn with_start(mut self, fixed: &[&str]) -> Self {
let start = self.start.get_or_insert_with(StartSpec::default);
start.fixed = Some(fixed.iter().map(|entry| (*entry).to_string()).collect());
self
}
pub fn with_end(mut self, fixed: &[&str]) -> Self {
self.end.fixed = fixed.iter().map(|entry| (*entry).to_string()).collect();
self
}
pub fn with_rule(mut self, rule: HooverRuleSpec) -> Self {
self.start.get_or_insert_with(StartSpec::default).rule = Some(rule);
self
}
pub fn with_escape_char(mut self, escape_char: char) -> Self {
self.escape_char = Some(escape_char);
self
}
pub fn with_escape(mut self, escaped: &str, replacement: &str) -> Self {
self.escape
.insert(escaped.to_string(), replacement.to_string());
self
}
fn token_name(&self) -> &str {
self.token.as_deref().unwrap_or(DEFAULT_TOKEN)
}
fn allow_unknown(&self) -> bool {
self.allow_unknown_escape.unwrap_or(true)
}
}
#[derive(Clone, Default)]
pub struct HooverOptions {
pub block: Vec<Block>,
pub lex_order: Option<f64>,
pub action: Option<ActionFn>,
}
impl fmt::Debug for HooverOptions {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("HooverOptions")
.field("block", &self.block)
.field("lex_order", &self.lex_order)
.field("action", &self.action.as_ref().map(|_| "<function>"))
.finish()
}
}
impl HooverOptions {
pub fn new(block: Vec<Block>) -> Self {
Self {
block,
lex_order: None,
action: None,
}
}
pub fn with_lex_order(mut self, order: f64) -> Self {
self.lex_order = Some(order);
self
}
pub fn with_action(
mut self,
action: impl Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Send + Sync + 'static,
) -> Self {
self.action = Some(Arc::new(action));
self
}
#[cfg(feature = "serde_json")]
pub fn from_json(document: &JsonValue) -> Result<Self, HooverError> {
let map = document
.as_object()
.ok_or_else(|| HooverError("hoover: options must be an object".into()))?;
let mut options = Self::default();
if let Some(blocks) = field(map, "block") {
let blocks = blocks.as_array().ok_or_else(|| {
HooverError("hoover: options.block must be an array of blocks".into())
})?;
options.block = blocks
.iter()
.map(block_from_json)
.collect::<Result<Vec<_>, _>>()?;
}
if let Some(lex) = field(map, "lex").and_then(JsonValue::as_object) {
if let Some(order) = field(lex, "order") {
options.lex_order = Some(order.as_f64().ok_or_else(|| {
HooverError("hoover: options.lex.order must be a number".into())
})?);
}
}
Ok(options)
}
}
#[cfg(feature = "serde_json")]
fn field<'a>(map: &'a serde_json::Map<String, JsonValue>, key: &str) -> Option<&'a JsonValue> {
map.get(key).or_else(|| {
map.iter()
.find(|(candidate, _)| candidate.eq_ignore_ascii_case(key))
.map(|(_, value)| value)
})
}
#[cfg(feature = "serde_json")]
fn strings_from_json(value: &JsonValue, label: &str) -> Result<Vec<String>, HooverError> {
match value {
JsonValue::String(text) => Ok(vec![text.clone()]),
JsonValue::Array(items) => items
.iter()
.map(|item| {
item.as_str()
.map(str::to_string)
.ok_or_else(|| HooverError(format!("hoover: {label} entries must be strings")))
})
.collect(),
_ => Err(HooverError(format!(
"hoover: {label} must be a string or a list of strings"
))),
}
}
#[cfg(feature = "serde_json")]
fn consume_from_json(
map: &serde_json::Map<String, JsonValue>,
label: &str,
) -> Result<Consume, HooverError> {
match field(map, "consume") {
None | Some(JsonValue::Null) | Some(JsonValue::Bool(true)) => Ok(Consume::All),
Some(JsonValue::Bool(false)) => Ok(Consume::Never),
Some(list @ JsonValue::Array(_)) => Ok(Consume::Only(strings_from_json(
list,
&format!("{label}.consume"),
)?)),
Some(_) => Err(HooverError(format!(
"hoover: {label}.consume must be a boolean or a list of strings"
))),
}
}
#[cfg(feature = "serde_json")]
fn filter_from_json(value: &JsonValue, label: &str) -> Result<HooverRuleFilter, HooverError> {
let map = value
.as_object()
.ok_or_else(|| HooverError(format!("hoover: {label} must be an object")))?;
Ok(HooverRuleFilter {
include: field(map, "include")
.map(|list| strings_from_json(list, &format!("{label}.include")))
.transpose()?,
exclude: field(map, "exclude")
.map(|list| strings_from_json(list, &format!("{label}.exclude")))
.transpose()?,
})
}
#[cfg(feature = "serde_json")]
fn rule_from_json(value: &JsonValue, label: &str) -> Result<HooverRuleSpec, HooverError> {
let map = value
.as_object()
.ok_or_else(|| HooverError(format!("hoover: {label} must be an object")))?;
Ok(HooverRuleSpec {
parent: field(map, "parent")
.map(|filter| filter_from_json(filter, &format!("{label}.parent")))
.transpose()?,
current: field(map, "current")
.map(|filter| filter_from_json(filter, &format!("{label}.current")))
.transpose()?,
state: field(map, "state")
.and_then(JsonValue::as_str)
.map(str::to_string),
})
}
#[cfg(feature = "serde_json")]
fn block_from_json(value: &JsonValue) -> Result<Block, HooverError> {
let map = value
.as_object()
.ok_or_else(|| HooverError("hoover: each block must be an object".into()))?;
let name = field(map, "name")
.and_then(JsonValue::as_str)
.unwrap_or("")
.to_string();
let label = format!("block {name:?}");
let mut block = Block::new(name);
if let Some(token) = field(map, "token").and_then(JsonValue::as_str) {
block.token = Some(token.to_string());
}
if let Some(escape_char) = field(map, "escapeChar").and_then(JsonValue::as_str) {
let mut chars = escape_char.chars();
block.escape_char = match (chars.next(), chars.next()) {
(None, _) => None,
(Some(first), None) => Some(first),
(Some(_), Some(_)) => {
return Err(HooverError(format!(
"hoover: {label}.escapeChar must be a single character"
)))
}
};
}
if let Some(escape) = field(map, "escape").and_then(JsonValue::as_object) {
for (key, replacement) in escape {
if let Some(replacement) = replacement.as_str() {
block.escape.insert(key.clone(), replacement.to_string());
}
}
}
if let Some(allow) = field(map, "allowUnknownEscape").and_then(JsonValue::as_bool) {
block.allow_unknown_escape = Some(allow);
}
block.preserve_escape_char = field(map, "preserveEscapeChar")
.and_then(JsonValue::as_bool)
.unwrap_or(false);
block.trim = field(map, "trim")
.and_then(JsonValue::as_bool)
.unwrap_or(false);
if let Some(start) = field(map, "start") {
if !start.is_null() && !start.is_object() {
return Err(HooverError(format!(
"hoover: {label}.start must be an object"
)));
}
}
if let Some(end) = field(map, "end") {
if !end.is_null() && !end.is_object() {
return Err(HooverError(format!(
"hoover: {label}.end must be an object"
)));
}
}
if let Some(start) = field(map, "start").and_then(JsonValue::as_object) {
let start_label = format!("{label}.start");
block.start = Some(StartSpec {
fixed: field(start, "fixed")
.map(|fixed| strings_from_json(fixed, &format!("{start_label}.fixed")))
.transpose()?,
consume: consume_from_json(start, &start_label)?,
rule: field(start, "rule")
.map(|rule| rule_from_json(rule, &format!("{start_label}.rule")))
.transpose()?,
});
}
if let Some(end) = field(map, "end").and_then(JsonValue::as_object) {
let end_label = format!("{label}.end");
block.end = EndSpec {
fixed: field(end, "fixed")
.map(|fixed| strings_from_json(fixed, &format!("{end_label}.fixed")))
.transpose()?
.unwrap_or_default(),
consume: consume_from_json(end, &end_label)?,
};
}
Ok(block)
}
pub fn plugin(options: HooverOptions) -> Plugin {
Plugin::new("Hoover", move |parser, _plugin_options| {
install(parser, &options).map_err(PluginError::from)
})
}
pub fn hoover(parser: &mut Tabnas, options: HooverOptions) -> Result<(), HooverError> {
parser
.use_plugin(plugin(options), None)
.map(|_| ())
.map_err(HooverError::from)
}
struct Prepared {
block: Block,
token_name: String,
tin: Tin,
}
struct MatcherConfig {
value_lex: bool,
definitions: HashMap<String, Value>,
}
impl MatcherConfig {
fn from_options(options: &Options) -> Self {
Self {
value_lex: options.value.lex,
definitions: options
.value
.definitions
.iter()
.map(|(source, definition)| {
(
source.clone(),
definition.val.clone().unwrap_or(Value::Undefined),
)
})
.collect(),
}
}
}
static INSTALLS: AtomicUsize = AtomicUsize::new(0);
fn json_string(text: &str) -> String {
let mut out = String::with_capacity(text.len() + 2);
out.push('"');
for c in text.chars() {
match c {
'"' => out.push_str("\\\""),
'\\' => out.push_str("\\\\"),
'\n' => out.push_str("\\n"),
'\r' => out.push_str("\\r"),
'\t' => out.push_str("\\t"),
c if (c as u32) < 0x20 => out.push_str(&format!("\\u{:04x}", c as u32)),
c => out.push(c),
}
}
out.push('"');
out
}
fn install(parser: &mut Tabnas, options: &HooverOptions) -> Result<(), HooverError> {
if !parser.rule_names().iter().any(|name| name == "val") {
return Err(HooverError(
"tabnas-hoover: the 'val' rule is missing; \
register a grammar that defines it before the hoover plugin"
.into(),
));
}
let id = INSTALLS.fetch_add(1, Ordering::Relaxed);
let make_ref = format!("@hoover-matcher-{id}");
let action_ref = format!("@hoover-action-{id}");
let config = parser.config();
let include: Vec<String> = listed(&config.rule.include).map(str::to_string).collect();
let groups = include.join(",");
let mut prepared: Vec<Prepared> = Vec::with_capacity(options.block.len());
let mut token_map: Vec<(String, Tin)> = Vec::new();
let mut alts: Vec<String> = Vec::new();
if let Some(action) = options.action.clone() {
parser.action_with_context(action_ref.clone(), move |rule, context| {
action(rule, context)
});
}
for block in &options.block {
let token_name = block.token_name().to_string();
if token_name.is_empty() || token_name.chars().any(char::is_whitespace) {
return Err(HooverError(format!(
"tabnas-hoover: block {:?} has the token name {:?}; \
a token name is a non-empty word without whitespace",
block.name, token_name
)));
}
let tin = parser.token(token_name.clone());
if !token_map.iter().any(|(name, _)| *name == token_name) {
let mut alt = format!("{{\"s\":{}", json_string(&token_name));
if options.action.is_some() {
alt.push_str(&format!(",\"a\":{}", json_string(&action_ref)));
}
if !groups.is_empty() {
alt.push_str(&format!(",\"g\":{}", json_string(&groups)));
}
alt.push('}');
alts.insert(0, alt);
token_map.push((token_name.clone(), tin));
}
prepared.push(Prepared {
block: block.clone(),
token_name,
tin,
});
}
let blocks = Arc::new(prepared);
parser.lex_match_factory_ref(make_ref.clone(), move |resolved: &Options| {
let config = Arc::new(MatcherConfig::from_options(resolved));
let blocks = Arc::clone(&blocks);
let matcher: ImperativeLexMatcher = Arc::new(
move |lexer: &mut Lexer<'_>, rule: &mut Rule, _context: &mut Context| {
hoover_matcher(lexer, rule, &blocks, &config)
},
);
Some(matcher)
});
let order = options.lex_order.unwrap_or(DEFAULT_LEX_ORDER);
if !order.is_finite() {
return Err(HooverError(
"hoover: lex.order must be a finite number".into(),
));
}
let document = format!(
"{{\"options\":{{\"lex\":{{\"match\":{{\"hoover\":{{\"order\":{order},\"make\":{make}}}}}}}}},\
\"rule\":{{\"val\":{{\"open\":[{alts}]}}}}}}",
make = json_string(&make_ref),
alts = alts.join(",")
);
let spec = GrammarSpec::from_json(&document)?;
parser.grammar(&spec)?;
let config = parser.config();
let survivors = parser
.rule_specs()
.into_iter()
.find(|spec| spec.name == "val")
.map(|spec| spec.open.clone())
.unwrap_or_default();
let missing: Vec<&str> = token_map
.iter()
.filter(|(_, tin)| {
!survivors.iter().any(|alt| {
alt.s.iter().any(|position| position.contains(tin))
&& groups_enabled(&alt.g, &config.rule.include, &config.rule.exclude)
})
})
.map(|(name, _)| name.as_str())
.collect();
if !missing.is_empty() {
return Err(HooverError(format!(
"tabnas-hoover: the block alternate was removed from the 'val' rule by the \
host grammar's alt filter (rule.include={:?}, rule.exclude={:?}); \
hoover cannot extend a grammar that excludes it",
include,
listed(&config.rule.exclude).collect::<Vec<_>>(),
)));
}
Ok(())
}
fn listed(list: &str) -> impl Iterator<Item = &str> {
list.split(',')
.map(str::trim)
.filter(|entry| !entry.is_empty())
}
fn groups_enabled(alt_groups: &str, include: &str, exclude: &str) -> bool {
if include.is_empty() && exclude.is_empty() {
return true;
}
let declares = |wanted: &str| listed(alt_groups).any(|group| group == wanted);
let included = listed(include).next().is_none() || listed(include).any(declares);
included && !listed(exclude).any(declares)
}
fn and_into(match_rule: &mut Option<bool>, value: bool) {
*match_rule = Some(value && match_rule.unwrap_or(true));
}
fn hoover_matcher(
lexer: &mut Lexer<'_>,
rule: &mut Rule,
blocks: &[Prepared],
config: &MatcherConfig,
) -> Option<Token> {
let mut exhausted = !lexer.windowed();
'blocks: for prepared in blocks {
let block = &prepared.block;
let point = lexer.point();
loop {
let rest = lexer.window();
let scanned = match match_start(rest, rule, block, exhausted) {
Start::No => continue 'blocks,
Start::Edge => Err(Rejected::Edge),
Start::At(start) => parse_to_end(rest, start, block, config, exhausted),
};
match scanned {
Ok(Scanned { value, end }) => {
let source = &rest[..end];
let mut token =
lexer.token(&prepared.token_name, prepared.tin, value, source, point);
token
.use_data_mut()
.insert("block".to_string(), Value::String(block.name.clone()));
let consumed = source.chars().count();
lexer.advance_chars(consumed);
return Some(token);
}
Err(Rejected::Edge) => {
let ahead = rest.len();
let read = rest.chars().count();
lexer.fill(read.saturating_mul(2).max(read + 1));
if lexer.window().len() <= ahead {
exhausted = true;
}
}
Err(Rejected::Escape { at }) => {
let position = point.site.pos + rest[..at].chars().count();
return Some(lexer.bad_span(INVALID_ESCAPE, position, position + 1));
}
Err(Rejected::Unterminated { start }) => {
let position = point.site.pos;
let width = rest[..start].chars().count();
return Some(lexer.bad_span(INVALID_TEXT, position, position + width));
}
}
}
}
None
}
enum Start {
No,
Edge,
At(usize),
}
fn match_start(rest: &str, rule: &Rule, block: &Block, exhausted: bool) -> Start {
let start = block.start.as_ref();
let rulespec = start.and_then(|start| start.rule.as_ref());
let mut match_rule: Option<bool> = None;
if let Some(rulespec) = rulespec {
if let Some(parent) = &rulespec.parent {
let parent_name = rule
.parent_rule
.as_deref()
.map_or("", |parent| parent.name.as_ref());
parent.passes(parent_name, &mut match_rule);
}
if let Some(current) = &rulespec.current {
current.passes(rule.name.as_ref(), &mut match_rule);
}
}
let rulestate = rulespec
.and_then(|spec| spec.state.as_deref())
.unwrap_or("o");
if !rulestate.is_empty() {
let state = match rule.state {
RuleState::Open => 'o',
RuleState::Close => 'c',
};
and_into(&mut match_rule, rulestate.contains(state));
}
if !match_rule.unwrap_or(true) {
return Start::No;
}
let Some(fixed) = start.and_then(|start| start.fixed.as_ref()) else {
return Start::At(0);
};
let consume = start.map(|start| &start.consume);
for delimiter in fixed {
if rest.starts_with(delimiter.as_str()) {
let consumed = consume.is_none_or(|consume| consume.applies_to(delimiter));
return Start::At(if consumed { delimiter.len() } else { 0 });
}
if !exhausted && rest.len() < delimiter.len() && delimiter.starts_with(rest) {
return Start::Edge;
}
}
Start::No
}
struct Scanned {
value: Value,
end: usize,
}
enum Rejected {
Escape { at: usize },
Unterminated { start: usize },
Edge,
}
fn parse_to_end(
rest: &str,
start: usize,
block: &Block,
config: &MatcherConfig,
exhausted: bool,
) -> Result<Scanned, Rejected> {
let fixed = &block.end.fixed;
let endchars: Vec<Option<char>> = fixed.iter().map(|end| end.chars().next()).collect();
let endseqs: Vec<&str> = fixed
.iter()
.map(|end| end.chars().next().map_or("", |c| &end[c.len_utf8()..]))
.collect();
let mut value = String::new();
let mut index = start;
let mut done = false;
let mut end_index = index;
loop {
let current = rest[index..].chars().next();
if current.is_none() && !exhausted {
return Err(Rejected::Edge);
}
if let Some(found) = endchars.iter().position(|end| *end == current) {
let tail = endseqs[found];
let after = index + current.map_or(0, char::len_utf8);
if current.is_none() || tail.is_empty() {
end_index = after;
done = true;
break;
}
if !exhausted && rest.len() - after < tail.len() {
return Err(Rejected::Edge);
}
if rest[after..].starts_with(tail) {
end_index = after + tail.len();
done = true;
break;
}
}
let Some(c) = current else {
break;
};
if Some(c) == block.escape_char {
let next = index + c.len_utf8();
let Some(escaped) = rest[next..].chars().next() else {
if !exhausted {
return Err(Rejected::Edge);
}
return Err(Rejected::Unterminated { start });
};
let after = next + escaped.len_utf8();
let mapped = if (escaped as u32) <= 0xFFFF {
block.escape.get(&escaped.to_string())
} else {
None
};
if let Some(replacement) = mapped {
value.push_str(replacement);
} else if block.allow_unknown() {
if block.preserve_escape_char {
value.push(c);
}
value.push(escaped);
} else {
return Err(Rejected::Escape { at: index });
}
index = after;
} else {
value.push(c);
index += c.len_utf8();
}
}
if !done {
return Err(Rejected::Unterminated { start });
}
let endfixed = &rest[index..end_index];
if block.end.consume.applies_to(endfixed) {
index = end_index;
}
let text = if block.trim {
js_trim(&value).to_string()
} else {
value
};
let value = match config.definitions.get(&text) {
Some(defined) if config.value_lex => defined.clone(),
_ => Value::String(text),
};
Ok(Scanned { value, end: index })
}
fn is_trim_space(c: char) -> bool {
matches!(
c,
'\u{0009}' | '\u{000A}' | '\u{000B}' | '\u{000C}' | '\u{000D}' | '\u{0020}' | '\u{00A0}' | '\u{1680}' | '\u{2000}' | '\u{2001}' | '\u{2002}' | '\u{2003}' | '\u{2004}' | '\u{2005}' | '\u{2006}' | '\u{2007}' | '\u{2008}' | '\u{2009}' | '\u{200A}' | '\u{2028}' | '\u{2029}' | '\u{202F}' | '\u{205F}' | '\u{3000}' | '\u{FEFF}' )
}
pub fn js_trim(text: &str) -> &str {
text.trim_matches(is_trim_space)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn js_trim_follows_ecma_262_not_unicode_white_space() {
assert_eq!(js_trim("\u{FEFF} hello \u{FEFF}"), "hello");
assert_eq!(js_trim("\u{0085}hello\u{0085}"), "\u{0085}hello\u{0085}");
assert_eq!(js_trim("\u{200B}hello"), "\u{200B}hello");
assert_eq!(js_trim("\u{FEFF} \u{3000}"), "");
}
#[test]
fn groups_enabled_mirrors_the_engine_filter() {
assert!(groups_enabled("", "", ""));
assert!(groups_enabled("mini", "mini", ""));
assert!(!groups_enabled("", "mini", ""));
assert!(!groups_enabled("mini", "mini", "mini"));
assert!(groups_enabled("a,mini", "mini,json", "other"));
}
}