Skip to content

Commit 5b5ba01

Browse files
committed
strs_tools : unescaping
1 parent aae2330 commit 5b5ba01

File tree

3 files changed

+106
-4
lines changed

3 files changed

+106
-4
lines changed

module/core/strs_tools/task/task_plan.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* ✅ Increment 3: Fix Compilation Errors
2020
* ✅ Increment 4: Implement Unescaping Logic
2121
* ✅ Increment 5: Implement Quoted Segment Logic
22-
* Increment 6: Add New Tests for Unescaping and Quoting
22+
* Increment 6: Add New Tests for Unescaping and Quoting
2323
* ⚫ Increment 7: Finalization
2424

2525
### Permissions & Boundaries
@@ -133,9 +133,10 @@
133133
* **Specification Reference:** "Acceptance Criteria" from the proposal.
134134
* **Steps:**
135135
* Step 1: Create a new test file: `module/core/strs_tools/tests/inc/split_test/quoting_and_unescaping_tests.rs`.
136-
* Step 2: Add this new file as a module in `module/core/strs_tools/tests/inc/split_test/mod.rs`.
137-
* Step 3: In the new test file, add a test case that is an exact copy of the MRE from the task description. Assert that the output for the quoted part is a single `Split` item with the correctly unescaped string.
138-
* Step 4: Add more test cases covering:
136+
* Step 2: Use `read_file` to load `module/core/strs_tools/tests/inc/split_test/mod.rs`.
137+
* Step 3: Use `insert_content` to add `pub mod quoting_and_unescaping_tests;` to `module/core/strs_tools/tests/inc/split_test/mod.rs`.
138+
* Step 4: In the new test file (`quoting_and_unescaping_tests.rs`), add a test case that is an exact copy of the MRE from the task description. Assert that the output for the quoted part is a single `Split` item with the correctly unescaped string.
139+
* Step 5: Add more test cases covering:
139140
* Strings with no quotes.
140141
* Strings with empty quoted sections (`""`).
141142
* Strings with multiple, different escape sequences.

module/core/strs_tools/tests/inc/split_test/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ mod quoting_options_tests;
4747
mod indexing_options_tests;
4848
mod combined_options_tests;
4949
mod edge_case_tests;
50+
mod quoting_and_unescaping_tests;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//! Tests focusing on `quoting` and unescaping behavior.
2+
use strs_tools::string::split::*;
3+
4+
// Test case from the original issue description
5+
#[test]
6+
fn test_mre_unescaping()
7+
{
8+
let src = r#"sub .asset.get path:"a b""#;
9+
let iter = split()
10+
.src( src )
11+
.delimeter( " " )
12+
.quoting( true )
13+
.preserving_quoting( false )
14+
.perform();
15+
let splits : Vec<_> = iter.map( | e | e.string ).collect();
16+
assert_eq!( splits, vec![ "sub", ".asset.get", "path:a b" ] );
17+
}
18+
19+
#[test]
20+
fn test_no_quotes()
21+
{
22+
let src = "a b c";
23+
let iter = split()
24+
.src( src )
25+
.delimeter( " " )
26+
.quoting( true )
27+
.perform();
28+
let splits : Vec<_> = iter.map( | e | e.string ).collect();
29+
assert_eq!( splits, vec![ "a", "b", "c" ] );
30+
}
31+
32+
#[test]
33+
fn test_empty_quoted_sections()
34+
{
35+
let src = r#"a "" b"#;
36+
let iter = split()
37+
.src( src )
38+
.delimeter( " " )
39+
.quoting( true )
40+
.preserving_quoting( false )
41+
.perform();
42+
let splits : Vec<_> = iter.map( | e | e.string ).collect();
43+
assert_eq!( splits, vec![ "a", "", "b" ] );
44+
}
45+
46+
#[test]
47+
fn test_multiple_escape_sequences()
48+
{
49+
let src = r#""\n\t\\\"""#;
50+
let iter = split()
51+
.src( src )
52+
.delimeter( " " )
53+
.quoting( true )
54+
.preserving_quoting( false )
55+
.perform();
56+
let splits : Vec<_> = iter.map( | e | e.string ).collect();
57+
assert_eq!( splits, vec![ "\n\t\\\"" ] );
58+
}
59+
60+
#[test]
61+
fn test_quoted_at_start()
62+
{
63+
let src = r#""a b" c"#;
64+
let iter = split()
65+
.src( src )
66+
.delimeter( " " )
67+
.quoting( true )
68+
.preserving_quoting( false )
69+
.perform();
70+
let splits : Vec<_> = iter.map( | e | e.string ).collect();
71+
assert_eq!( splits, vec![ "a b", "c" ] );
72+
}
73+
74+
#[test]
75+
fn test_quoted_at_end()
76+
{
77+
let src = r#"a "b c""#;
78+
let iter = split()
79+
.src( src )
80+
.delimeter( " " )
81+
.quoting( true )
82+
.preserving_quoting( false )
83+
.perform();
84+
let splits : Vec<_> = iter.map( | e | e.string ).collect();
85+
assert_eq!( splits, vec![ "a", "b c" ] );
86+
}
87+
88+
#[test]
89+
fn test_unterminated_quote()
90+
{
91+
let src = r#"a "b c"#;
92+
let iter = split()
93+
.src( src )
94+
.delimeter( " " )
95+
.quoting( true )
96+
.preserving_quoting( false )
97+
.perform();
98+
let splits : Vec<_> = iter.map( | e | e.string ).collect();
99+
assert_eq!( splits, vec![ "a", "b c" ] );
100+
}

0 commit comments

Comments
 (0)