Skip to content

Commit ff3e210

Browse files
committed
Fix arithmetic op bug
1 parent c4f4c40 commit ff3e210

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

src/elements/arithmetic_expr/elem.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,34 @@ pub enum Elem {
1515
LeftParen,
1616
RightParen,
1717
Increment(i64), //pre increment
18-
// OutputFormat(String, bool), // ex.: [#8] -> Base("8", false), [##16] -> Base("16", true)
1918
}
2019

2120
pub fn op_order(op: &Elem) -> u8 {
2221
match op {
23-
Elem::Increment(_) => 14,
22+
Elem::Increment(_) => 20,
2423
Elem::UnaryOp(s) => {
2524
match s.as_str() {
26-
"-" | "+" => 14,
27-
_ => 13,
25+
"-" | "+" => 19,
26+
_ => 18,
2827
}
2928
},
3029
Elem::BinaryOp(s) => {
3130
match s.as_str() {
32-
"**" => 12,
33-
"*" | "/" | "%" => 11,
34-
"+" | "-" => 10,
35-
"<<" | ">>" => 9,
36-
"<=" | ">=" | ">" | "<" => 8,
37-
"==" | "!=" => 7,
38-
"&" => 6,
39-
"^" => 5,
40-
"|" => 4,
31+
"**" => 17,
32+
"*" | "/" | "%" => 16,
33+
"+" | "-" => 15,
34+
"<<" | ">>" => 14,
35+
"<=" | ">=" | ">" | "<" => 13,
36+
"==" | "!=" => 12,
37+
"&" => 11,
38+
"^" => 10,
39+
"|" => 9,
40+
"&&" => 8,
41+
"||" => 7,
4142
_ => 2,
4243
}
4344
},
44-
Elem::Ternary(_, _) => 1,
45+
Elem::Ternary(_, _) => 3,
4546
_ => 0,
4647
}
4748
}

test/error

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
../test/test_compound.bash
2+
../test/test_others.bash
3+
../test/test_others.bash

test/ok

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
../test/test_compound.bash
88
../test/test_compound.bash
99
../test/test_compound.bash
10+
../../test/test_others.bash

test/test_others.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@ res=$($com <<< 'echo $((123 && -1 )) $(( 0 && 10 )) $(( 0 || -1 || 0 )) $(( 0 ||
760760
res=$($com<<<'echo $((123&&-1))$((0&&10))$((0||-1||0))$((0||0))$((0&&0))')
761761
[ "$res" == "10100" ] || err $LINENO
762762

763+
res=$($com<<<'echo $((A=1 && B=1))')
764+
[ "$?" == "1" ] || err $LINENO
765+
[ "$res" == "" ] || err $LINENO
766+
763767
res=$($com <<< 'echo $(( 1? 20 : 30 )) $(( -5 + 5 ? 100 : 200))')
764768
[ "$res" == "20 200" ] || err $LINENO
765769

0 commit comments

Comments
 (0)