rlsp-yaml 0.4.3

A fast, lightweight YAML language server
Documentation
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
// SPDX-License-Identifier: MIT

use std::collections::HashMap;
use tower_lsp::lsp_types::{Position, Range, TextEdit, Url, WorkspaceEdit};

/// A token found in the text: either an anchor (`&name`) or an alias (`*name`).
#[derive(Debug, Clone)]
struct Token {
    name: String,
    line: u32,
    start_col: u32,
    end_col: u32,
    is_anchor: bool,
}

/// Prepare rename: validates cursor is on anchor/alias, returns name range.
///
/// Returns `None` if the cursor is not on an anchor or alias, the position
/// is out of bounds, or the document is empty.
#[must_use]
pub fn prepare_rename(text: &str, position: Position) -> Option<Range> {
    let lines: Vec<&str> = text.lines().collect();
    let line_idx = position.line as usize;
    let col_idx = position.character as usize;

    let line = lines.get(line_idx)?;
    if col_idx > line.len() {
        return None;
    }

    let doc_range = document_range_for_line(&lines, line_idx);
    let tokens = scan_tokens(&lines, doc_range.0, doc_range.1);

    // Find the token at the cursor position (anchor or alias)
    let token = tokens.iter().find(|t| {
        t.line == position.line && col_idx >= t.start_col as usize && col_idx < t.end_col as usize
    })?;

    Some(Range::new(
        Position::new(token.line, token.start_col),
        Position::new(token.line, token.end_col),
    ))
}

/// Rename: returns edits for all occurrences of anchor and aliases.
///
/// Returns `None` if the cursor is not on an anchor or alias, the new name
/// is invalid, the position is out of bounds, or the document is empty.
#[must_use]
pub fn rename(text: &str, uri: &Url, position: Position, new_name: &str) -> Option<WorkspaceEdit> {
    // Validate new_name first
    if !is_valid_anchor_name(new_name) {
        return None;
    }

    let lines: Vec<&str> = text.lines().collect();
    let line_idx = position.line as usize;
    let col_idx = position.character as usize;

    let line = lines.get(line_idx)?;
    if col_idx > line.len() {
        return None;
    }

    let doc_range = document_range_for_line(&lines, line_idx);
    let tokens = scan_tokens(&lines, doc_range.0, doc_range.1);

    // Find the token at the cursor position (anchor or alias)
    let cursor_token = tokens.iter().find(|t| {
        t.line == position.line && col_idx >= t.start_col as usize && col_idx < t.end_col as usize
    })?;

    let name = &cursor_token.name;

    // Collect all edits for this name (anchor + all aliases)
    let edits: Vec<TextEdit> = tokens
        .iter()
        .filter(|t| t.name == *name)
        .map(|t| {
            let prefix = if t.is_anchor { "&" } else { "*" };
            TextEdit {
                range: Range::new(
                    Position::new(t.line, t.start_col),
                    Position::new(t.line, t.end_col),
                ),
                new_text: format!("{prefix}{new_name}"),
            }
        })
        .collect();

    let mut changes = HashMap::new();
    changes.insert(uri.clone(), edits);

    Some(WorkspaceEdit {
        changes: Some(changes),
        ..WorkspaceEdit::default()
    })
}

/// Determine the document boundaries for the YAML document containing the
/// given line. Returns `(start_line, end_line)` where end is exclusive.
/// Documents are separated by `---`.
fn document_range_for_line(lines: &[&str], line_idx: usize) -> (usize, usize) {
    let mut start = 0;
    let end = lines.len();

    // Walk backwards to find the start of the current document
    for i in (0..=line_idx).rev() {
        let trimmed = lines.get(i).map_or("", |l| l.trim());
        if trimmed == "---" && i < line_idx {
            start = i + 1;
            break;
        }
    }

    // Walk forward to find the end of the current document
    for i in (line_idx + 1)..end {
        let trimmed = lines.get(i).map_or("", |l| l.trim());
        if trimmed == "---" {
            return (start, i);
        }
    }

    (start, end)
}

