From ca327bbf681b73bf59ceef2732d0b15547c8aa14 Mon Sep 17 00:00:00 2001 From: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Date: Sun, 19 May 2024 18:25:10 -0700 Subject: [PATCH] test: Add test & example for `prepare_stream` (#4481) --- prqlc/prqlc-parser/src/lib.rs | 27 +++++++++++++++++++++++++++ prqlc/prqlc-parser/src/span.rs | 4 +++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/prqlc/prqlc-parser/src/lib.rs b/prqlc/prqlc-parser/src/lib.rs index 6a150c9f12cf..1a930961fe98 100644 --- a/prqlc/prqlc-parser/src/lib.rs +++ b/prqlc/prqlc-parser/src/lib.rs @@ -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::>(), @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, source_id: u16) -> Error { // We want to slice based on the chars, not the bytes, so can't just index // into the str. diff --git a/prqlc/prqlc-parser/src/span.rs b/prqlc/prqlc-parser/src/span.rs index 9e6368a1b369..11b109e0cb68 100644 --- a/prqlc/prqlc-parser/src/span.rs +++ b/prqlc/prqlc-parser/src/span.rs @@ -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 {