@@ -323,6 +323,82 @@ def test(x, y) = x & y
323323 RUBY
324324 end
325325
326+ def test_opt_and_true_true
327+ assert_compiles 'true' , %q{
328+ def test(a, b) = a & b
329+ test(true, true)
330+ test(true, true)
331+ } , call_threshold : 2 , insns : [ :opt_and ]
332+ end
333+
334+ def test_opt_and_true_false
335+ assert_compiles 'false' , %q{
336+ def test(a, b) = a & b
337+ test(true, false)
338+ test(true, false)
339+ } , call_threshold : 2 , insns : [ :opt_and ]
340+ end
341+
342+ def test_opt_and_false_true
343+ assert_compiles 'false' , %q{
344+ def test(a, b) = a & b
345+ test(false, true)
346+ test(false, true)
347+ } , call_threshold : 2 , insns : [ :opt_and ]
348+ end
349+
350+ def test_opt_and_false_false
351+ assert_compiles 'false' , %q{
352+ def test(a, b) = a & b
353+ test(false, false)
354+ test(false, false)
355+ } , call_threshold : 2 , insns : [ :opt_and ]
356+ end
357+
358+ def test_opt_and_true_with_truthy
359+ assert_compiles 'true' , %q{
360+ def test(a, b) = a & b
361+ test(true, true)
362+ test(true, 1)
363+ } , call_threshold : 2 , insns : [ :opt_and ]
364+ end
365+
366+ def test_opt_and_true_with_falsey
367+ assert_compiles 'false' , %q{
368+ def test(a, b) = a & b
369+ test(true, true)
370+ test(true, nil)
371+ } , call_threshold : 2 , insns : [ :opt_and ]
372+ end
373+
374+ def test_opt_and_false_with_truthy
375+ assert_compiles 'false' , %q{
376+ def test(a, b) = a & b
377+ test(false, true)
378+ test(false, "hi")
379+ } , call_threshold : 2 , insns : [ :opt_and ]
380+ end
381+
382+ def test_opt_and_bool_fallthrough_to_integer
383+ assert_compiles '1' , %q{
384+ def test(a, b) = a & b
385+ test(true, false)
386+ test(true, true)
387+ test(3, 1)
388+ } , call_threshold : 2 , insns : [ :opt_and ]
389+ end
390+
391+ def test_opt_and_mixed_types_side_exit
392+ assert_compiles '[false, true, 1]' , %q{
393+ def test(a, b) = a & b
394+ test(true, true)
395+ r1 = test(true, false)
396+ r2 = test(true, 1)
397+ r3 = test(3, 1)
398+ [r1, r2, r3]
399+ } , call_threshold : 2 , insns : [ :opt_and ]
400+ end
401+
326402 def test_opt_or
327403 assert_compiles ( '[11, [3, 2, 1]]' , <<~RUBY , insns : [ :opt_or ] )
328404 def test(x, y) = x | y
0 commit comments