go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/starlark/starlarkproto/testdata/desc_set.star (about)

     1  # Copyright 2019 The LUCI Authors.
     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  ds = proto.new_descriptor_set(name='zzz', blob=read('./testprotos/all.pb'))
    16  assert.true(ds)
    17  assert.eq(str(ds), 'proto.DescriptorSet("zzz")')
    18  assert.eq(type(ds), 'proto.DescriptorSet')
    19  assert.eq(dir(ds), ['register'])
    20  
    21  # Can be used as a map key.
    22  m = {ds: 123}
    23  
    24  # Registration works.
    25  l1 = proto.new_loader()
    26  ds.register(l1)
    27  assert.true(l1.module('go.chromium.org/luci/starlark/starlarkproto/testprotos/test.proto'))
    28  ds.register(l1)  # doing it twice is OK
    29  l1.add_descriptor_set(ds)  # this also works
    30  
    31  # Registration through deps works.
    32  l2 = proto.new_loader()
    33  ds2 = proto.new_descriptor_set(deps=[ds])
    34  ds2.register(l2)
    35  assert.true(l2.module('go.chromium.org/luci/starlark/starlarkproto/testprotos/test.proto'))