dynoxide-rs 3.0.0

An embeddable DynamoDB emulator backed by SQLite. Starts in under a millisecond, and is verified against real AWS by a public conformance suite.
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
//! Shared tokenizer for all DynamoDB expression types.

use std::fmt;

/// Byte-offset span of a token (or tokenizer error) into the original source string.
/// Spans are byte offsets, not char indices; UpdateExpression and ProjectionExpression
/// callers slice the original source via `&source[span.start..span.start + span.len]`
/// to build the AWS-style `near: "..."` window in error messages.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TokenSpan {
    pub start: usize,
    pub len: usize,
}

impl TokenSpan {
    pub fn new(start: usize, len: usize) -> Self {
        Self { start, len }
    }

    pub fn end(self) -> usize {
        self.start + self.len
    }
}

/// Structured tokenizer error carrying the byte position of the offending input,
/// so callers (UpdateExpression, ProjectionExpression) can build their own
/// `near: "..."` window from the original source rather than just a flat message.
#[derive(Debug, Clone)]
pub struct TokenizeError {
    pub message: String,
    pub position: usize,
    pub bad_len: usize,
}

impl fmt::Display for TokenizeError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.message)
    }
}

#[derive(Debug, Clone, PartialEq)]
pub enum Token {
    // Identifiers and references
    Identifier(String), // attribute name (e.g., `pk`, `myAttr`)
    NameRef(String),    // #name reference
    ValueRef(String),   // :value reference

    // Operators
    Eq,    // =
    Ne,    // <>
    Lt,    // <
    Le,    // <=
    Gt,    // >
    Ge,    // >=
    Plus,  // +
    Minus, // -

    // Keywords (case-insensitive)
    And,
    Or,
    Not,
    Between,
    In,
    Set,
    Remove,
    Add,
    Delete,

    // Punctuation
    LParen,   // (
    RParen,   // )
    LBracket, // [
    RBracket, // ]
    Dot,      // .
    Comma,    // ,

    // Literals
    Number(String), // numeric literal in brackets [0], [1]
}

impl fmt::Display for Token {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Token::Identifier(s) => write!(f, "{s}"),
            Token::NameRef(s) => write!(f, "{s}"),
            Token::ValueRef(s) => write!(f, "{s}"),
            Token::Eq => write!(f, "="),
            Token::Ne => write!(f, "<>"),
            Token::Lt => write!(f, "<"),
            Token::Le => write!(f, "<="),
            Token::Gt => write!(f, ">"),
            Token::Ge => write!(f, ">="),
            Token::Plus => write!(f, "+"),
            Token::Minus => write!(f, "-"),
            Token::And => write!(f, "AND"),
            Token::Or => write!(f, "OR"),
            Token::Not => write!(f, "NOT"),
            Token::Between => write!(f, "BETWEEN"),
            Token::In => write!(f, "IN"),
            Token::Set => write!(f, "SET"),
            Token::Remove => write!(f, "REMOVE"),
            Token::Add => write!(f, "ADD"),
            Token::Delete => write!(f, "DELETE"),
            Token::LParen => write!(f, "("),
            Token::RParen => write!(f, ")"),
            Token::LBracket => write!(f, "["),
            Token::RBracket => write!(f, "]"),
            Token::Dot => write!(f, "."),
            Token::Comma => write!(f, ","),
            Token::Number(n) => write!(f, "{n}"),
        }
    }
}

