github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/props/volatility_test.go (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package props 12 13 import ( 14 "testing" 15 16 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 17 "github.com/stretchr/testify/require" 18 ) 19 20 func TestVolatilitySet(t *testing.T) { 21 var v VolatilitySet 22 23 check := func(str string, isLeakProof, hasStable, hasVolatile bool) { 24 t.Helper() 25 26 require.Equal(t, v.String(), str) 27 require.Equal(t, v.IsLeakProof(), isLeakProof) 28 require.Equal(t, v.HasStable(), hasStable) 29 require.Equal(t, v.HasVolatile(), hasVolatile) 30 } 31 check("leak-proof", true, false, false) 32 33 v.Add(tree.VolatilityLeakProof) 34 check("leak-proof", true, false, false) 35 36 v.AddImmutable() 37 check("immutable", false, false, false) 38 39 v.AddStable() 40 check("stable", false, true, false) 41 42 v.AddVolatile() 43 check("stable+volatile", false, true, true) 44 45 v = 0 46 v.AddVolatile() 47 check("volatile", false, false, true) 48 49 var w VolatilitySet 50 w.AddImmutable() 51 v.UnionWith(w) 52 check("volatile", false, false, true) 53 54 w.AddStable() 55 v.UnionWith(w) 56 check("stable+volatile", false, true, true) 57 }