mirror of
https://github.com/openai/codex.git
synced 2026-04-29 08:56:38 +00:00
basic.rs: using expect tests
This commit is contained in:
@@ -25,3 +25,13 @@ impl Decision {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Decision {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Allow => f.write_str("allow"),
|
||||
Self::Prompt => f.write_str("prompt"),
|
||||
Self::Forbidden => f.write_str("forbidden"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,3 +64,23 @@ impl Policy {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Evaluation {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::NoMatch => f.write_str("NoMatch"),
|
||||
Self::Match {
|
||||
decision,
|
||||
matched_rules,
|
||||
} => {
|
||||
writeln!(f, "Match {{")?;
|
||||
writeln!(f, " decision: {decision},")?;
|
||||
writeln!(f, " matched_rules: [")?;
|
||||
for rule in matched_rules {
|
||||
writeln!(f, " {rule},")?;
|
||||
}
|
||||
write!(f, " ]\n}}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,12 @@ impl PatternToken {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PatternToken {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(render_pattern_token(self).as_str())
|
||||
}
|
||||
}
|
||||
|
||||
/// Prefix matcher for commands with support for alternative match tokens.
|
||||
/// First token is fixed since we key by the first token in policy.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
@@ -60,11 +66,29 @@ impl PrefixPattern {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for PrefixPattern {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "[{}]", render_pattern(self))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Rule {
|
||||
Prefix(PrefixRule),
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Rule {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Prefix(rule) => write!(
|
||||
f,
|
||||
"prefix_rule(pattern = {}, decision = {})",
|
||||
rule.pattern, rule.decision
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct PrefixRule {
|
||||
pub pattern: PrefixPattern,
|
||||
@@ -87,6 +111,20 @@ impl RuleMatch {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for RuleMatch {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::PrefixRuleMatch {
|
||||
matched_prefix,
|
||||
decision,
|
||||
} => write!(
|
||||
f,
|
||||
"PrefixRuleMatch {{ matched_prefix: {matched_prefix:?}, decision: {decision} }}"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Rule {
|
||||
pub fn program(&self) -> &str {
|
||||
match self {
|
||||
|
||||
Reference in New Issue
Block a user