@@ -2595,6 +2595,46 @@ func TestCheckErrorData(t *testing.T) {
2595
2595
}
2596
2596
}
2597
2597
2598
+ func TestCheckInvalidOptSelectMember (t * testing.T ) {
2599
+ fac := ast .NewExprFactory ()
2600
+ target := fac .NewStruct (1 , "Foo" , nil )
2601
+ arg1 := fac .NewStruct (2 , "Foo" , nil )
2602
+ arg2 := fac .NewLiteral (3 , types .String ("field" ))
2603
+ call := fac .NewMemberCall (4 , "_?._" , target , arg1 , arg2 )
2604
+
2605
+ // This is not valid syntax, just for illustration purposes.
2606
+ src := common .NewTextSource ("Foo{}._?._(Foo{}, 'field')" )
2607
+ parsed := ast .NewAST (call , ast .NewSourceInfo (src ))
2608
+ reg := newTestRegistry (t )
2609
+ env , err := NewEnv (containers .DefaultContainer , reg )
2610
+ if err != nil {
2611
+ t .Fatalf ("NewEnv(cont, reg) failed: %v" , err )
2612
+ }
2613
+ _ , iss := Check (parsed , src , env )
2614
+ if ! strings .Contains (iss .ToDisplayString (), "incorrect signature. member call" ) {
2615
+ t .Errorf ("got %s, wanted 'incorrect signature. member call'" , iss .ToDisplayString ())
2616
+ }
2617
+ }
2618
+
2619
+ func TestCheckInvalidOptSelectMissingArg (t * testing.T ) {
2620
+ fac := ast .NewExprFactory ()
2621
+ arg1 := fac .NewStruct (1 , "Foo" , nil )
2622
+ call := fac .NewCall (2 , "_?._" , arg1 )
2623
+
2624
+ // This is not valid syntax, just for illustration purposes.
2625
+ src := common .NewTextSource ("_?._(Foo{})" )
2626
+ parsed := ast .NewAST (call , ast .NewSourceInfo (src ))
2627
+ reg := newTestRegistry (t )
2628
+ env , err := NewEnv (containers .DefaultContainer , reg )
2629
+ if err != nil {
2630
+ t .Fatalf ("NewEnv(cont, reg) failed: %v" , err )
2631
+ }
2632
+ _ , iss := Check (parsed , src , env )
2633
+ if ! strings .Contains (iss .ToDisplayString (), "incorrect signature. argument count: 1" ) {
2634
+ t .Errorf ("got %s, wanted 'incorrect signature. argument count: 1'" , iss .ToDisplayString ())
2635
+ }
2636
+ }
2637
+
2598
2638
func TestCheckInvalidLiteral (t * testing.T ) {
2599
2639
fac := ast .NewExprFactory ()
2600
2640
durLiteral := fac .NewLiteral (1 , types.Duration {Duration : time .Second })
0 commit comments