summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2020-01-19 21:50:20 +0100
committerLaurenz <laurmaedje@gmail.com>2020-01-19 21:53:24 +0100
commit95e6b078fecddeaa3d6f2c920b617201b74bf01e (patch)
tree1c03b0b16d614a5a2350dccf71a1eb1e34f9a812 /tests
parent277f2d2176f5e98305870f90b16af3feae1bb3d1 (diff)
Move to non-fatal errors 🪂 [WIP]
- Dynamic models instead of SyntaxTrees - No more ParseResult/LayoutResult - Errors and Decorations which are propagated to parent contexts - Models are finally clonable
Diffstat (limited to 'tests')
-rw-r--r--tests/src/layouter.rs49
-rw-r--r--tests/src/parser.rs38
-rw-r--r--tests/src/spanless.rs12
3 files changed, 35 insertions, 64 deletions
diff --git a/tests/src/layouter.rs b/tests/src/layouter.rs
index fa0c631a..eeca1a1b 100644
--- a/tests/src/layouter.rs
+++ b/tests/src/layouter.rs
@@ -76,10 +76,7 @@ fn test(name: &str, src: &str) -> DynResult<()> {
let font_paths = provider.paths();
typesetter.add_font_provider(provider);
- let layouts = match compile(&typesetter, src) {
- Some(layouts) => layouts,
- None => return Ok(()),
- };
+ let layouts = compile(&typesetter, src);
// Compute the font's paths.
let mut fonts = HashMap::new();
@@ -122,40 +119,32 @@ fn test(name: &str, src: &str) -> DynResult<()> {
}
/// Compile the source code with the typesetter.
-fn compile(typesetter: &Typesetter, src: &str) -> Option<MultiLayout> {
+fn compile(typesetter: &Typesetter, src: &str) -> MultiLayout {
#[cfg(not(debug_assertions))] {
use std::time::Instant;
// Warmup.
let warmup_start = Instant::now();
- let is_ok = block_on(typesetter.typeset(&src)).is_ok();
+ block_on(typesetter.typeset(&src));
let warmup_end = Instant::now();
- // Only continue if the typesetting was successful.
- if is_ok {
- let start = Instant::now();
- let tree = typesetter.parse(&src).unwrap();
- let mid = Instant::now();
- block_on(typesetter.layout(&tree)).unwrap();
- let end = Instant::now();
-
- println!(" - cold start: {:?}", warmup_end - warmup_start);
- println!(" - warmed up: {:?}", end - start);
- println!(" - parsing: {:?}", mid - start);
- println!(" - layouting: {:?}", end - mid);
- println!();
- }
- };
-
- match block_on(typesetter.typeset(&src)) {
- Ok(layouts) => Some(layouts),
- Err(err) => {
- println!(" - compilation failed: {}", err);
- #[cfg(not(debug_assertions))]
- println!();
- None
- }
+ let start = Instant::now();
+ let tree = typesetter.parse(&src).output;
+ let mid = Instant::now();
+ let layouts = block_on(typesetter.layout(&tree)).output;
+ let end = Instant::now();
+
+ println!(" - cold start: {:?}", warmup_end - warmup_start);
+ println!(" - warmed up: {:?}", end - start);
+ println!(" - parsing: {:?}", mid - start);
+ println!(" - layouting: {:?}", end - mid);
+ println!();
+
+ layouts
}
+
+ #[cfg(debug_assertions)]
+ block_on(typesetter.typeset(&src))
}
/// Command line options.
diff --git a/tests/src/parser.rs b/tests/src/parser.rs
index b2aa01da..550090a8 100644
--- a/tests/src/parser.rs
+++ b/tests/src/parser.rs
@@ -107,23 +107,22 @@ macro_rules! case {
(ps $($rest:tt)*) => (case!(@parse PartialEq::eq, $($rest)*));
(@parse $cmp:expr, $src:expr, [$($e:tt)*]) => ({
- let expected = SyntaxTree { nodes: list!(nodes [$($e)*]) };
+ let expected = SyntaxModel { nodes: list!(nodes [$($e)*]) };
let found = parse($src, ParseContext { scope: &scope() }).0;
($cmp(&found, &expected), expected, found)
});
(c $src:expr, [$($e:tt)*]) => ({
- let expected = Colorization { tokens: list!(colors [$($e)*]) };
+ let expected = Colorization { tokens: list!(decorations [$($e)*]) };
let found = parse($src, ParseContext { scope: &scope() }).1;
(expected == found, expected, found)
});
(e $src:expr, [$($e:tt)*]) => ({
- let errors = list!([$($e)*]).into_iter()
+ let expected = list!([$($e)*]).into_iter()
.map(|s| s.map(|m| m.to_string()))
.collect();
- let expected = ErrorMap { errors };
let found = parse($src, ParseContext { scope: &scope() }).2;
(expected == found, expected, found)
});
@@ -131,7 +130,7 @@ macro_rules! case {
/// A scope containing the `DebugFn` as a fallback.
fn scope() -> Scope {
- Scope::with_debug::<DebugFn>()
+ Scope::with_fallback::<DebugFn>()
}
/// Parses possibly-spanned lists of token or node expressions.
@@ -182,7 +181,7 @@ macro_rules! func {
$(positional = list!(expr [$($p)*]);)?
$(keyword = list!(expr [$($k)*]);)?
- Node::Func(FuncCall(Box::new(DebugFn {
+ Node::Model(Box::new(DebugFn {
header: FuncHeader {
name: zspan(Ident($name.to_string())),
args: FuncArgs {
@@ -191,10 +190,10 @@ macro_rules! func {
},
},
body: func!(@body $($b)*),
- })))
+ }))
});
- (@body Some($($b:tt)*)) => (Some(SyntaxTree { nodes: list!(nodes $($b)*) }));
+ (@body Some($($b:tt)*)) => (Some(SyntaxModel{ nodes: list!(nodes $($b)*) }));
(@body None) => (None);
}
@@ -270,27 +269,8 @@ mod cuts {
}
}
- pub mod colors {
- pub use typstc::syntax::ColorToken::{
- Comment as C,
- Bracket as B,
- FuncName as FN,
- Colon as CL,
- Key as K,
- Equals as EQ,
- Comma as CM,
- Paren as P,
- Brace as BR,
- ExprIdent as ID,
- ExprStr as STR,
- ExprNumber as NUM,
- ExprSize as SIZE,
- ExprBool as BOOL,
- Bold as BD,
- Italic as IT,
- Monospace as MS,
- Invalid as INV,
- };
+ pub mod decorations {
+ pub use typstc::syntax::Decoration::*;
}
pub mod expr {
diff --git a/tests/src/spanless.rs b/tests/src/spanless.rs
index fde5a2ed..87d3f39d 100644
--- a/tests/src/spanless.rs
+++ b/tests/src/spanless.rs
@@ -13,15 +13,17 @@ impl SpanlessEq<Vec<Spanned<Token<'_>>>> for Vec<Spanned<Token<'_>>> {
}
}
-impl SpanlessEq<SyntaxTree> for SyntaxTree {
- fn spanless_eq(&self, other: &SyntaxTree) -> bool {
- fn downcast(func: &FuncCall) -> &DebugFn {
- func.0.downcast::<DebugFn>().expect("not a debug fn")
+impl SpanlessEq<SyntaxModel> for SyntaxModel {
+ fn spanless_eq(&self, other: &SyntaxModel) -> bool {
+ fn downcast(func: &dyn Model) -> &DebugFn {
+ func.downcast::<DebugFn>().expect("not a debug fn")
}
self.nodes.len() == other.nodes.len()
&& self.nodes.iter().zip(&other.nodes).all(|(x, y)| match (&x.v, &y.v) {
- (Node::Func(a), Node::Func(b)) => downcast(a).spanless_eq(downcast(b)),
+ (Node::Model(a), Node::Model(b)) => {
+ downcast(a.as_ref()).spanless_eq(downcast(b.as_ref()))
+ }
(a, b) => a == b,
})
}