Skip to content

Commit 8484b10

Browse files
chaliyclaude
andauthored
test: verify issues #275, #279, #282 are not reproducible (#306)
## Summary - Add regression tests confirming 3 reported issues work correctly - #275: `\(` in single-quoted strings preserved as literal - #279: Reserved words like `done` work as case patterns - #282: `find -type f` enumerates VFS files correctly ## Test plan - [x] All 4 tests pass locally - [ ] CI green Closes #275 #279 #282 --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent b64f7ee commit 8484b10

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//! Regression tests verifying issues #275, #279, #282 are not reproducible.
2+
//!
3+
//! These issues were reported but code review and testing confirm
4+
//! they work correctly in the current implementation.
5+
6+
use bashkit::Bash;
7+
8+
async fn run(script: &str) -> String {
9+
let mut bash = Bash::builder().build();
10+
let result = bash.exec(script).await.expect("exec failed");
11+
result.stdout
12+
}
13+
14+
/// Issue #275: Parser corrupts \( in single-quoted strings
15+
/// Single-quoted strings should be completely literal.
16+
#[tokio::test]
17+
async fn test_issue_275_backslash_paren_in_single_quotes() {
18+
// \( inside single quotes should be passed literally to sed
19+
let output = run(r#"echo "test pattern here" | sed 's/\(pattern\)/[\1]/'"#).await;
20+
assert!(
21+
output.contains("[pattern]"),
22+
"Expected '[pattern]' in output, got: {}",
23+
output
24+
);
25+
}
26+
27+
/// Issue #279: "done" as case pattern should work
28+
#[tokio::test]
29+
async fn test_issue_279_done_as_case_pattern() {
30+
let output = run(r#"
31+
status="done"
32+
case "$status" in
33+
done) echo "matched" ;;
34+
*) echo "nope" ;;
35+
esac
36+
"#)
37+
.await;
38+
assert_eq!(output.trim(), "matched");
39+
}
40+
41+
/// Issue #279: Other reserved words as case patterns
42+
#[tokio::test]
43+
async fn test_issue_279_reserved_words_as_case_patterns() {
44+
let output = run(r#"
45+
word="in"
46+
case "$word" in
47+
in) echo "matched_in" ;;
48+
do) echo "matched_do" ;;
49+
*) echo "nope" ;;
50+
esac
51+
"#)
52+
.await;
53+
assert_eq!(output.trim(), "matched_in");
54+
}
55+
56+
/// Issue #282: find -type f should enumerate VFS files
57+
#[tokio::test]
58+
async fn test_issue_282_find_type_f_vfs() {
59+
let mut bash = Bash::builder()
60+
.mount_text("/data/file1.txt", "hello")
61+
.mount_text("/data/file2.txt", "world")
62+
.mount_text("/data/subdir/file3.txt", "nested")
63+
.build();
64+
let result = bash
65+
.exec("find /data -type f | sort")
66+
.await
67+
.expect("exec failed");
68+
let lines: Vec<&str> = result.stdout.trim().lines().collect();
69+
assert!(
70+
lines.len() >= 3,
71+
"Expected at least 3 files, got {}: {:?}",
72+
lines.len(),
73+
lines
74+
);
75+
assert!(
76+
result.stdout.contains("file1.txt"),
77+
"Missing file1.txt in: {}",
78+
result.stdout
79+
);
80+
assert!(
81+
result.stdout.contains("file2.txt"),
82+
"Missing file2.txt in: {}",
83+
result.stdout
84+
);
85+
assert!(
86+
result.stdout.contains("file3.txt"),
87+
"Missing file3.txt in: {}",
88+
result.stdout
89+
);
90+
}

0 commit comments

Comments
 (0)