aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-11-05 11:04:09 +0100
committerMartin Fischer <martin@push-f.com>2022-11-05 11:04:26 +0100
commit95c2572fc6339ddf20ce0ccbb7dcd9a73fc239cf (patch)
treea6fbf1c4857c740b3a668e5937329f7447b84e9a
parent95aa0534320a6b077a6063b612a099dd3d9d4145 (diff)
fix: anonymous template arguments having wrong indexlua
-rw-r--r--src/lua/template.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/lua/template.rs b/src/lua/template.rs
index 99dfded..a5666a6 100644
--- a/src/lua/template.rs
+++ b/src/lua/template.rs
@@ -304,7 +304,6 @@ pub fn parse_call_args(text: &str) -> (ModuleFunction, std::vec::IntoIter<(ArgIn
CallInnerToken::Pipe => {
args.push(parse_arg(&arg, &mut idx));
arg = String::new();
- idx += 1;
}
}
}
@@ -331,3 +330,19 @@ pub fn parse_call_args(text: &str) -> (ModuleFunction, std::vec::IntoIter<(ArgIn
args.into_iter(),
)
}
+
+#[cfg(test)]
+mod test_parse_call_args {
+ use crate::lua::template::ArgIndex;
+
+ #[test]
+ fn test_anon_args() {
+ let (modfun, mut args) = super::parse_call_args("test|foo|bar|baz");
+ assert_eq!(modfun.function_name, "test");
+ assert_eq!(modfun.module_name, "default");
+ assert!(matches!(args.next(), Some((ArgIndex::Num(1), s)) if s == "foo"));
+ assert!(matches!(args.next(), Some((ArgIndex::Num(2), s)) if s == "bar"));
+ assert!(matches!(args.next(), Some((ArgIndex::Num(3), s)) if s == "baz"));
+ assert!(matches!(args.next(), None));
+ }
+}