@@ -633,6 +633,80 @@ func TestValueEquals(t *testing.T) {
633
633
NumberIntVal (1 ),
634
634
False , // because no string value -- even null -- can be equal to a non-null number
635
635
},
636
+ {
637
+ ObjectVal (map [string ]Value {
638
+ "a" : StringVal ("a" ),
639
+ }),
640
+ // A null value is always known
641
+ ObjectVal (map [string ]Value {
642
+ "a" : NullVal (DynamicPseudoType ),
643
+ }),
644
+ BoolVal (false ),
645
+ },
646
+ {
647
+ ObjectVal (map [string ]Value {
648
+ "a" : NullVal (DynamicPseudoType ),
649
+ }),
650
+ ObjectVal (map [string ]Value {
651
+ "a" : NullVal (DynamicPseudoType ),
652
+ }),
653
+ BoolVal (true ),
654
+ },
655
+ {
656
+ ObjectVal (map [string ]Value {
657
+ "a" : StringVal ("a" ),
658
+ "b" : UnknownVal (Number ),
659
+ }),
660
+ // While we have a dynamic type, the different object types should
661
+ // still compare false
662
+ ObjectVal (map [string ]Value {
663
+ "a" : NullVal (DynamicPseudoType ),
664
+ "c" : UnknownVal (Number ),
665
+ }),
666
+ BoolVal (false ),
667
+ },
668
+ {
669
+ ObjectVal (map [string ]Value {
670
+ "a" : StringVal ("a" ),
671
+ "b" : UnknownVal (Number ),
672
+ }),
673
+ // While we have a dynamic type, the different object types should
674
+ // still compare false
675
+ ObjectVal (map [string ]Value {
676
+ "a" : DynamicVal ,
677
+ "c" : UnknownVal (Number ),
678
+ }),
679
+ BoolVal (false ),
680
+ },
681
+ {
682
+ ObjectVal (map [string ]Value {
683
+ "a" : NullVal (DynamicPseudoType ),
684
+ }),
685
+ ObjectVal (map [string ]Value {
686
+ "a" : DynamicVal ,
687
+ }),
688
+ UnknownVal (Bool ),
689
+ },
690
+ {
691
+ ObjectVal (map [string ]Value {
692
+ "a" : NullVal (List (String )),
693
+ }),
694
+ // While the unknown val does contain dynamic types, the overall
695
+ // container types can't conform.
696
+ ObjectVal (map [string ]Value {
697
+ "a" : UnknownVal (List (List (DynamicPseudoType ))),
698
+ }),
699
+ BoolVal (false ),
700
+ },
701
+ {
702
+ ObjectVal (map [string ]Value {
703
+ "a" : NullVal (List (List (String ))),
704
+ }),
705
+ ObjectVal (map [string ]Value {
706
+ "a" : UnknownVal (List (List (DynamicPseudoType ))),
707
+ }),
708
+ UnknownVal (Bool ),
709
+ },
636
710
637
711
// Marks
638
712
{
@@ -2435,3 +2509,78 @@ func TestValueGoString(t *testing.T) {
2435
2509
})
2436
2510
}
2437
2511
}
2512
+
2513
+ func TestHasWhollyKnownType (t * testing.T ) {
2514
+ tests := []struct {
2515
+ Value Value
2516
+ Want bool
2517
+ }{
2518
+ {
2519
+ Value : DynamicVal ,
2520
+ Want : false ,
2521
+ },
2522
+ {
2523
+ Value : ObjectVal (map [string ]Value {
2524
+ "dyn" : DynamicVal ,
2525
+ }),
2526
+ Want : false ,
2527
+ },
2528
+ {
2529
+ Value : NullVal (Object (map [string ]Type {
2530
+ "dyn" : DynamicPseudoType ,
2531
+ })),
2532
+ Want : true ,
2533
+ },
2534
+ {
2535
+ Value : TupleVal ([]Value {
2536
+ StringVal ("a" ),
2537
+ NullVal (DynamicPseudoType ),
2538
+ }),
2539
+ Want : true ,
2540
+ },
2541
+ {
2542
+ Value : ListVal ([]Value {
2543
+ ObjectVal (map [string ]Value {
2544
+ "null" : NullVal (DynamicPseudoType ),
2545
+ }),
2546
+ }),
2547
+ Want : true ,
2548
+ },
2549
+ {
2550
+ Value : ListVal ([]Value {
2551
+ NullVal (Object (map [string ]Type {
2552
+ "dyn" : DynamicPseudoType ,
2553
+ })),
2554
+ }),
2555
+ Want : true ,
2556
+ },
2557
+ {
2558
+ Value : ObjectVal (map [string ]Value {
2559
+ "tuple" : TupleVal ([]Value {
2560
+ StringVal ("a" ),
2561
+ NullVal (DynamicPseudoType ),
2562
+ }),
2563
+ }),
2564
+ Want : true ,
2565
+ },
2566
+ {
2567
+ Value : ObjectVal (map [string ]Value {
2568
+ "tuple" : TupleVal ([]Value {
2569
+ ObjectVal (map [string ]Value {
2570
+ "dyn" : DynamicVal ,
2571
+ }),
2572
+ }),
2573
+ }),
2574
+ Want : false ,
2575
+ },
2576
+ }
2577
+ for _ , test := range tests {
2578
+ t .Run (test .Value .GoString (), func (t * testing.T ) {
2579
+ got := test .Value .HasWhollyKnownType ()
2580
+ want := test .Want
2581
+ if got != want {
2582
+ t .Errorf ("wrong result\n got: %v\n want: %v" , got , want )
2583
+ }
2584
+ })
2585
+ }
2586
+ }
0 commit comments