@@ -628,6 +628,93 @@ func TestCost(t *testing.T) {
628
628
expr : `['hello', 'hi'][0] != ['hello', 'bye'][1]` ,
629
629
wanted : CostEstimate {Min : 23 , Max : 23 },
630
630
},
631
+ {
632
+ name : "type call" ,
633
+ expr : `type(1)` ,
634
+ wanted : CostEstimate {Min : 1 , Max : 1 },
635
+ },
636
+ {
637
+ name : "type call variable" ,
638
+ expr : `type(self.val1)` ,
639
+ vars : []* decls.VariableDecl {
640
+ decls .NewVariable ("self" , types .NewMapType (types .StringType , types .IntType )),
641
+ },
642
+ wanted : CostEstimate {Min : 3 , Max : 3 },
643
+ },
644
+ {
645
+ name : "type call variable equality" ,
646
+ expr : `type(self.val1) == int` ,
647
+ vars : []* decls.VariableDecl {
648
+ decls .NewVariable ("self" , types .NewMapType (types .StringType , types .IntType )),
649
+ },
650
+ wanted : CostEstimate {Min : 5 , Max : 1844674407370955268 },
651
+ },
652
+ {
653
+ name : "type literal equality cost" ,
654
+ expr : `type(1) == int` ,
655
+ wanted : CostEstimate {Min : 3 , Max : 1844674407370955266 },
656
+ },
657
+ {
658
+ name : "type variable equality cost" ,
659
+ expr : `type(1) == int` ,
660
+ wanted : CostEstimate {Min : 3 , Max : 1844674407370955266 },
661
+ },
662
+ {
663
+ name : "namespace variable equality" ,
664
+ expr : `self.val1 == 1.0` ,
665
+ vars : []* decls.VariableDecl {
666
+ decls .NewVariable ("self.val1" , types .DoubleType ),
667
+ },
668
+ wanted : CostEstimate {Min : 2 , Max : 2 },
669
+ },
670
+ {
671
+ name : "simple map variable equality" ,
672
+ expr : `self.val1 == 1.0` ,
673
+ vars : []* decls.VariableDecl {
674
+ decls .NewVariable ("self" , types .NewMapType (types .StringType , types .DoubleType )),
675
+ },
676
+ wanted : CostEstimate {Min : 3 , Max : 3 },
677
+ },
678
+ {
679
+ name : "date-time math" ,
680
+ vars : []* decls.VariableDecl {
681
+ decls .NewVariable ("self" , types .NewMapType (types .StringType , types .TimestampType )),
682
+ },
683
+ expr : `self.val1 == timestamp('2011-08-18T00:00:00.000+01:00') + duration('19h3m37s10ms')` ,
684
+ wanted : FixedCostEstimate (6 ),
685
+ },
686
+ {
687
+ name : "date-time math self-conversion" ,
688
+ vars : []* decls.VariableDecl {
689
+ decls .NewVariable ("self" , types .NewMapType (types .StringType , types .TimestampType )),
690
+ },
691
+ expr : `timestamp(self.val1) == timestamp('2011-08-18T00:00:00.000+01:00') + duration('19h3m37s10ms')` ,
692
+ wanted : FixedCostEstimate (7 ),
693
+ },
694
+ {
695
+ name : "boolean vars equal" ,
696
+ vars : []* decls.VariableDecl {
697
+ decls .NewVariable ("self" , types .NewMapType (types .StringType , types .BoolType )),
698
+ },
699
+ expr : `self.val1 != self.val2` ,
700
+ wanted : FixedCostEstimate (5 ),
701
+ },
702
+ {
703
+ name : "boolean var equals literal" ,
704
+ vars : []* decls.VariableDecl {
705
+ decls .NewVariable ("self" , types .NewMapType (types .StringType , types .BoolType )),
706
+ },
707
+ expr : `self.val1 != true` ,
708
+ wanted : FixedCostEstimate (3 ),
709
+ },
710
+ {
711
+ name : "double var equals literal" ,
712
+ vars : []* decls.VariableDecl {
713
+ decls .NewVariable ("self" , types .NewMapType (types .StringType , types .DoubleType )),
714
+ },
715
+ expr : `self.val1 == 1.0` ,
716
+ wanted : FixedCostEstimate (3 ),
717
+ },
631
718
}
632
719
633
720
for _ , tst := range cases {
0 commit comments