Skip to content

Commit

Permalink
Implement < and >
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Sep 22, 2024
1 parent 40ff865 commit c2ab60f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/elements/expr/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,12 @@ impl ConditionalExpr {
Err(e) => return Err(e),
};

if op == "==" || op == "=" || op == "!=" {
if op == "==" || op == "=" || op == "!=" || op == "<" || op == ">" {
let ans = match op {
"==" | "=" => left == right,
"!=" => left != right,
">" => left > right,
"<" => left < right,
_ => false,
};

Expand Down
2 changes: 1 addition & 1 deletion src/feeder/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,6 @@ 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", "==", "=", "!=", "<", ">"])
}
}
3 changes: 3 additions & 0 deletions test/ok
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
../../../test/test_compound.bash
../../../test/test_compound.bash
../../../test/test_compound.bash
../../../test/test_compound.bash
../../../test/test_compound.bash
../../../test/test_compound.bash
5 changes: 4 additions & 1 deletion test/test_compound.bash
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,10 @@ res=$($com -c 'A=あいう ; [[ != $A ]]')
res=$($com -c '[[ aaa != ]]')
[ "$?" = "2" ] || err $LINENO

res=$($com -c '[[ == ]] && [[ = ]] && [[ != ]]')
$com -c '[[ == ]] && [[ = ]] && [[ != ]]'
[ "$?" = "0" ] || err $LINENO

$com -c '[[ abc > aaa ]] && [[ 0100 < 2 ]] && [[ ! abc > abc ]]'
[ "$?" = "0" ] || err $LINENO

# and or
Expand Down

0 comments on commit c2ab60f

Please sign in to comment.