Skip to content

Commit

Permalink
add tests for getTypeUrl method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorcode committed Oct 16, 2020
1 parent ba7fa51 commit ae0f73d
Show file tree
Hide file tree
Showing 20 changed files with 1,591 additions and 70 deletions.
3 changes: 2 additions & 1 deletion scripts/gentests.js
Expand Up @@ -13,7 +13,8 @@ var fs = require("fs"),
{ file: "tests/data/rpc.proto", flags: [] },
{ file: "tests/data/rpc-reserved.proto", flags: [] },
{ file: "tests/data/test.proto", flags: [] },
{ file: "bench/data/bench.proto", flags: ["no-create", "no-verify", "no-delimited", "no-convert", "no-comments"], out: "bench/data/static_pbjs.js" }
{ file: "tests/data/type_url.proto", flags: [] },
{ file: "bench/data/bench.proto", flags: ["no-create", "no-verify", "no-delimited", "no-convert", "no-verify", "no-typeurl", "no-comments"], out: "bench/data/static_pbjs.js" }
]
.forEach(function({ file, flags, out }) {
var basename = file.replace(/\.proto$/, "");
Expand Down
2 changes: 2 additions & 0 deletions tests/data/comments.d.ts
Expand Up @@ -19,6 +19,7 @@ export class Test1 implements ITest1 {
public static fromObject(object: { [k: string]: any }): Test1;
public static toObject(message: Test1, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}

export interface ITest2 {
Expand All @@ -35,6 +36,7 @@ export class Test2 implements ITest2 {
public static fromObject(object: { [k: string]: any }): Test2;
public static toObject(message: Test2, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}

export enum Test3 {
Expand Down
22 changes: 22 additions & 0 deletions tests/data/comments.js
Expand Up @@ -241,6 +241,17 @@ $root.Test1 = (function() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};

/**
* Gets the default type url for Test1
* @function getTypeUrl
* @memberof Test1
* @static
* @returns {string} The default type url
*/
Test1.getTypeUrl = function getTypeUrl() {
return "type.googleapis.com/Test1";
};

return Test1;
})();

Expand Down Expand Up @@ -401,6 +412,17 @@ $root.Test2 = (function() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};

/**
* Gets the default type url for Test2
* @function getTypeUrl
* @memberof Test2
* @static
* @returns {string} The default type url
*/
Test2.getTypeUrl = function getTypeUrl() {
return "type.googleapis.com/Test2";
};

return Test2;
})();

Expand Down
1 change: 1 addition & 0 deletions tests/data/convert.d.ts
Expand Up @@ -31,6 +31,7 @@ export class Message implements IMessage {
public static fromObject(object: { [k: string]: any }): Message;
public static toObject(message: Message, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}

export namespace Message {
Expand Down
35 changes: 30 additions & 5 deletions tests/data/convert.js
Expand Up @@ -201,7 +201,7 @@ $root.Message = (function() {
Message.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Message(), key;
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.Message(), key, value;
while (reader.pos < end) {
var tag = reader.uint32();
switch (tag >>> 3) {
Expand Down Expand Up @@ -248,12 +248,26 @@ $root.Message = (function() {
message.enumRepeated.push(reader.int32());
break;
case 9:
reader.skip().pos++;
if (message.int64Map === $util.emptyObject)
message.int64Map = {};
key = reader.string();
reader.pos++;
message.int64Map[key] = reader.int64();
var end2 = reader.uint32() + reader.pos;
key = "";
value = 0;
while (reader.pos < end2) {
var tag2 = reader.uint32();
switch (tag2 >>> 3) {
case 1:
key = reader.string();
break;
case 2:
value = reader.int64();
break;
default:
reader.skipType(tag2 & 7);
break;
}
}
message.int64Map[key] = value;
break;
default:
reader.skipType(tag & 7);
Expand Down Expand Up @@ -548,6 +562,17 @@ $root.Message = (function() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};

/**
* Gets the default type url for Message
* @function getTypeUrl
* @memberof Message
* @static
* @returns {string} The default type url
*/
Message.getTypeUrl = function getTypeUrl() {
return "type.googleapis.com/Message";
};

/**
* SomeEnum enum.
* @name Message.SomeEnum
Expand Down
4 changes: 4 additions & 0 deletions tests/data/mapbox/vector_tile.d.ts
Expand Up @@ -17,6 +17,7 @@ export namespace vector_tile {
public static fromObject(object: { [k: string]: any }): vector_tile.Tile;
public static toObject(message: vector_tile.Tile, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}

namespace Tile {
Expand Down Expand Up @@ -56,6 +57,7 @@ export namespace vector_tile {
public static fromObject(object: { [k: string]: any }): vector_tile.Tile.Value;
public static toObject(message: vector_tile.Tile.Value, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}

interface IFeature {
Expand All @@ -80,6 +82,7 @@ export namespace vector_tile {
public static fromObject(object: { [k: string]: any }): vector_tile.Tile.Feature;
public static toObject(message: vector_tile.Tile.Feature, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}

interface ILayer {
Expand Down Expand Up @@ -108,6 +111,7 @@ export namespace vector_tile {
public static fromObject(object: { [k: string]: any }): vector_tile.Tile.Layer;
public static toObject(message: vector_tile.Tile.Layer, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}
}
}
44 changes: 44 additions & 0 deletions tests/data/mapbox/vector_tile.js
Expand Up @@ -223,6 +223,17 @@ $root.vector_tile = (function() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};

/**
* Gets the default type url for Tile
* @function getTypeUrl
* @memberof vector_tile.Tile
* @static
* @returns {string} The default type url
*/
Tile.getTypeUrl = function getTypeUrl() {
return "type.googleapis.com/vector_tile.Tile";
};

/**
* GeomType enum.
* @name vector_tile.Tile.GeomType
Expand Down Expand Up @@ -600,6 +611,17 @@ $root.vector_tile = (function() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};

/**
* Gets the default type url for Value
* @function getTypeUrl
* @memberof vector_tile.Tile.Value
* @static
* @returns {string} The default type url
*/
Value.getTypeUrl = function getTypeUrl() {
return "type.googleapis.com/vector_tile.Tile.Value";
};

return Value;
})();

Expand Down Expand Up @@ -941,6 +963,17 @@ $root.vector_tile = (function() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};

/**
* Gets the default type url for Feature
* @function getTypeUrl
* @memberof vector_tile.Tile.Feature
* @static
* @returns {string} The default type url
*/
Feature.getTypeUrl = function getTypeUrl() {
return "type.googleapis.com/vector_tile.Tile.Feature";
};

return Feature;
})();

Expand Down Expand Up @@ -1299,6 +1332,17 @@ $root.vector_tile = (function() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};

/**
* Gets the default type url for Layer
* @function getTypeUrl
* @memberof vector_tile.Tile.Layer
* @static
* @returns {string} The default type url
*/
Layer.getTypeUrl = function getTypeUrl() {
return "type.googleapis.com/vector_tile.Tile.Layer";
};

return Layer;
})();

Expand Down
2 changes: 2 additions & 0 deletions tests/data/package.d.ts
Expand Up @@ -47,6 +47,7 @@ export class Package implements IPackage {
public static fromObject(object: { [k: string]: any }): Package;
public static toObject(message: Package, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}

export namespace Package {
Expand All @@ -69,5 +70,6 @@ export namespace Package {
public static fromObject(object: { [k: string]: any }): Package.Repository;
public static toObject(message: Package.Repository, options?: $protobuf.IConversionOptions): { [k: string]: any };
public toJSON(): { [k: string]: any };
public static getTypeUrl(): string;
}
}

0 comments on commit ae0f73d

Please sign in to comment.