From 1d01b93f679bccf8f228616bcf0f0ebcdee64d98 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 13 Jan 2021 15:44:41 +0100 Subject: [PATCH] =?UTF-8?q?Move=20comment=20tests=20to=20integration=20?= =?UTF-8?q?=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eval/call.rs | 28 +++++++++++++++++++--------- src/parse/tests.rs | 17 ----------------- tests/ref/comments.png | Bin 0 -> 1469 bytes tests/typ/comments.typ | 23 +++++++++++++++++++++++ tests/typeset.rs | 9 ++++++++- 5 files changed, 50 insertions(+), 27 deletions(-) create mode 100644 tests/ref/comments.png create mode 100644 tests/typ/comments.typ diff --git a/src/eval/call.rs b/src/eval/call.rs index 186e7630d..a2387a175 100644 --- a/src/eval/call.rs +++ b/src/eval/call.rs @@ -59,13 +59,16 @@ impl Eval for Spanned<&ExprArgs> { /// Evaluated arguments to a function. #[derive(Debug)] pub struct Args { - span: Span, - pos: SpanVec, - named: Vec<(Spanned, Spanned)>, + /// The span of the whole argument list. + pub span: Span, + /// The positional arguments. + pub pos: SpanVec, + /// The named arguments. + pub named: Vec<(Spanned, Spanned)>, } impl Args { - /// Find the first convertible positional argument. + /// Find and remove the first convertible positional argument. pub fn find(&mut self, ctx: &mut EvalContext) -> Option where T: Cast>, @@ -73,8 +76,8 @@ impl Args { self.pos.iter_mut().find_map(move |slot| try_cast(ctx, slot)) } - /// Find the first convertible positional argument, producing an error if - /// no match was found. + /// Find and remove the first convertible positional argument, producing an + /// error if no match was found. pub fn require(&mut self, ctx: &mut EvalContext, what: &str) -> Option where T: Cast>, @@ -86,7 +89,7 @@ impl Args { found } - /// Filter out all convertible positional arguments. + /// Filter out and remove all convertible positional arguments. pub fn filter<'a, T>( &'a mut self, ctx: &'a mut EvalContext, @@ -97,8 +100,8 @@ impl Args { self.pos.iter_mut().filter_map(move |slot| try_cast(ctx, slot)) } - /// Convert the value for the given named argument, producing an error if - /// the conversion fails. + /// Convert and remove the value for the given named argument, producing an + /// error if the conversion fails. pub fn get<'a, T>(&mut self, ctx: &mut EvalContext, name: &str) -> Option where T: Cast>, @@ -108,6 +111,13 @@ impl Args { cast(ctx, value) } + /// Drain all remainings arguments into an array and a dictionary. + pub fn drain(&mut self) -> (ValueArray, ValueDict) { + let array = self.pos.drain(..).map(|s| s.v).collect(); + let dict = self.named.drain(..).map(|(k, v)| (k.v, v.v)).collect(); + (array, dict) + } + /// Produce "unexpected argument" errors for all remaining arguments. pub fn finish(self, ctx: &mut EvalContext) { let a = self.pos.iter().map(|v| v.as_ref()); diff --git a/src/parse/tests.rs b/src/parse/tests.rs index 9460db6b0..2e7a2af36 100644 --- a/src/parse/tests.rs +++ b/src/parse/tests.rs @@ -217,23 +217,6 @@ macro_rules! Let { }; } -#[test] -fn test_parse_comments() { - // In markup. - t!("a// you\nb" Text("a"), Space, Text("b")); - t!("* // \n /*\n\n*/*" Strong, Space, Space, Strong); - - // In code. - t!("[v /*12pt*/]" Call!("v")); - t!("[v //\n]" Call!("v")); - t!("[v 12, /*\n*/ size: 14]" Call!("v", Args![Int(12), "size" => Int(14)])); - - // Error. - t!("a*/b" - nodes: [Text("a"), Text("b")], - errors: [S(1..3, "unexpected end of block comment")]); -} - #[test] fn test_parse_simple_nodes() { // Basics. diff --git a/tests/ref/comments.png b/tests/ref/comments.png new file mode 100644 index 0000000000000000000000000000000000000000..399d25a179cfd9ced39f00b865eec1f6fa83ca02 GIT binary patch literal 1469 zcmeAS@N?(olHy`uVBq!ia0y~yU}OPd4xj+T>txYu3=FI-o-U3d6}R5r`CGWyO61tX z%Zw!r)*GxF_zKvUFfV7m$oR6M#DUX`eToC8*2D7u0<$)np7gz8eLcJV`L1Si{G#1Ywv&md)xhn_@NB5 zrSBQV`}K~;DsDNxYOmu5fn$gM#0fMctlK<6@j%M-y$TGA&ra^OWV*Kt$jo)!VCJ5% zA^p8bT^9q(>jl1V84JFB`}nb}?pxOe&crR8$4YK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 +// Test interaction with words, spacing and expressions. + +A// you +B + +C/* + /* */ +*/D + +[dump /*1*/ a: "b" // +, 1] + +--- +// Test error. +// +// ref: false +// error: 3:7-3:9 unexpected end of block comment + +// No start of block comment. +/* */ */ + +// Unterminated block comment is okay. +/* diff --git a/tests/typeset.rs b/tests/typeset.rs index 554c91497..f3c411519 100644 --- a/tests/typeset.rs +++ b/tests/typeset.rs @@ -15,7 +15,7 @@ use ttf_parser::OutlineBuilder; use typst::diag::{Diag, Feedback, Level, Pass}; use typst::env::{Env, ImageResource, ResourceLoader, SharedEnv}; -use typst::eval::State; +use typst::eval::{Args, EvalContext, State, Value, ValueFunc}; use typst::export::pdf; use typst::font::FontLoader; use typst::geom::{Length, Point, Sides, Size}; @@ -189,6 +189,13 @@ fn test_part(i: usize, src: &str, env: &SharedEnv) -> (bool, Vec) { state.page.size = Size::uniform(Length::pt(120.0)); state.page.margins = Sides::uniform(Some(Length::pt(10.0).into())); + pub fn dump(_: &mut EvalContext, args: &mut Args) -> Value { + let (array, dict) = args.drain(); + Value::Array(vec![Value::Array(array), Value::Dict(dict)]) + } + + Rc::make_mut(&mut state.scope).set("dump", ValueFunc::new("dump", dump)); + let Pass { output: mut frames, feedback: Feedback { mut diags, .. },