diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-08-16 14:23:13 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-08-16 14:38:30 +0200 |
| commit | 9f6137d8a829fe8f34554623495fa620252a0184 (patch) | |
| tree | da62c40caa247ac1825d335fde9350150c6604db /src/syntax/mod.rs | |
| parent | 84f30fb73518ca23cbc728b1bf414e80b344412a (diff) | |
Remove tuples and objects in favor of tables 🛢
This refactores the parser tests to make them more concise and flexible with regards to spans.
Diffstat (limited to 'src/syntax/mod.rs')
| -rw-r--r-- | src/syntax/mod.rs | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index fe0bf6b5..fdc105a3 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -1,9 +1,5 @@ //! Syntax trees, parsing and tokenization. -#[cfg(test)] -#[macro_use] -mod test; - pub mod decoration; pub mod expr; pub mod parsing; @@ -11,3 +7,60 @@ pub mod scope; pub mod span; pub mod tokens; pub mod tree; + +#[cfg(test)] +mod tests { + use std::fmt::Debug; + use crate::func::prelude::*; + use super::span; + + /// Assert that expected and found are equal, printing both and panicking + /// and the source of their test case if they aren't. + /// + /// When `cmp_spans` is false, spans are ignored. + pub fn check<T>(src: &str, exp: T, found: T, cmp_spans: bool) + where + T: Debug + PartialEq, + { + span::set_cmp(cmp_spans); + let equal = exp == found; + span::set_cmp(true); + + if !equal { + println!("source: {:?}", src); + if cmp_spans { + println!("expected: {:#?}", exp); + println!("found: {:#?}", found); + } else { + println!("expected: {:?}", exp); + println!("found: {:?}", found); + } + panic!("test failed"); + } + } + + pub fn s<T>(sl: usize, sc: usize, el: usize, ec: usize, v: T) -> Spanned<T> { + Spanned::new(v, Span::new(Pos::new(sl, sc), Pos::new(el, ec))) + } + + // Enables tests to optionally specify spans. + impl<T> From<T> for Spanned<T> { + fn from(t: T) -> Self { + Spanned::zero(t) + } + } + + pub fn debug_func(call: FuncCall, _: &ParseState) -> Pass<SyntaxNode> { + Pass::node(DebugNode(call), Feedback::new()) + } + + #[derive(Debug, Clone, PartialEq)] + pub struct DebugNode(pub FuncCall); + + #[async_trait(?Send)] + impl Layout for DebugNode { + async fn layout<'a>(&'a self, _: LayoutContext<'_>) -> Pass<Commands<'a>> { + unimplemented!() + } + } +} |
