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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//! Tests for the low-allocation block string parsing optimization
//! in `GraphQLTokenKind::parse_string_value()` (specifically the
//! internal `parse_block_string()` function).
//!
//! ## Optimization summary
//!
//! `parse_block_string()` was rewritten to avoid per-line heap
//! allocations:
//!
//! 1. **`Cow::Borrowed` fast path** — when the block string has no
//! `\"""` escapes (the vast majority of cases), the content slice
//! borrows directly from the raw token text with zero allocation.
//!
//! 2. **Two-pass index tracking** — pass 1 computes the common
//! indent and finds the first/last non-blank line indices; pass 2
//! writes stripped lines directly into a single pre-allocated
//! `String`. This replaces the old `Vec<String>` +
//! `Vec::remove(0)` + `join()` approach.
//!
//! 3. **`is_graphql_blank()`** — uses byte-level checks for
//! `b' '` and `b'\t'` only (per the GraphQL spec definition of
//! `WhiteSpace`), avoiding Rust's Unicode-aware `trim()`.
//!
//! ## What these tests verify
//!
//! - Borrowed path (no escapes) produces correct results
//! - Owned path (`\"""` escapes) produces correct results
//! - Blank line trimming via index tracking
//! - Indentation edge cases (short lines, tabs, mixed)
//! - Line ending variants (`\r\n`, `\r`)
//! - Unicode content preservation through indent stripping
//!
//! Written by Claude Code, reviewed by a human.
use crateGraphQLTokenKind;
/// Helper: parse a block string and return the result string.
// =============================================================================
// Cow::Borrowed fast path (no escaped triple quotes)
// =============================================================================
/// Verifies that a simple block string with no escapes works
/// through the `Cow::Borrowed` path.
///
/// When the content between the triple quotes contains no `\"""`
/// sequences, `parse_block_string()` borrows the content slice
/// directly from the raw token text (zero allocation for the
/// content itself).
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that multi-line block strings with uniform indentation
/// work correctly through the Borrowed path.
///
/// Common indentation of 4 spaces should be stripped from all lines
/// after the first. Per GraphQL spec:
/// <https://spec.graphql.org/September2025/#BlockStringValue()>
///
/// Written by Claude Code, reviewed by a human.
// =============================================================================
// Escaped triple quote handling (Cow::Owned path)
// =============================================================================
/// Verifies that multiple `\"""` replacements produce `"""` in the
/// output.
///
/// When `\"""` is present, the content goes through
/// `Cow::Owned(content.replace(...))`, so this tests the owned
/// path.
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that `\"""` right after opening `"""` works.
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that `\"""` right before closing `"""` works.
///
/// Written by Claude Code, reviewed by a human.
// =============================================================================
// Blank line trimming (index tracking correctness)
// =============================================================================
/// Verifies that block strings with only whitespace/blank lines
/// return an empty string.
///
/// When all lines are blank, `first_non_blank` is `None` and the
/// function returns `Ok(String::new())` early. Per GraphQL spec,
/// leading and trailing blank lines are removed from block strings:
/// <https://spec.graphql.org/September2025/#BlockStringValue()>
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that leading and trailing blank lines are stripped,
/// leaving only the single content line.
///
/// Tests the `first_non_blank` and `last_non_blank` index tracking:
/// lines before `first_non_blank` and after `last_non_blank` are
/// skipped in pass 2. Per GraphQL spec, leading and trailing blank
/// lines are removed from block strings:
/// <https://spec.graphql.org/September2025/#BlockStringValue()>
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that content on the first line only (rest blank) works
/// correctly.
///
/// Tests the `first_non_blank == 0` path where the first line has
/// content and subsequent lines are blank.
///
/// Written by Claude Code, reviewed by a human.
// =============================================================================
// Indentation edge cases
// =============================================================================
/// Verifies that a line shorter than common indent is preserved
/// as-is without causing a negative slice.
///
/// The implementation guards with `line.len() >= common_indent`.
/// When the line is shorter (e.g., contains only a few spaces but
/// common indent is larger), it writes the entire line without
/// stripping.
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that tabs count as 1 character for common indent
/// calculation.
///
/// Per GraphQL spec, `WhiteSpace` is Tab (U+0009) and Space
/// (U+0020). A tab byte is 1 byte, so it contributes 1 to the
/// indent count.
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that mixed tabs and spaces are handled correctly in
/// indent calculation.
///
/// Tabs and spaces both count as 1 byte each in the byte-level
/// indent counting.
///
/// Written by Claude Code, reviewed by a human.
// =============================================================================
// Line ending variants
// =============================================================================
/// Verifies that `\r\n` line endings in block strings are handled
/// correctly.
///
/// `str::lines()` splits on both `\n` and `\r\n`, so CRLF should
/// be transparent to the indent/trim algorithm.
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that `\r`-only line endings in block strings are
/// handled correctly.
///
/// Per GraphQL spec, `\r` is a valid line terminator:
/// <https://spec.graphql.org/September2025/#sec-Language.Source-Text.Line-Terminators>
///
/// The block string value algorithm must split lines using the same
/// line terminators as the rest of the GraphQL spec — including
/// bare `\r`. When `\r` splits two lines, the block string value
/// coercion algorithm treats each as a separate line and joins
/// them with `\n` in the output (just like `\n`-separated lines).
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that block strings with bare `\r` line endings and
/// indentation are correctly processed by the two-pass algorithm.
///
/// This is a more thorough regression test for bare `\r` handling:
/// the common-indent computation (pass 1) and indent stripping
/// (pass 2) must both use `\r`-aware line splitting. With
/// `str::lines()`, bare `\r` would not split lines, causing the
/// indent algorithm to see a single long line instead of multiple
/// indented lines.
///
/// Written by Claude Code, reviewed by a human.
// =============================================================================
// Unicode content
// =============================================================================
/// Verifies that emoji and CJK characters in block string content
/// survive indent stripping.
///
/// Unicode content should pass through the two-pass algorithm
/// without corruption.
///
/// Written by Claude Code, reviewed by a human.
/// Verifies that non-ASCII characters in the whitespace region are
/// NOT considered whitespace by `is_graphql_blank()` and are NOT
/// stripped as indent.
///
/// `is_graphql_blank()` only considers bytes `b' '` and `b'\t'` as
/// whitespace. Non-ASCII bytes (>= 0x80) are not whitespace, so a
/// line starting with a multi-byte character has 0 indent.
///
/// Written by Claude Code, reviewed by a human.