Skip to content

Commit

Permalink
test: Add test & example for prepare_stream (PRQL#4481)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored May 20, 2024
1 parent fa87900 commit ca327bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions prqlc/prqlc-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,33 @@ fn prepare_stream(
Stream::from_iter(eoi, tokens)
}

#[test]
fn test_prepare_stream() {
use insta::assert_yaml_snapshot;

let input = "from artists | filter name == 'John'";
let tokens = lex_source(input).unwrap();
let mut stream = prepare_stream(tokens.0.into_iter(), input, 0);
assert_yaml_snapshot!(stream.fetch_tokens().collect::<Vec<(TokenKind, ParserSpan)>>(), @r###"
---
- - Ident: from
- "0:0-4"
- - Ident: artists
- "0:5-12"
- - Control: "|"
- "0:13-14"
- - Ident: filter
- "0:15-21"
- - Ident: name
- "0:22-26"
- - Eq
- "0:27-29"
- - Literal:
String: John
- "0:30-36"
"###);
}

fn convert_lexer_error(source: &str, e: chumsky::error::Cheap<char>, source_id: u16) -> Error {
// We want to slice based on the chars, not the bytes, so can't just index
// into the str.
Expand Down
4 changes: 3 additions & 1 deletion prqlc/prqlc-parser/src/span.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::ops::{Add, Deref, DerefMut, Sub};

use serde::{Deserialize, Serialize};

use crate::Span;

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct ParserSpan(pub crate::Span);

impl Deref for ParserSpan {
Expand Down

0 comments on commit ca327bb

Please sign in to comment.