/// Scan lines for anchor (`&name`) and alias (`*name`) tokens within the
/// given line range. Skips comment lines.
fn scan_tokens(lines: &[&str], start_line: usize, end_line: usize) -> Vec<Token> {
    let mut tokens = Vec::new();

    for line_idx in start_line..end_line {
        let Some(line) = lines.get(line_idx) else {
            continue;
        };

        let trimmed = line.trim();

        // Skip comment lines
        if trimmed.starts_with('#') {
            continue;
        }

        #[allow(clippy::cast_possible_truncation)]
        let line_num = line_idx as u32;

        let mut chars = line.char_indices().peekable();
        while let Some((i, ch)) = chars.next() {
            if ch == '&' || ch == '*' {
                let is_anchor = ch == '&';

                // Check if followed by a valid anchor name character
                let name_start = i + 1;
                let mut name_end = name_start;

                while let Some(&(j, next_ch)) = chars.peek() {
                    if is_anchor_name_char(next_ch) {
                        name_end = j + next_ch.len_utf8();
                        chars.next();
                    } else {
                        break;
                    }
                }

                // Must have at least one name character
                if name_end > name_start {
                    #[allow(clippy::cast_possible_truncation)]
                    tokens.push(Token {
                        name: line[name_start..name_end].to_string(),
                        line: line_num,
                        start_col: i as u32,
                        end_col: name_end as u32,
                        is_anchor,
                    });
                }
            }
        }
    }

    tokens
}

/// Check if a character is valid in a YAML anchor/alias name.
/// Valid characters: alphanumeric, `-`, `_`, `.`
const fn is_anchor_name_char(ch: char) -> bool {
    ch.is_ascii_alphanumeric() || ch == '-' || ch == '_' || ch == '.'
}

/// Validate that a proposed new anchor name is valid.
fn is_valid_anchor_name(name: &str) -> bool {
    !name.is_empty() && name.len() <= 256 && name.chars().all(is_anchor_name_char)
}

#[cfg(test)]
#[allow(clippy::indexing_slicing, clippy::expect_used, clippy::unwrap_used)]
mod tests {
    use super::*;

    fn pos(line: u32, character: u32) -> Position {
        Position::new(line, character)
    }

    fn test_uri() -> Url {
        Url::parse("file:///test/doc.yaml").expect("valid test URI")
    }

    // ---- prepare_rename: Happy Path ----

    // Test 1
    #[test]
    fn should_return_range_when_cursor_on_anchor() {
        let text = "key: &myanchor value\n";
        let result = prepare_rename(text, pos(0, 6));

        let range = result.expect("should return a range");
        assert_eq!(range.start.line, 0);
        assert_eq!(range.start.character, 5, "&myanchor starts at column 5");
        assert_eq!(range.end.character, 14, "&myanchor ends at column 14");
    }

    // Test 2
    #[test]
    fn should_return_range_when_cursor_on_alias() {
        let text = "defaults: &defaults\n  key: val\nproduction:\n  <<: *defaults\n";
        let result = prepare_rename(text, pos(3, 7));

        let range = result.expect("should return a range");
        assert_eq!(range.start.line, 3);
        assert!(range.start.character <= 7);
        assert!(range.end.character > 7);
    }

    // Test 3
    #[test]
    fn should_return_range_when_cursor_at_end_of_anchor_name() {
        let text = "key: &anchor value\n";
        let result = prepare_rename(text, pos(0, 11));

        let range = result.expect("should return a range");
        assert_eq!(range.start.line, 0);
        assert_eq!(range.start.character, 5);
    }

    // ---- prepare_rename: Edge Cases ----

    // Test 4
    #[test]
    fn should_return_none_when_cursor_not_on_anchor_or_alias() {
        let text = "key: value\n";
        let result = prepare_rename(text, pos(0, 0));

        assert!(
            result.is_none(),
            "should return None when cursor is not on an anchor or alias"
        );
    }

    // Test 5
    #[test]
    fn should_return_none_for_empty_document() {
        let text = "";
        let result = prepare_rename(text, pos(0, 0));

        assert!(result.is_none(), "should return None for empty document");
    }

    // Test 6
    #[test]
    fn should_return_none_for_position_beyond_document_lines() {
        let text = "key: &anchor value\n";
        let result = prepare_rename(text, pos(10, 0));

        assert!(
            result.is_none(),
            "should return None for position beyond document lines"
        );
    }

    // Test 7
    #[test]
    fn should_return_none_for_position_beyond_line_length() {
        let text = "key: &anchor value\n";
        let result = prepare_rename(text, pos(0, 100));

        assert!(
            result.is_none(),
            "should return None for position beyond line length"
        );
    }

    // Test 8
    #[test]
    fn should_return_none_for_anchor_in_comment() {
        let text = "# &fake\nkey: value\n";
        let result = prepare_rename(text, pos(0, 2));

        assert!(result.is_none(), "should return None for anchor in comment");
    }

    // ---- rename: Happy Path ----

    // Test 9
    #[test]
    fn should_rename_anchor_and_single_alias() {
        let text = "defaults: &old\n  key: val\nproduction:\n  <<: *old\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 10), "new");

        let edit = result.expect("should return WorkspaceEdit");
        let changes = edit.changes.expect("should have changes");
        let edits = changes.get(&uri).expect("should have edits for uri");
        assert_eq!(edits.len(), 2, "should have 2 edits (anchor + alias)");
    }