/// Tokenize a DynamoDB expression string, returning each token together with its
/// byte-offset span into the original input. Callers use the spans to build
/// `near: "..."` windows in syntax error messages.
pub fn tokenize(input: &str) -> Result<Vec<(Token, TokenSpan)>, TokenizeError> {
    let mut tokens: Vec<(Token, TokenSpan)> = Vec::new();
    let bytes = input.as_bytes();
    let mut i = 0;

    while i < bytes.len() {
        let start = i;
        // `i` is always on a character boundary: every arm below steps over
        // ASCII bytes or a whole character.
        let c = input[i..].chars().next().unwrap_or_default();

        // Skip ASCII whitespace. DynamoDB reads any other character outside a
        // string, a no-break space included, as a token it can't read
        // (eu-west-2 and us-east-1, 2026-10-09).
        if c.is_ascii() && c.is_whitespace() {
            i += 1;
            continue;
        }

        match c {
            // Attribute name reference: #name
            '#' => {
                i += 1;
                let name_start = i;
                while i < bytes.len() && is_name_byte(bytes[i]) {
                    i += 1;
                }
                if i == name_start {
                    return Err(TokenizeError {
                        message: "Syntax error; token: \"#\"".to_string(),
                        position: start,
                        bad_len: 1,
                    });
                }
                let name = &input[name_start..i];
                tokens.push((
                    Token::NameRef(format!("#{name}")),
                    TokenSpan::new(start, i - start),
                ));
            }

            // Attribute value reference: :value
            ':' => {
                i += 1;
                let name_start = i;
                while i < bytes.len() && is_name_byte(bytes[i]) {
                    i += 1;
                }
                if i == name_start {
                    return Err(TokenizeError {
                        message: "Syntax error; token: \":\"".to_string(),
                        position: start,
                        bad_len: 1,
                    });
                }
                let name = &input[name_start..i];
                tokens.push((
                    Token::ValueRef(format!(":{name}")),
                    TokenSpan::new(start, i - start),
                ));
            }

            // Comparison operators
            '<' => {
                i += 1;
                if i < bytes.len() && bytes[i] == b'>' {
                    i += 1;
                    tokens.push((Token::Ne, TokenSpan::new(start, 2)));
                } else if i < bytes.len() && bytes[i] == b'=' {
                    i += 1;
                    tokens.push((Token::Le, TokenSpan::new(start, 2)));
                } else {
                    tokens.push((Token::Lt, TokenSpan::new(start, 1)));
                }
            }

            '>' => {
                i += 1;
                if i < bytes.len() && bytes[i] == b'=' {
                    i += 1;
                    tokens.push((Token::Ge, TokenSpan::new(start, 2)));
                } else {
                    tokens.push((Token::Gt, TokenSpan::new(start, 1)));
                }
            }

            '=' => {
                i += 1;
                tokens.push((Token::Eq, TokenSpan::new(start, 1)));
            }
            '+' => {
                i += 1;
                tokens.push((Token::Plus, TokenSpan::new(start, 1)));
            }
            '-' => {
                i += 1;
                tokens.push((Token::Minus, TokenSpan::new(start, 1)));
            }

            // Punctuation
            '(' => {
                i += 1;
                tokens.push((Token::LParen, TokenSpan::new(start, 1)));
            }
            ')' => {
                i += 1;
                tokens.push((Token::RParen, TokenSpan::new(start, 1)));
            }
            '[' => {
                i += 1;
                tokens.push((Token::LBracket, TokenSpan::new(start, 1)));
                // Try to read a number inside brackets. A number starting with
                // 0 is the 0 alone, as DynamoDB reads it, so `l[00]` leaves a
                // second digit the tokenizer then refuses (`token: "0", near:
                // "00]"`, eu-west-2, 2026-10-09).
                let num_start = i;
                if i < bytes.len() && bytes[i] == b'0' {
                    i += 1;
                } else {
                    while i < bytes.len() && bytes[i].is_ascii_digit() {
                        i += 1;
                    }
                }
                if i > num_start {
                    let num = input[num_start..i].to_string();
                    tokens.push((Token::Number(num), TokenSpan::new(num_start, i - num_start)));
                }
            }
            ']' => {
                i += 1;
                tokens.push((Token::RBracket, TokenSpan::new(start, 1)));
            }
            '.' => {
                i += 1;
                tokens.push((Token::Dot, TokenSpan::new(start, 1)));
            }
            ',' => {
                i += 1;
                tokens.push((Token::Comma, TokenSpan::new(start, 1)));
            }

            // Identifiers and keywords
            c if is_ident_start(c) => {
                let ident_start = i;
                while i < bytes.len() && is_name_byte(bytes[i]) {
                    i += 1;
                }
                let word = &input[ident_start..i];
                let token = match word.to_uppercase().as_str() {
                    "AND" => Token::And,
                    "OR" => Token::Or,
                    "NOT" => Token::Not,
                    "BETWEEN" => Token::Between,
                    "IN" => Token::In,
                    "SET" => Token::Set,
                    "REMOVE" => Token::Remove,
                    "ADD" => Token::Add,
                    "DELETE" => Token::Delete,
                    _ => Token::Identifier(word.to_string()),
                };
                tokens.push((token, TokenSpan::new(ident_start, i - ident_start)));
            }

            c => {
                return Err(TokenizeError {
                    message: format!("Syntax error; token: \"{c}\""),
                    position: start,
                    bad_len: c.len_utf8(),
                });
            }
        }
    }

    Ok(tokens)
}

