summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-13 15:44:41 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-13 15:44:41 +0100
commit1d01b93f679bccf8f228616bcf0f0ebcdee64d98 (patch)
tree3fa476cf5f783fcbb22614e0b7b53cb25a398b91 /src
parent60154474ba1cf4a556bbed7f80ee0947c29dbca8 (diff)
Move comment tests to integration 🚚
Diffstat (limited to 'src')
-rw-r--r--src/eval/call.rs28
-rw-r--r--src/parse/tests.rs17
2 files changed, 19 insertions, 26 deletions
diff --git a/src/eval/call.rs b/src/eval/call.rs
index 186e7630..a2387a17 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<Value>,
- named: Vec<(Spanned<String>, Spanned<Value>)>,
+ /// The span of the whole argument list.
+ pub span: Span,
+ /// The positional arguments.
+ pub pos: SpanVec<Value>,
+ /// The named arguments.
+ pub named: Vec<(Spanned<String>, Spanned<Value>)>,
}
impl Args {
- /// Find the first convertible positional argument.
+ /// Find and remove the first convertible positional argument.
pub fn find<T>(&mut self, ctx: &mut EvalContext) -> Option<T>
where
T: Cast<Spanned<Value>>,
@@ -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<T>(&mut self, ctx: &mut EvalContext, what: &str) -> Option<T>
where
T: Cast<Spanned<Value>>,
@@ -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<T>
where
T: Cast<Spanned<Value>>,
@@ -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 9460db6b..2e7a2af3 100644
--- a/src/parse/tests.rs
+++ b/src/parse/tests.rs
@@ -218,23 +218,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.
t!("");