From 090f1c48b7a95c5847a8e53c4fd638ec1b2d72a2 Mon Sep 17 00:00:00 2001 From: Ryuichi Ueda Date: Sun, 22 Sep 2024 14:46:52 +0900 Subject: [PATCH] Enable to scan -eq, -ne, ... --- src/elements/expr/conditional.rs | 13 +++++++++++++ src/feeder/scanner.rs | 3 ++- test/error | 4 ---- test/ok | 10 ---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/elements/expr/conditional.rs b/src/elements/expr/conditional.rs index 97b488ef..1299ee3d 100644 --- a/src/elements/expr/conditional.rs +++ b/src/elements/expr/conditional.rs @@ -228,6 +228,19 @@ impl ConditionalExpr { return Ok(()); } + if op == "-eq" || op == "-ne" || op == "-lt" || op == "-le" || op == "-gt" || op == "-ge" { + let ans = match op { + "==" | "=" => left == right, + "!=" => left != right, + ">" => left > right, + "<" => left < right, + _ => false, + }; + + stack.push( Elem::Ans(ans) ); + return Ok(()); + } + let result = file_check::metadata_comp(&left, &right, op); stack.push( Elem::Ans(result) ); Ok(()) diff --git a/src/feeder/scanner.rs b/src/feeder/scanner.rs index 6b2e4582..b8002bff 100644 --- a/src/feeder/scanner.rs +++ b/src/feeder/scanner.rs @@ -295,6 +295,7 @@ impl Feeder { pub fn scanner_test_compare_op(&mut self, core: &mut ShellCore) -> usize { self.backslash_check_and_feed(vec!["-", "-e", "-n", "-o", "=", "!"], core); - self.scanner_one_of(&["-ef", "-nt", "-ot", "==", "=", "!=", "<", ">"]) + self.scanner_one_of(&["-ef", "-nt", "-ot", "==", "=", "!=", "<", ">", + "-eq", "-ne", "-lt", "-le", "-gt", "-ge"]) } } diff --git a/test/error b/test/error index 2b08543d..e69de29b 100644 --- a/test/error +++ b/test/error @@ -1,4 +0,0 @@ -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash diff --git a/test/ok b/test/ok index ae8dbb6f..bb403ea0 100644 --- a/test/ok +++ b/test/ok @@ -4,13 +4,3 @@ ./test_compound.bash ./test_others.bash ./test_job.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash -../../../test/test_compound.bash