fn is_ident_start(c: char) -> bool {
    c.is_ascii_alphabetic() || c == '_'
}

fn is_name_byte(b: u8) -> bool {
    b.is_ascii_alphanumeric() || b == b'_'
}

/// A cursor over a token stream for parsing.
pub struct TokenStream {
    tokens: Vec<(Token, TokenSpan)>,
    pos: usize,
}

impl TokenStream {
    pub fn new(tokens: Vec<(Token, TokenSpan)>) -> Self {
        Self { tokens, pos: 0 }
    }

    pub fn peek(&self) -> Option<&Token> {
        self.tokens.get(self.pos).map(|(t, _)| t)
    }

    #[allow(clippy::should_implement_trait)]
    pub fn next(&mut self) -> Option<&Token> {
        let token = self.tokens.get(self.pos).map(|(t, _)| t);
        if token.is_some() {
            self.pos += 1;
        }
        token
    }

    /// Consume the next token if it is `expected`. On a mismatch the token is
    /// left in place, so the stream still points at it when the caller turns
    /// the failure into a `token: ..., near: ...` message.
    pub fn expect(&mut self, expected: &Token) -> Result<(), String> {
        match self.peek() {
            Some(t) if t == expected => {
                self.pos += 1;
                Ok(())
            }
            Some(t) => Err(format!("Expected {expected}, got {t}")),
            None => Err(format!("Expected {expected}, got end of expression")),
        }
    }

    /// The token `offset` places after the current one, without consuming.
    pub fn peek_at(&self, offset: usize) -> Option<&Token> {
        self.tokens.get(self.pos + offset).map(|(t, _)| t)
    }

    /// DynamoDB's syntax error for the token the stream is stopped at, or for
    /// the end of the expression when it has run out. See [`syntax_error_at`].
    pub fn syntax_error(&self, source: &str) -> String {
        let spans: Vec<TokenSpan> = self.tokens.iter().map(|(_, s)| *s).collect();
        syntax_error_at(source, &spans, self.pos)
    }

    pub fn at_end(&self) -> bool {
        self.pos >= self.tokens.len()
    }

    /// The index of the token the next call to `peek` or `next` returns.
    pub fn pos(&self) -> usize {
        self.pos
    }

    /// Set the stream position (used for backtracking).
    pub fn set_pos(&mut self, pos: usize) {
        self.pos = pos;
    }
}

