github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/utilities_test.go (about) 1 // Copyright 2016-2021, Pulumi Corporation. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package codegen 16 17 import ( 18 "testing" 19 20 "github.com/pulumi/pulumi/pkg/v3/codegen/schema" 21 "github.com/stretchr/testify/assert" 22 ) 23 24 func TestStringSetContains(t *testing.T) { 25 t.Parallel() 26 27 set123 := NewStringSet("1", "2", "3") 28 set12 := NewStringSet("1", "2") 29 set14 := NewStringSet("1", "4") 30 setEmpty := NewStringSet() 31 32 assert.True(t, set123.Contains(set123)) 33 assert.True(t, set123.Contains(set12)) 34 assert.False(t, set12.Contains(set123)) 35 assert.False(t, set123.Contains(set14)) 36 assert.True(t, set123.Contains(setEmpty)) 37 } 38 39 func TestStringSetSubtract(t *testing.T) { 40 t.Parallel() 41 42 set1234 := NewStringSet("1", "2", "3", "4") 43 set125 := NewStringSet("1", "2", "5") 44 set34 := NewStringSet("3", "4") 45 setEmpty := NewStringSet() 46 47 assert.Equal(t, set34, set1234.Subtract(set125)) 48 assert.Equal(t, setEmpty, set1234.Subtract(set1234)) 49 assert.Equal(t, set1234, set1234.Subtract(setEmpty)) 50 } 51 52 func TestSimplifyInputUnion(t *testing.T) { 53 t.Parallel() 54 55 u1 := &schema.UnionType{ 56 ElementTypes: []schema.Type{ 57 &schema.InputType{ElementType: schema.StringType}, 58 schema.NumberType, 59 }, 60 } 61 62 u2 := SimplifyInputUnion(u1) 63 assert.Equal(t, &schema.UnionType{ 64 ElementTypes: []schema.Type{ 65 schema.StringType, 66 schema.NumberType, 67 }, 68 }, u2) 69 }