@@ -387,3 +387,121 @@ end
387
387
388
388
# issue #11675
389
389
@test repr (Nullable ()) == " Nullable{Union{}}()"
390
+
391
+ # #############################################################################
392
+ # #
393
+ # # Test standard lifting semantics
394
+ # #
395
+ # #############################################################################
396
+
397
+ types = [
398
+ Float16,
399
+ Float32,
400
+ Float64,
401
+ Int128,
402
+ Int16,
403
+ Int32,
404
+ Int64,
405
+ Int8,
406
+ UInt16,
407
+ UInt32,
408
+ UInt64,
409
+ UInt8,
410
+ ]
411
+
412
+ f (x:: Number ) = 5 * x
413
+ f (x:: Number , y:: Number ) = x + y
414
+ f (x:: Number , y:: Number , z:: Number ) = x + y * z
415
+
416
+ for T in types
417
+ a = one (T)
418
+ x = Nullable {T} (a)
419
+ y = Nullable {T} ()
420
+
421
+ U1 = Core. Inference. return_type (f, Tuple{T})
422
+ @test isequal (SQ. lift (f, x), Nullable (f (a)))
423
+ @test isequal (SQ. lift (f, y), Nullable {U1} ())
424
+
425
+ U2 = Core. Inference. return_type (f, Tuple{T, T})
426
+ @test isequal (SQ. lift (f, x, x), Nullable (f (a, a)))
427
+ @test isequal (SQ. lift (f, x, y), Nullable {U2} ())
428
+
429
+ U3 = Core. Inference. return_type (f, Tuple{T, T, T})
430
+ @test isequal (SQ. lift (f, x, x, x), Nullable (f (a, a, a)))
431
+ @test isequal (SQ. lift (f, x, y, x), Nullable {U3} ())
432
+ end
433
+
434
+ # #############################################################################
435
+ # #
436
+ # # Test non-standard lifting semantics
437
+ # #
438
+ # #############################################################################
439
+
440
+ # three-valued logic
441
+
442
+ # & truth table
443
+ v1 = SQ. lift (& , Nullable (true ), Nullable (true ))
444
+ v2 = SQ. lift (& , Nullable (true ), Nullable (false ))
445
+ v3 = SQ. lift (& , Nullable (true ), Nullable {Bool} ())
446
+ v4 = SQ. lift (& , Nullable (false ), Nullable (true ))
447
+ v5 = SQ. lift (& , Nullable (false ), Nullable (false ))
448
+ v6 = SQ. lift (& , Nullable (false ), Nullable {Bool} ())
449
+ v7 = SQ. lift (& , Nullable {Bool} (), Nullable (true ))
450
+ v8 = SQ. lift (& , Nullable {Bool} (), Nullable (false ))
451
+ v9 = SQ. lift (& , Nullable {Bool} (), Nullable {Bool} ())
452
+
453
+ @test isequal (v1, Nullable (true ))
454
+ @test isequal (v2, Nullable (false ))
455
+ @test isequal (v3, Nullable {Bool} ())
456
+ @test isequal (v4, Nullable (false ))
457
+ @test isequal (v5, Nullable (false ))
458
+ @test isequal (v6, Nullable (false ))
459
+ @test isequal (v7, Nullable {Bool} ())
460
+ @test isequal (v8, Nullable (false ))
461
+ @test isequal (v9, Nullable {Bool} ())
462
+
463
+ # | truth table
464
+ u1 = SQ. lift (| , Nullable (true ), Nullable (true ))
465
+ u2 = SQ. lift (| , Nullable (true ), Nullable (false ))
466
+ u3 = SQ. lift (| , Nullable (true ), Nullable {Bool} ())
467
+ u4 = SQ. lift (| , Nullable (false ), Nullable (true ))
468
+ u5 = SQ. lift (| , Nullable (false ), Nullable (false ))
469
+ u6 = SQ. lift (| , Nullable (false ), Nullable {Bool} ())
470
+ u7 = SQ. lift (| , Nullable {Bool} (), Nullable (true ))
471
+ u8 = SQ. lift (| , Nullable {Bool} (), Nullable (false ))
472
+ u9 = SQ. lift (| , Nullable {Bool} (), Nullable {Bool} ())
473
+
474
+ @test isequal (u1, Nullable (true ))
475
+ @test isequal (u2, Nullable (true ))
476
+ @test isequal (u3, Nullable (true ))
477
+ @test isequal (u4, Nullable (true ))
478
+ @test isequal (u5, Nullable (false ))
479
+ @test isequal (u6, Nullable {Bool} ())
480
+ @test isequal (u7, Nullable (true ))
481
+ @test isequal (u8, Nullable {Bool} ())
482
+ @test isequal (u9, Nullable {Bool} ())
483
+
484
+ # others
485
+
486
+ x1 = Nullable (1 )
487
+ x2 = Nullable (2 )
488
+ y = Nullable {Int} ()
489
+ z1 = 1
490
+ z2 = 2
491
+
492
+ @test SQ. lift (isnull, x1) == false
493
+ @test SQ. lift (isnull, y) == true
494
+
495
+ @test SQ. lift (isless, x1, y) == true
496
+ @test SQ. lift (isless, y, x1) == false
497
+ @test SQ. lift (isless, x1, x2) == true
498
+ @test SQ. lift (isless, x2, x1) == false
499
+ @test SQ. lift (isless, y, y) == false
500
+ @test SQ. lift (isless, x1, z2) == true
501
+ @test SQ. lift (isless, x2, z1) == false
502
+ @test SQ. lift (isless, z1, x2) == true
503
+ @test SQ. lift (isless, z2, x1) == false
504
+
505
+ @test SQ. lift (get, x1) == 1
506
+ @test_throws NullException SQ. lift (get, y)
507
+ @test SQ. lift (get, y, 1 ) == 1
0 commit comments