/// DynamoDB's syntax error naming the token at `index` in `spans` (or the end
/// of the expression when `index` is past the last token):
/// `Syntax error; token: "x", near: ") x y"`.
///
/// `near` is the source from the start of the token before the offending one
/// to the end of the token after it, so it holds up to three tokens with their
/// original spacing. At the end of the expression the token is `<EOF>` and
/// `near` is the last token read. Captured in us-east-1 and eu-west-2,
/// 2026-10-09, across ConditionExpression, FilterExpression,
/// KeyConditionExpression and UpdateExpression.
///
/// An expression with no tokens at all, only whitespace, is the same error at
/// its end with the whitespace as sent for `near`: `near: "   "`, or a tab and
/// a newline as they were (captured eu-west-2 and us-east-1, 2026-10-10).
pub fn syntax_error_at(source: &str, spans: &[TokenSpan], index: usize) -> String {
    let Some(offending) = spans.get(index) else {
        let near = spans
            .last()
            .map_or(source, |last| &source[last.start..last.end()]);
        return format!(r#"Syntax error; token: "<EOF>", near: "{near}""#);
    };
    let start = if index > 0 {
        spans[index - 1].start
    } else {
        offending.start
    };
    let end = spans
        .get(index + 1)
        .map_or(offending.end(), |next| next.end());
    format!(
        r#"Syntax error; token: "{}", near: "{}""#,
        &source[offending.start..offending.end()],
        &source[start..end]
    )
}

/// DynamoDB's syntax error for a character the tokenizer can't read, such as a
/// stray `!`. The character counts as a token of its own, so `near` takes in
/// the token before it and the next token or unreadable character after it.
pub fn tokenizer_syntax_error(source: &str, err: &TokenizeError) -> String {
    let bad = TokenSpan::new(err.position, err.bad_len);
    // Everything before the first unreadable character tokenizes.
    let mut spans: Vec<TokenSpan> = tokenize(&source[..err.position])
        .map(|tokens| tokens.into_iter().map(|(_, s)| s).collect())
        .unwrap_or_default();
    let index = spans.len();
    spans.push(bad);
    if let Some(next) = next_lexeme(source, bad.end()) {
        spans.push(next);
    }
    syntax_error_at(source, &spans, index)
}

/// The span of the first token, or unreadable character, at or after `from`.
fn next_lexeme(source: &str, from: usize) -> Option<TokenSpan> {
    let rest = &source[from..];
    let skipped = rest.trim_start_matches(|c: char| c.is_ascii() && c.is_whitespace());
    let start = from + (rest.len() - skipped.len());
    if start >= source.len() {
        return None;
    }
    let offset = |s: TokenSpan| TokenSpan::new(start + s.start, s.len);
    match tokenize(&source[start..]) {
        Ok(tokens) => tokens.first().map(|(_, s)| offset(*s)),
        Err(e) if e.position == 0 => Some(TokenSpan::new(start, e.bad_len)),
        Err(e) => tokenize(&source[start..start + e.position])
            .ok()
            .and_then(|tokens| tokens.first().map(|(_, s)| offset(*s))),
    }
}

/// Detect redundant parentheses, matching DynamoDB's rule: a parenthesised
/// group whose entire content is itself a single parenthesised group, e.g.
/// `((expr))` or `((a)) AND (b)`. A single wrap like `(expr)` is fine, and a
/// wrap around a real combination like `((a) AND (b))` is fine. Shared by
/// condition/filter and key-condition parsing. Returns the raw reason; callers
/// add the `Invalid <X>Expression:` prefix.
pub fn check_redundant_parens(tokens: &[(Token, TokenSpan)]) -> Result<(), String> {
    let toks: Vec<&Token> = tokens.iter().map(|(t, _)| t).collect();
    let match_close = |open: usize| -> Option<usize> {
        let mut depth = 0;
        for (j, tok) in toks.iter().enumerate().skip(open) {
            match tok {
                Token::LParen => depth += 1,
                Token::RParen => {
                    depth -= 1;
                    if depth == 0 {
                        return Some(j);
                    }
                }
                _ => {}
            }
        }
        None
    };
    for i in 0..toks.len() {
        if !matches!(toks[i], Token::LParen) {
            continue;
        }
        let Some(outer_close) = match_close(i) else {
            continue;
        };
        // Redundant when the outer group's entire content is a single
        // parenthesised group: the token after the outer `(` is itself `(`
        // and its match sits immediately before the outer `)`.
        if matches!(toks.get(i + 1), Some(Token::LParen))
            && let Some(inner_close) = match_close(i + 1)
            && inner_close == outer_close - 1
        {
            return Err("The expression has redundant parentheses;".to_string());
        }
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    fn just_tokens(input: &str) -> Vec<Token> {
        tokenize(input)
            .unwrap()
            .into_iter()
            .map(|(t, _)| t)
            .collect()
    }

    #[test]
    fn test_tokenize_simple_condition() {
        assert_eq!(
            just_tokens("#status = :val"),
            vec![
                Token::NameRef("#status".into()),
                Token::Eq,
                Token::ValueRef(":val".into()),
            ]
        );
    }

    #[test]
    fn test_tokenize_comparison_operators() {
        let tokens = just_tokens("a < b");
        assert!(matches!(tokens[1], Token::Lt));

        let tokens = just_tokens("a <= b");
        assert!(matches!(tokens[1], Token::Le));

        let tokens = just_tokens("a > b");
        assert!(matches!(tokens[1], Token::Gt));

        let tokens = just_tokens("a >= b");
        assert!(matches!(tokens[1], Token::Ge));

        let tokens = just_tokens("a <> b");
        assert!(matches!(tokens[1], Token::Ne));
    }

    #[test]
    fn test_tokenize_keywords() {
        let tokens = just_tokens("a AND b OR NOT c BETWEEN d IN e");
        assert!(matches!(tokens[1], Token::And));
        assert!(matches!(tokens[3], Token::Or));
        assert!(matches!(tokens[4], Token::Not));
        assert!(matches!(tokens[6], Token::Between));
        assert!(matches!(tokens[8], Token::In));
    }

    #[test]
    fn test_tokenize_update_keywords() {
        let tokens = just_tokens("SET a = :v REMOVE b ADD c :d DELETE e :f");
        assert!(matches!(tokens[0], Token::Set));
        assert!(matches!(tokens[4], Token::Remove));
        assert!(matches!(tokens[6], Token::Add));
        assert!(matches!(tokens[9], Token::Delete));
    }

    #[test]
    fn test_tokenize_path_expression() {
        assert_eq!(
            just_tokens("a.b[0].c"),
            vec![
                Token::Identifier("a".into()),
                Token::Dot,
                Token::Identifier("b".into()),
                Token::LBracket,
                Token::Number("0".into()),
                Token::RBracket,
                Token::Dot,
                Token::Identifier("c".into()),
            ]
        );
    }

    #[test]
    fn test_tokenize_function_call() {
        assert_eq!(
            just_tokens("attribute_exists(#name)"),
            vec![
                Token::Identifier("attribute_exists".into()),
                Token::LParen,
                Token::NameRef("#name".into()),
                Token::RParen,
            ]
        );
    }

    #[test]
    fn test_tokenize_arithmetic() {
        let tokens = just_tokens("Price + :inc");
        assert!(matches!(tokens[1], Token::Plus));

        let tokens = just_tokens("Price - :dec");
        assert!(matches!(tokens[1], Token::Minus));
    }

    #[test]
    fn test_tokenize_case_insensitive_keywords() {
        let tokens = just_tokens("set AND or");
        assert!(matches!(tokens[0], Token::Set));
        assert!(matches!(tokens[1], Token::And));
        assert!(matches!(tokens[2], Token::Or));
    }

    #[test]
    fn test_tokenize_returns_byte_spans() {
        let tokens = tokenize("INVALID SYNTAX HERE").unwrap();
        assert_eq!(tokens.len(), 3);
        assert_eq!(tokens[0].1, TokenSpan::new(0, 7));
        assert_eq!(tokens[1].1, TokenSpan::new(8, 6));
        assert_eq!(tokens[2].1, TokenSpan::new(15, 4));
    }

    #[test]
    fn test_tokenize_error_carries_position() {
        let err = tokenize("!!!").unwrap_err();
        assert_eq!(err.message, "Syntax error; token: \"!\"");
        assert_eq!(err.position, 0);
    }

    fn syntax_error_for(source: &str, index: usize) -> String {
        let spans: Vec<TokenSpan> = tokenize(source)
            .unwrap()
            .into_iter()
            .map(|(_, s)| s)
            .collect();
        syntax_error_at(source, &spans, index)
    }

    #[test]
    fn test_syntax_error_near_takes_the_tokens_either_side() {
        assert_eq!(
            syntax_error_for("INVALID SYNTAX HERE", 0),
            r#"Syntax error; token: "INVALID", near: "INVALID SYNTAX""#
        );
        assert_eq!(
            syntax_error_for("attribute_exists(pk) x y", 4),
            r#"Syntax error; token: "x", near: ") x y""#
        );
        assert_eq!(
            syntax_error_for("a = :v)", 3),
            r#"Syntax error; token: ")", near: ":v)""#
        );
    }

    #[test]
    fn test_syntax_error_at_the_end_names_the_last_token() {
        assert_eq!(
            syntax_error_for("attribute_not_exists(", 2),
            r#"Syntax error; token: "<EOF>", near: "(""#
        );
    }

    #[test]
    fn test_tokenizer_syntax_error_treats_the_character_as_a_token() {
        let near = |source: &str| {
            let err = tokenize(source).unwrap_err();
            tokenizer_syntax_error(source, &err)
        };
        assert_eq!(near("!!!"), r#"Syntax error; token: "!", near: "!!""#);
        assert_eq!(
            near("a = :v !"),
            r#"Syntax error; token: "!", near: ":v !""#
        );
        assert_eq!(near("a ! b"), r#"Syntax error; token: "!", near: "a ! b""#);
    }

    /// A character outside ASCII is a token of its own, whatever its width,
    /// and so is a no-break space. Captured as ConditionExpressions in
    /// eu-west-2 and us-east-1, 2026-10-09.
    #[test]
    fn test_tokenizer_syntax_error_names_a_non_ascii_character() {
        let near = |source: &str| {
            let err = tokenize(source).unwrap_err();
            tokenizer_syntax_error(source, &err)
        };
        for c in ["é", "€", "\u{1F600}", "\u{a0}"] {
            for (source, window) in [
                (format!("{c}a = :v"), format!("{c}a")),
                (format!("a {c} = :v"), format!("a {c} =")),
                (format!("a = :v {c}"), format!(":v {c}")),
                (format!("a = :v{c}"), format!(":v{c}")),
                (format!("a{c} = :v"), format!("a{c} =")),
            ] {
                assert_eq!(
                    near(&source),
                    format!(r#"Syntax error; token: "{c}", near: "{window}""#),
                    "{source:?}"
                );
            }
        }
    }
}