Skip to content

Commit 821d9b2

Browse files
committed
tests: add whitespace tests for vertical tab behavior
Add two small tests to highlight how vertical tab is handled differently. - vertical_tab_lexer.rs checks that the lexer treats vertical tab as whitespace - ascii_whitespace_excludes_vertical_tab.rs shows that split_ascii_whitespace does not split on it This helps document the difference between the Rust parser (which accepts vertical tab) and the standard library’s ASCII whitespace handling. See: rust-lang/rust-project-goals#53
1 parent bf4fbfb commit 821d9b2

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This test checks that split_ascii_whitespace does not split on a
2+
// vertical tab (\x0B). The standard library follows the WhatWG ASCII
3+
// whitespace definition, which does not include vertical tab.
4+
//
5+
// So in this case, "a\x0Bb" should stay as a single piece.
6+
//
7+
// See: https://github.com/rust-lang/rust-project-goals/issues/53
8+
9+
fn main() {
10+
let s = "a\x0Bb";
11+
12+
let parts: Vec<&str> = s.split_ascii_whitespace().collect();
13+
14+
assert_eq!(parts.len(), 1,
15+
"vertical tab should not be treated as ASCII whitespace");
16+
17+
let s2 = "a b";
18+
let parts2: Vec<&str> = s2.split_ascii_whitespace().collect();
19+
assert_eq!(parts2.len(), 2,
20+
"regular space should split correctly");
21+
22+
println!("All assertions passed.");
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This test checks that the Rust lexer treats a vertical tab (\x0B)
2+
// as whitespace. That matches how the language parses code, even though
3+
// the standard library's is_ascii_whitespace does not include it.
4+
//
5+
// See: https://github.com/rust-lang/rust-project-goals/issues/53
6+
7+
fn main() {
8+
let x = 5;
9+
let y = 10;
10+
let z = x + y;
11+
println!("{}", z);
12+
}

0 commit comments

Comments
 (0)