refactor(parsing): remove old FromStr-based parser implementation

This commit is contained in:
Khaïs COLIN 2025-05-04 18:17:36 +02:00
parent 106c2547b5
commit 6b49d3ca14
9 changed files with 67 additions and 99 deletions

View file

@ -94,25 +94,11 @@ impl From<ScanError> for CommandParseError {
}
}
impl std::str::FromStr for Command {
type Err = CommandParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.starts_with(".") {
s.parse::<MetaCommand>()
.map(|x| x.into())
.map_err(|x| x.into())
} else {
s.parse::<Statement>()
.map(|x| x.into())
.map_err(|x| x.into())
}
}
}
#[cfg(test)]
mod tests {
use crate::{command::Command, meta_commands::MetaCommand, statements::Statement};
use crate::{
command::Command, meta_commands::MetaCommand, parser::parse, statements::Statement,
};
use insta::{assert_debug_snapshot, assert_snapshot};
#[test]
@ -136,11 +122,11 @@ mod tests {
#[test]
fn test_parse_wrong_statement() {
assert_debug_snapshot!("salact".parse::<Command>());
assert_debug_snapshot!(parse("<stdin>".to_string(), "salact".to_string()));
}
#[test]
fn test_parse_wrong_meta_command() {
assert_debug_snapshot!(".halp".parse::<Command>());
assert_debug_snapshot!(parse("<stdin>".to_string(), ".halp".to_string()));
}
}