github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/props/physical/required_test.go (about) 1 // Copyright 2018 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 physical_test 12 13 import ( 14 "testing" 15 16 "github.com/cockroachdb/cockroach/pkg/sql/opt" 17 "github.com/cockroachdb/cockroach/pkg/sql/opt/props/physical" 18 ) 19 20 func TestRequiredProps(t *testing.T) { 21 // Empty props. 22 phys := &physical.Required{} 23 testRequiredProps(t, phys, "[]") 24 25 if phys.Defined() { 26 t.Error("no props should be defined") 27 } 28 29 // Presentation props. 30 presentation := physical.Presentation{ 31 opt.AliasedColumn{Alias: "a", ID: 1}, 32 opt.AliasedColumn{Alias: "b", ID: 2}, 33 } 34 phys = &physical.Required{Presentation: presentation} 35 testRequiredProps(t, phys, "[presentation: a:1,b:2]") 36 37 if presentation.Any() { 38 t.Error("presentation should not be empty") 39 } 40 41 if !presentation.Equals(presentation) { 42 t.Error("presentation should equal itself") 43 } 44 45 if presentation.Equals(physical.Presentation(nil)) { 46 t.Error("presentation should not equal the empty presentation") 47 } 48 49 if presentation.Equals(physical.Presentation{}) { 50 t.Error("presentation should not equal the 0 column presentation") 51 } 52 53 if (physical.Presentation{}).Equals(physical.Presentation(nil)) { 54 t.Error("0 column presentation should not equal the empty presentation") 55 } 56 57 // Add ordering props. 58 ordering := physical.ParseOrderingChoice("+1,+5") 59 phys.Ordering = ordering 60 testRequiredProps(t, phys, "[presentation: a:1,b:2] [ordering: +1,+5]") 61 } 62 63 func testRequiredProps(t *testing.T, physProps *physical.Required, expected string) { 64 t.Helper() 65 actual := physProps.String() 66 if actual != expected { 67 t.Errorf("\nexpected: %s\nactual: %s", expected, actual) 68 } 69 }