use super::{grouper::group_blocks, tokenizer::parse_script_blocks};
use crate::CommandGroup;
pub(crate) fn parse_shell_blocks(input: &str) -> Vec<CommandGroup> {
let blocks = parse_script_blocks(input);
group_blocks(&blocks)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_group_blocks() {
let input = r#"Last login: Wed Jun 4 23:31:44 on ttys000
[root@localhost:~]# echo "Hello, world!"
Hello, world!
[root@localhost:~]# date
Wed Jun 4 23:31:50 AM EDT 2025
[root@localhost:~]#
[root@localhost:~]#
[root@localhost:~]# cd /etc
[root@localhost:/etc]# cd ssh/
[root@localhost:/etc/ssh]# ps -ef
UID PID PPID C STIME TTY TIME CMD
0 1 0 0 14 525 ?? 109:26.82 /sbin/launchd
0 88 1 0 14 525 ?? 50:56.48 /usr/libexec/logd
"#;
let cmds = parse_shell_blocks(input);
for (i, cmd) in cmds.iter().enumerate() {
println!("🎯 Cmd {}:\n{:#?}", i + 1, cmd);
}
assert!(cmds.len() >= 8);
assert_eq!(cmds[0].prompt, "");
assert_eq!(cmds[0].command, "");
assert!(!cmds[0].output.is_empty());
assert!(cmds[1].prompt.contains("[root@localhost:~]#"));
assert_eq!(cmds[1].command, r#"echo "Hello, world!""#);
}
}