    // Test 10
    #[test]
    fn should_rename_anchor_and_multiple_aliases() {
        let text = "defaults: &shared\n  key: val\ndev:\n  <<: *shared\nprod:\n  <<: *shared\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 10), "common");

        let edit = result.expect("should return WorkspaceEdit");
        let changes = edit.changes.expect("should have changes");
        let edits = changes.get(&uri).expect("should have edits for uri");
        assert_eq!(edits.len(), 3, "should have 3 edits (1 anchor + 2 aliases)");
    }

    // Test 11
    #[test]
    fn should_rename_when_cursor_on_alias() {
        let text = "defaults: &old\n  key: val\nproduction:\n  <<: *old\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(3, 7), "new");

        let edit = result.expect("should return WorkspaceEdit");
        let changes = edit.changes.expect("should have changes");
        let edits = changes.get(&uri).expect("should have edits for uri");
        assert_eq!(edits.len(), 2, "should have 2 edits (anchor + alias)");
    }

    // Test 12
    #[test]
    fn should_rename_anchor_with_no_aliases() {
        let text = "key: &lonely value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "orphan");

        let edit = result.expect("should return WorkspaceEdit");
        let changes = edit.changes.expect("should have changes");
        let edits = changes.get(&uri).expect("should have edits for uri");
        assert_eq!(edits.len(), 1, "should have 1 edit (just the anchor)");
    }

    // ---- rename: Multi-Document Boundaries ----

    // Test 13
    #[test]
    fn should_not_rename_across_document_boundaries() {
        let text = "doc1: &name\n  ref: *name\n---\ndoc2: &name\n  ref: *name\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 6), "renamed");

        let edit = result.expect("should return WorkspaceEdit");
        let changes = edit.changes.expect("should have changes");
        let edits = changes.get(&uri).expect("should have edits for uri");
        assert_eq!(
            edits.len(),
            2,
            "should have only 2 edits (anchor and alias in doc1 only)"
        );
    }

    // Test 14
    #[test]
    fn should_rename_within_second_document() {
        let text = "doc1: &name\n---\ndoc2: &name\n  ref: *name\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(2, 6), "other");

        let edit = result.expect("should return WorkspaceEdit");
        let changes = edit.changes.expect("should have changes");
        let edits = changes.get(&uri).expect("should have edits for uri");
        assert_eq!(
            edits.len(),
            2,
            "should have 2 edits (only doc2's anchor and alias)"
        );
    }

    // ---- rename: Invalid Position Cases ----

    // Test 15
    #[test]
    fn rename_should_return_none_when_cursor_not_on_anchor_or_alias() {
        let text = "key: value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 0), "anything");

        assert!(
            result.is_none(),
            "should return None when cursor is not on an anchor or alias"
        );
    }

