From 5f79f153ba17dd0c3560c4bd66715f022e9ea119 Mon Sep 17 00:00:00 2001 From: Ph0enixKM Date: Fri, 31 Mar 2023 11:14:32 +0200 Subject: [PATCH 1/2] feat: add chain modifiers for function invocations --- src/modules/command/modifier.rs | 6 +++--- src/modules/condition/failed.rs | 4 +++- src/tests/validity.rs | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/modules/command/modifier.rs b/src/modules/command/modifier.rs index c82552fe..7bfae033 100644 --- a/src/modules/command/modifier.rs +++ b/src/modules/command/modifier.rs @@ -81,8 +81,8 @@ impl SyntaxModule for CommandModifier { swap(&mut self.is_unsafe, &mut meta.context.is_unsafe_ctx); if self.is_expr { syntax(meta, &mut *self.expr)?; - if !matches!(self.expr.value, Some(ExprType::CommandExpr(_))) { - return error!(meta, tok, format!("Expected command expression, after '{sequence}' command modifiers.")); + if !matches!(self.expr.value, Some(ExprType::CommandExpr(_) | ExprType::FunctionInvocation(_))) { + return error!(meta, tok, format!("Expected command or function call, after '{sequence}' command modifiers.")); } } else { match token(meta, "{") { @@ -104,7 +104,7 @@ impl SyntaxModule for CommandModifier { impl TranslateModule for CommandModifier { fn translate(&self, meta: &mut TranslateMetadata) -> String { - meta.silenced = true; + meta.silenced = self.is_silent; let result = if self.is_expr { return self.expr.translate(meta) } else { diff --git a/src/modules/condition/failed.rs b/src/modules/condition/failed.rs index 6b069eae..d5a74893 100644 --- a/src/modules/condition/failed.rs +++ b/src/modules/condition/failed.rs @@ -6,7 +6,7 @@ use crate::utils::metadata::{ParserMetadata, TranslateMetadata}; #[derive(Debug, Clone)] pub struct Failed { - is_parsed: bool, + pub is_parsed: bool, is_question_mark: bool, is_main: bool, block: Box @@ -27,6 +27,8 @@ impl SyntaxModule for Failed { fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult { let tok = meta.get_current_token(); if meta.context.is_unsafe_ctx { + self.is_main = meta.context.is_main_ctx; + self.is_parsed = true; return Ok(()); } if let Ok(_) = token(meta, "?") { diff --git a/src/tests/validity.rs b/src/tests/validity.rs index 6567594a..208a6ae5 100644 --- a/src/tests/validity.rs +++ b/src/tests/validity.rs @@ -779,4 +779,41 @@ fn chained_modifiers() { silent unsafe $non-existant command$ "; test_amber!(code, "Hello World"); +} + +#[test] +fn chained_modifiers_commands() { + let code = " + unsafe silent { + echo 'Hello World' + $non-existant command$ + } + // Test for expression + let _ = silent unsafe $non-existant command$ + // Test for single statement + silent unsafe $non-existant command$ + "; + test_amber!(code, "Hello World"); +} + +#[test] +fn chained_modifiers_functions() { + let code = " + fun foo(a) { + echo a + fail 1 + } + + fun bar() { + echo 'this should not appear' + } + + unsafe foo('one') + unsafe { + foo('two') + } + unsafe silent foo('this should not appear') + silent bar() + "; + test_amber!(code, "one\ntwo"); } \ No newline at end of file From e46c8b72d0f173550816237093b01061cb68a7cc Mon Sep 17 00:00:00 2001 From: Ph0enixKM Date: Fri, 31 Mar 2023 11:16:42 +0200 Subject: [PATCH 2/2] fix: remove performance tests --- .github/workflows/rust.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 363b0afd..51d6e5a9 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,5 +18,3 @@ jobs: run: cargo build --verbose - name: Run validity tests run: cargo test validity --verbose - - name: Run performance tests - run: cargo test performance --verbose