@@ -723,8 +723,13 @@ func TestIntegerDivisionAndModulo(t *testing.T) {
723723 def arithmetic
724724 {
725725 int_div: 7 / 2,
726+ neg_div_left: -7 / 2,
727+ neg_div_right: 7 / -2,
728+ neg_div_both: -7 / -2,
726729 float_div: 7.0 / 2,
727730 mod_chain: 10 / 2 % 3,
731+ neg_mod_left: -7 % 2,
732+ neg_mod_right: 7 % -2,
728733 gcd: gcd(54, 24),
729734 hailstone: hailstone(7)
730735 }
@@ -739,12 +744,18 @@ func TestIntegerDivisionAndModulo(t *testing.T) {
739744 if ! got ["int_div" ].Equal (NewInt (3 )) {
740745 t .Fatalf ("int_div mismatch: %v" , got ["int_div" ])
741746 }
747+ if ! got ["neg_div_left" ].Equal (NewInt (- 4 )) || ! got ["neg_div_right" ].Equal (NewInt (- 4 )) || ! got ["neg_div_both" ].Equal (NewInt (3 )) {
748+ t .Fatalf ("negative division mismatch: left=%v right=%v both=%v" , got ["neg_div_left" ], got ["neg_div_right" ], got ["neg_div_both" ])
749+ }
742750 if got ["float_div" ].Kind () != KindFloat || got ["float_div" ].Float () != 3.5 {
743751 t .Fatalf ("float_div mismatch: %v" , got ["float_div" ])
744752 }
745753 if ! got ["mod_chain" ].Equal (NewInt (2 )) {
746754 t .Fatalf ("mod_chain mismatch: %v" , got ["mod_chain" ])
747755 }
756+ if ! got ["neg_mod_left" ].Equal (NewInt (1 )) || ! got ["neg_mod_right" ].Equal (NewInt (- 1 )) {
757+ t .Fatalf ("negative modulo mismatch: left=%v right=%v" , got ["neg_mod_left" ], got ["neg_mod_right" ])
758+ }
748759 if ! got ["gcd" ].Equal (NewInt (6 )) {
749760 t .Fatalf ("gcd mismatch: %v" , got ["gcd" ])
750761 }
@@ -1134,6 +1145,16 @@ func TestLineTerminatedHeadersAndStatements(t *testing.T) {
11341145 end
11351146 end
11361147
1148+ def if_chain(values)
1149+ if values
1150+ .reverse
1151+ .include?(1)
1152+ "hit"
1153+ else
1154+ "miss"
1155+ end
1156+ end
1157+
11371158 def while_body
11381159 seen = []
11391160 i = 0
@@ -1191,6 +1212,12 @@ func TestLineTerminatedHeadersAndStatements(t *testing.T) {
11911212 t .Fatalf ("if_hash expected hash, got %v" , hashResult .Kind ())
11921213 }
11931214 compareHash (t , hashResult .Hash (), map [string ]Value {"a" : NewInt (1 )})
1215+ if got := callFunc (t , script , "if_chain" , []Value {NewArray ([]Value {NewInt (2 ), NewInt (1 )})}); ! got .Equal (NewString ("hit" )) {
1216+ t .Fatalf ("if_chain hit mismatch: %v" , got )
1217+ }
1218+ if got := callFunc (t , script , "if_chain" , []Value {NewArray ([]Value {NewInt (2 )})}); ! got .Equal (NewString ("miss" )) {
1219+ t .Fatalf ("if_chain miss mismatch: %v" , got )
1220+ }
11941221
11951222 compareArrays (t , callFunc (t , script , "while_body" , nil ), []Value {NewInt (0 )})
11961223 compareArrays (t , callFunc (t , script , "until_body" , nil ), []Value {NewInt (0 )})
0 commit comments