    // Test 16
    #[test]
    fn rename_should_return_none_for_empty_document() {
        let text = "";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 0), "anything");

        assert!(result.is_none(), "should return None for empty document");
    }

    // Test 17
    #[test]
    fn rename_should_return_none_for_position_beyond_document_lines() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(10, 0), "anything");

        assert!(
            result.is_none(),
            "should return None for position beyond document lines"
        );
    }

    // Test 18
    #[test]
    fn rename_should_return_none_for_position_beyond_line_length() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 100), "anything");

        assert!(
            result.is_none(),
            "should return None for position beyond line length"
        );
    }

    // ---- rename: Invalid new_name Validation (Security Cases) ----

    // Test 19
    #[test]
    fn should_reject_empty_new_name() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "");

        assert!(result.is_none(), "should return None for empty new_name");
    }

    // Test 20
    #[test]
    fn should_reject_new_name_with_spaces() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "has space");

        assert!(
            result.is_none(),
            "should return None for new_name with spaces"
        );
    }

    // Test 21
    #[test]
    fn should_reject_new_name_with_open_bracket() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "bad[name");

        assert!(result.is_none(), "should return None for new_name with [");
    }

    // Test 22
    #[test]
    fn should_reject_new_name_with_close_bracket() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "bad]name");

        assert!(result.is_none(), "should return None for new_name with ]");
    }

    // Test 23
    #[test]
    fn should_reject_new_name_with_open_brace() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "bad{name");

        assert!(result.is_none(), "should return None for new_name with {{");
    }

    // Test 24
    #[test]
    fn should_reject_new_name_with_close_brace() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "bad}name");

        assert!(result.is_none(), "should return None for new_name with }}");
    }

    // Test 25
    #[test]
    fn should_reject_new_name_with_colon() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "bad:name");

        assert!(result.is_none(), "should return None for new_name with :");
    }

    // Test 26
    #[test]
    fn should_reject_new_name_with_comma() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "bad,name");

        assert!(result.is_none(), "should return None for new_name with ,");
    }

    // Test 27
    #[test]
    fn should_accept_new_name_with_hyphen() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "valid-name");

        assert!(result.is_some(), "should accept new_name with hyphen");
    }

    // Test 28
    #[test]
    fn should_accept_new_name_with_underscore() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "valid_name");

        assert!(result.is_some(), "should accept new_name with underscore");
    }

    // Test 29
    #[test]
    fn should_accept_new_name_with_dot() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "valid.name");

        assert!(result.is_some(), "should accept new_name with dot");
    }

    // ---- rename: Edit Content Verification ----

    // Test 30
    #[test]
    fn should_produce_correct_edit_ranges() {
        let text = "key: &old value\nref: *old\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "new");

        let edit = result.expect("should return WorkspaceEdit");
        let changes = edit.changes.expect("should have changes");
        let edits = changes.get(&uri).expect("should have edits for uri");
        assert_eq!(edits.len(), 2);

        // Check first edit (anchor)
        assert_eq!(edits[0].range.start.line, 0);
        assert_eq!(edits[0].range.start.character, 5);
        assert_eq!(edits[0].range.end.line, 0);
        assert_eq!(edits[0].range.end.character, 9);
        assert_eq!(edits[0].new_text, "&new");

        // Check second edit (alias)
        assert_eq!(edits[1].range.start.line, 1);
        assert_eq!(edits[1].range.start.character, 5);
        assert_eq!(edits[1].range.end.line, 1);
        assert_eq!(edits[1].range.end.character, 9);
        assert_eq!(edits[1].new_text, "*new");
    }

    // ---- Additional Invalid new_name Tests (Security) ----

    // Test 36
    #[test]
    fn should_reject_new_name_with_whitespace_only() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "   ");

        assert!(
            result.is_none(),
            "should return None for whitespace-only new_name"
        );
    }

    // Test 37
    #[test]
    fn should_reject_new_name_with_hash() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "name#comment");

        assert!(result.is_none(), "should return None for new_name with #");
    }

    // Test 38
    #[test]
    fn should_reject_new_name_with_newline() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "name\n");

        assert!(
            result.is_none(),
            "should return None for new_name with newline"
        );
    }

    // Test 39
    #[test]
    fn should_reject_new_name_with_tab() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "name\t");

        assert!(result.is_none(), "should return None for new_name with tab");
    }

    // Test 40
    #[test]
    fn should_reject_new_name_with_carriage_return() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "name\r");

        assert!(
            result.is_none(),
            "should return None for new_name with carriage return"
        );
    }

    // Test 41
    #[test]
    fn should_reject_new_name_with_ampersand() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "name&other");

        assert!(result.is_none(), "should return None for new_name with &");
    }

    // Test 42
    #[test]
    fn should_reject_new_name_with_asterisk() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "name*other");

        assert!(result.is_none(), "should return None for new_name with *");
    }

    // Test 43
    #[test]
    fn should_reject_new_name_with_exclamation() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "name!tag");

        assert!(result.is_none(), "should return None for new_name with !");
    }

    // Test 44
    #[test]
    fn should_accept_new_name_starting_with_digit() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let result = rename(text, &uri, pos(0, 5), "123abc");

        assert!(
            result.is_some(),
            "should accept new_name starting with digit"
        );
    }

    // Test 45
    #[test]
    fn should_reject_new_name_exceeding_max_length() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let long_name = "a".repeat(257);
        let result = rename(text, &uri, pos(0, 5), &long_name);
        assert!(
            result.is_none(),
            "name longer than 256 chars must be rejected"
        );
    }

    #[test]
    fn should_accept_new_name_at_exactly_max_length() {
        let text = "key: &anchor value\n";
        let uri = test_uri();
        let max_name = "a".repeat(256);
        let result = rename(text, &uri, pos(0, 5), &max_name);
        assert!(
            result.is_some(),
            "name of exactly 256 chars must be accepted"
        );
    }

    // ---- Additional Position Edge Cases ----

    // Test 46
    #[test]
    fn should_return_none_for_cursor_at_exact_end_of_line() {
        let text = "key: &anchor\n";
        let result = prepare_rename(text, pos(0, 12));

        assert!(
            result.is_none(),
            "should return None for cursor one past last char"
        );
    }

    // Test 47
    #[test]
    fn should_handle_cursor_at_document_end() {
        let text = "key: &anchor";
        let result = prepare_rename(text, pos(0, 12));

        assert!(
            result.is_none(),
            "should return None for cursor at/past end"
        );
    }
}