1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
fn test_BASH_BUILTIN_005_printf_format_specifiers() {
// DOCUMENTATION: printf format specifiers (POSIX)
//
// %s: String (default format)
// %d, %i: Signed decimal integer
// %u: Unsigned decimal integer
// %x, %X: Hexadecimal (lowercase/uppercase)
// %o: Octal
// %f: Floating point
// %e, %E: Scientific notation
// %g, %G: Shortest representation (f or e)
// %c: Single character
// %%: Literal percent sign
//
// INPUT (bash):
// printf 'String: %s\n' "text"
// printf 'Decimal: %d\n' 42
// printf 'Hex: %x\n' 255
// printf 'Float: %.2f\n' 3.14159
//
// RUST:
// println!("String: {}", "text");
// println!("Decimal: {}", 42);
// println!("Hex: {:x}", 255);
// println!("Float: {:.2}", 3.14159);
//
// PURIFIED (POSIX sh):
// printf 'String: %s\n' "text"
// printf 'Decimal: %d\n' 42
// printf 'Hex: %x\n' 255
// printf 'Float: %.2f\n' 3.14159
let format_specifiers = r#"
# String format
printf 'Name: %s\n' "Alice"
printf 'Path: %s\n' "/usr/local/bin"
# Integer formats
printf 'Decimal: %d\n' 42
printf 'Unsigned: %u\n' 100
printf 'Hex (lower): %x\n' 255
printf 'Hex (upper): %X\n' 255
printf 'Octal: %o\n' 64
# Floating point formats
printf 'Float: %f\n' 3.14159
printf 'Precision: %.2f\n' 3.14159
printf 'Scientific: %e\n' 1000.0
# Character and literal
printf 'Char: %c\n' "A"
printf 'Percent: %%\n'
# Multiple arguments
printf '%s: %d items\n' "Cart" 5
printf '%s %s %d\n' "User" "logged in at" 1630000000
"#;
let mut lexer = Lexer::new(format_specifiers);
match lexer.tokenize() {
Ok(tokens) => {
assert!(!tokens.is_empty(), "format specifiers should tokenize");
let _ = tokens;
}
Err(_) => {
// Parser may not fully support all format specifiers yet
}
}
}
#[test]
fn test_BASH_BUILTIN_005_printf_escape_sequences() {
// DOCUMENTATION: printf escape sequences (POSIX)
//
// \n: Newline
// \t: Tab
// \\: Backslash
// \': Single quote
// \": Double quote
// \r: Carriage return
// \a: Alert (bell)
// \b: Backspace
// \f: Form feed
// \v: Vertical tab
// \0NNN: Octal character code
// \xHH: Hexadecimal character code
//
// INPUT (bash):
// printf 'Line1\nLine2\n'
// printf 'Col1\tCol2\tCol3\n'
//
// RUST:
// println!("Line1\nLine2");
// println!("Col1\tCol2\tCol3");
//
// PURIFIED:
// printf 'Line1\nLine2\n'
// printf 'Col1\tCol2\tCol3\n'
let escape_sequences = r#"
# Newline
printf 'Line1\nLine2\nLine3\n'
# Tab
printf 'Col1\tCol2\tCol3\n'
# Backslash and quotes
printf 'Path: C:\\Users\\Alice\n'
printf 'Quote: \'single\' and "double"\n'
# Other escapes
printf 'Alert:\a\n'
printf 'Carriage return:\r\n'
# Multiple escapes in one format
printf 'Name:\t%s\nAge:\t%d\nCity:\t%s\n' "Alice" 30 "NYC"
"#;
let mut lexer = Lexer::new(escape_sequences);
match lexer.tokenize() {
Ok(tokens) => {
assert!(!tokens.is_empty(), "escape sequences should tokenize");
let _ = tokens;
}
Err(_) => {
// Parser may not fully support escape sequences yet
}
}
}