Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Add test case for Long handling in int64
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed May 1, 2018
1 parent 41f499c commit 2828b3c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
5 changes: 4 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ js_library(
],
# Make devmode loading work when it does require("protobufjs/minimal")
# so this is shimmed to define it to equal global.protobuf
amd_names = {"protobufjs/minimal": "protobuf"},
amd_names = {
"long": "Long",
"protobufjs/minimal": "protobuf",
},
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions examples/protocol_buffers/car.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ message Car {
int32 year = 3;
Tire front_tires = 4;
Tire rear_tires = 5;
int64 mileage = 6;
}
37 changes: 28 additions & 9 deletions examples/protocol_buffers/car.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import {Car} from './car';
import Long = require('long');

describe('protocol buffers', () => {

it('allows creation of an object described by proto', () => {
const pontiac = Car.create({"make": "pontiac"});
pontiac.frontTires = {
width: 225,
aspectRatio: 65,
construction: 'R',
diameter: 17,
};
const pontiac = Car.create({
make: "pontiac",
frontTires: {
width: 225,
aspectRatio: 65,
construction: 'R',
diameter: 17,
},
});
expect(pontiac.make).toEqual('pontiac');
expect(pontiac.frontTires.width).toEqual(225);
if (!pontiac.frontTires) {
fail('Should have frontTires set');
} else {
expect(pontiac.frontTires.width).toEqual(225);
}
});
});

// Asserts that longs are handled correctly.
// This value comes from https://github.com/dcodeIO/long.js#background
it('handles long values correctly', () => {

This comment has been minimized.

Copy link
@mrmeku

mrmeku May 1, 2018

Contributor

Awesome

const pontiac = Car.create({
make: "pontiac",
// Long.MAX_VALUE
mileage: new Long(0xFFFFFFFF, 0x7FFFFFFF),
});
const object = Car.toObject(pontiac, {longs: String});
expect(object["mileage"]).toEqual("9223372036854775807");
});
});
3 changes: 3 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"compilerOptions": {
"strict": true,
"lib": ["es2015.promise", "dom", "es5"],
// Include the output directory in rootDirs so that generated .d.ts files
// can be used for type-checking in the editor, for example the car.proto
// produces a car.d.ts.
"rootDirs": [".", "../bazel-bin/examples"]
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/protobufjs/ts_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def _run_pbjs(actions, executable, output_name, proto_files, suffix = ".js", wra
args = actions.args()
args.add(["--target", "static-module"])
args.add(["--wrap", wrap])
args.add("--strict-long") # Force usage of Long type with int64 fields
args.add(["--out", js_file.path + ".tmpl"])
args.add([f.path for f in proto_files])

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"devDependencies": {
"@bazel/ibazel": "^0.2.0",
"@types/jasmine": "^2.8.2",
"@types/long": "^4.0.0",
"@types/node": "7.0.18",
"@types/source-map": "^0.5.1",
"@types/tmp": "^0.0.33",
Expand Down
24 changes: 14 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
version "2.8.2"
resolved "https://registry.yarnpkg.com/@types/jasmine/-/jasmine-2.8.2.tgz#6ae4d8740c0da5d5a627df725b4eed71b8e36668"

"@types/long@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.0.tgz#719551d2352d301ac8b81db732acb6bdc28dbdef"

"@types/[email protected]":
version "7.0.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.18.tgz#cd67f27d3dc0cfb746f0bdd5e086c4c5d55be173"
Expand Down Expand Up @@ -925,15 +929,15 @@ [email protected]:
source-map "^0.5.6"
source-map-support "^0.4.2"

tslib@^1.7.1:
version "1.8.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.8.0.tgz#dc604ebad64bcbf696d613da6c954aa0e7ea1eb6"
tslib@^1.8.1:
version "1.9.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8"

tsutils@2.12.1:
version "2.12.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.12.1.tgz#f4d95ce3391c8971e46e54c4cf0edb0a21dd5b24"
tsutils@2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.20.0.tgz#303394064bc80be8ee04e10b8609ae852e9312d3"
dependencies:
tslib "^1.7.1"
tslib "^1.8.1"

tunnel-agent@^0.6.0:
version "0.6.0"
Expand All @@ -945,9 +949,9 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
version "0.14.5"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"

typescript@2.5.x:
version "2.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.3.tgz#df3dcdc38f3beb800d4bc322646b04a3f6ca7f0d"
typescript@2.6.x:
version "2.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"

[email protected]:
version "1.0.2"
Expand Down

0 comments on commit 2828b3c

Please sign in to comment.