Skip to content

Commit

Permalink
unit test for issue #1783
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePlenkov committed Aug 18, 2022
1 parent 2b43bdd commit 62941d4
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/comp_import_extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
exports.__esModule = true;
var path = require("path");
var tape = require("tape");
var protobuf = require("../index");
// to extend Root
require("../ext/descriptor");
tape.test("extensions", function (test) {
// load document with extended field imported multiple times
var root = protobuf.loadSync(path.resolve(__dirname, "data/test-import-extend/main.proto"));
root.resolveAll();
// convert to Descriptor Set
var decodedDescriptorSet = root.toDescriptor("proto3");
// load back from descriptor set
var root2 = protobuf.Root.fromDescriptor(decodedDescriptorSet);
test.pass("should parse and resolve without errors");
test.end();
});
37 changes: 37 additions & 0 deletions tests/comp_import_extend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import path = require("path");
import * as tape from "tape";

import * as protobuf from "../index";
import { IFileDescriptorSet } from "../ext/descriptor";
// to extend Root
require("../ext/descriptor");

interface Descriptor {
toDescriptor(
protoVersion: string
): protobuf.Message<IFileDescriptorSet> & IFileDescriptorSet;
fromDescriptor(
descriptor: IFileDescriptorSet | protobuf.Reader | Uint8Array
): protobuf.Root;
}

tape.test("extensions", function (test) {
// load document with extended field imported multiple times
const root = protobuf.loadSync(
path.resolve(__dirname, "data/test-import-extend/main.proto")
);
root.resolveAll();

// convert to Descriptor Set
const decodedDescriptorSet = (root as unknown as Descriptor).toDescriptor(
"proto3"
);

// load back from descriptor set
const root2 = (protobuf.Root as unknown as Descriptor).fromDescriptor(
decodedDescriptorSet
);

test.pass("should parse and resolve without errors");
test.end();
});
6 changes: 6 additions & 0 deletions tests/data/test-import-extend/main.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";

package test.import.extend;

import "source_a.proto";
import "source_b.proto";
5 changes: 5 additions & 0 deletions tests/data/test-import-extend/source_a.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

package source.a;

import "validation.proto";
5 changes: 5 additions & 0 deletions tests/data/test-import-extend/source_b.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
syntax = "proto3";

package source.b;

import "validation.proto";
15 changes: 15 additions & 0 deletions tests/data/test-import-extend/validation.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

package validation;

import "../google/protobuf/descriptor.proto";

option java_package = "com.reserve.validation";
option java_outer_classname = "ValidationRules";

extend google.protobuf.FieldOptions { FieldRules rules = 70001; }

message FieldRules {
reserved 1;
reserved "optional";
}

0 comments on commit 62941d4

Please sign in to comment.