• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2022 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7//     https://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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15/* eslint-env browser */
16
17import { Message } from 'pigweedjs/protos/pw_protobuf_compiler/pw_protobuf_compiler_protos/nested/more_nesting/test_pb';
18
19import { ProtoCollection } from 'pigweedjs/protos/collection';
20
21describe('ProtoCollection', () => {
22  it('getMessageType returns message', () => {
23    const lib = new ProtoCollection();
24
25    const fetched = lib.getMessageCreator('pw.protobuf_compiler.test.Message');
26    expect(fetched).toEqual(Message);
27  });
28
29  it('getMessageType for invalid identifier returns undefined', () => {
30    const lib = new ProtoCollection();
31
32    let fetched = lib.getMessageCreator('pw');
33    expect(fetched).toBeUndefined();
34    fetched = lib.getMessageCreator('pw.test1.Garbage');
35    expect(fetched).toBeUndefined();
36  });
37
38  it('getDescriptorProto returns descriptor', () => {
39    const lib = new ProtoCollection();
40
41    const fetched = lib.getDescriptorProto('pw.protobuf_compiler.test.Message');
42    expect(fetched.getFieldList()[0].getName()).toEqual('field');
43  });
44
45  it('getDescriptorProto for invalid identifier returns undefined', () => {
46    const lib = new ProtoCollection();
47
48    let fetched = lib.getMessageCreator('pw');
49    expect(fetched).toBeUndefined();
50    fetched = lib.getMessageCreator('pw.test1.Garbage');
51    expect(fetched).toBeUndefined();
52  });
53});
54