2018-12-05 18:35:35 +00:00
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2019-05-22 09:22:04 +00:00
|
|
|
package descfmt
|
2018-12-05 18:35:35 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestDescriptorAccessors tests that descriptorAccessors is up-to-date.
|
|
|
|
func TestDescriptorAccessors(t *testing.T) {
|
|
|
|
ignore := map[string]bool{
|
2019-05-12 09:27:46 +00:00
|
|
|
"ParentFile": true,
|
2018-12-06 20:10:41 +00:00
|
|
|
"Parent": true,
|
|
|
|
"Index": true,
|
|
|
|
"Syntax": true,
|
|
|
|
"Name": true,
|
|
|
|
"FullName": true,
|
|
|
|
"IsPlaceholder": true,
|
2019-06-18 08:02:13 +00:00
|
|
|
"Options": true,
|
2018-12-06 20:10:41 +00:00
|
|
|
"ProtoInternal": true,
|
|
|
|
"ProtoType": true,
|
|
|
|
|
2019-06-18 08:02:13 +00:00
|
|
|
"SourceLocations": true, // specific to FileDescriptor
|
|
|
|
"ExtensionRangeOptions": true, // specific to MessageDescriptor
|
|
|
|
"DefaultEnumValue": true, // specific to FieldDescriptor
|
|
|
|
"MapKey": true, // specific to FieldDescriptor
|
|
|
|
"MapValue": true, // specific to FieldDescriptor
|
2018-12-05 18:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for rt, m := range descriptorAccessors {
|
|
|
|
got := map[string]bool{}
|
|
|
|
for _, s := range m {
|
|
|
|
got[s] = true
|
|
|
|
}
|
|
|
|
want := map[string]bool{}
|
|
|
|
for i := 0; i < rt.NumMethod(); i++ {
|
|
|
|
want[rt.Method(i).Name] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if descriptorAccessors contains a non-existent accessor.
|
|
|
|
// If this test fails, remove the accessor from descriptorAccessors.
|
|
|
|
for s := range got {
|
|
|
|
if !want[s] && !ignore[s] {
|
|
|
|
t.Errorf("%v.%v does not exist", rt, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if there are new protoreflect interface methods that are not
|
|
|
|
// handled by the formatter. If this fails, either add the method to
|
|
|
|
// ignore or add them to descriptorAccessors.
|
|
|
|
for s := range want {
|
|
|
|
if !got[s] && !ignore[s] {
|
|
|
|
t.Errorf("%v.%v is not called by formatter", rt, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|