github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/timeutil/pgdate/fields_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 pgdate 12 13 import "testing" 14 15 func TestFieldSet(t *testing.T) { 16 var f fieldSet 17 if f.Has(fieldDay) { 18 t.Fatal("unexpected day") 19 } 20 f = newFieldSet(fieldDay, fieldHour) 21 if !f.Has(fieldDay) { 22 t.Fatal("expected day") 23 } 24 if !f.Has(fieldHour) { 25 t.Fatal("expected hour") 26 } 27 28 if !f.HasAll(newFieldSet(fieldDay, fieldHour)) { 29 t.Fatal("expected day and hour") 30 } 31 if f.HasAll(newFieldSet(fieldDay, fieldSecond)) { 32 t.Fatal("should not have matched") 33 } 34 if f != f.Add(fieldHour) { 35 t.Fatal("setting existing field should be no-op") 36 } 37 f = f.Clear(fieldHour) 38 if f.Has(fieldHour) { 39 t.Fatal("unexpected hour") 40 } 41 }