-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Upgrade to long 5.0.0. * Use import require for Long w/o esModuleInterop. * Update tests. * Er, undo importSuffix addition.
- Loading branch information
Showing
78 changed files
with
204 additions
and
704 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,103 @@ | ||
import { Extendable, Nested, packed, repeated, bytes, string, long, fixed, enumField, group, Enum } from './test'; | ||
import * as Long from 'long'; | ||
import { Extendable, Nested, packed, repeated, bytes, string, long, fixed, enumField, group, Enum } from "./test"; | ||
import Long = require("long"); | ||
|
||
describe('extensions-test', () => { | ||
it('works with namespaced extensions', () => { | ||
const test: Extendable = { | ||
field: 'hello' | ||
}; | ||
describe("extensions-test", () => { | ||
it("works with namespaced extensions", () => { | ||
const test: Extendable = { | ||
field: "hello", | ||
}; | ||
|
||
const extensionData = [ | ||
{ | ||
field: 'a' | ||
}, | ||
{ | ||
field: 'b' | ||
} | ||
]; | ||
const extensionData = [ | ||
{ | ||
field: "a", | ||
}, | ||
{ | ||
field: "b", | ||
}, | ||
]; | ||
|
||
Extendable.setExtension(test, Nested.message, extensionData); | ||
Extendable.setExtension(test, Nested.message, extensionData); | ||
|
||
const encoded = Extendable.encode(test).finish(); | ||
const result = Extendable.decode(encoded); | ||
const encoded = Extendable.encode(test).finish(); | ||
const result = Extendable.decode(encoded); | ||
|
||
expect(result).toEqual(test); | ||
expect(result).toEqual(test); | ||
|
||
const extension = Extendable.getExtension(result, Nested.message); | ||
const extension = Extendable.getExtension(result, Nested.message); | ||
|
||
expect(extension).toEqual(extensionData); | ||
expect(extension).toEqual(extensionData); | ||
|
||
const unsetExtension = Extendable.getExtension(result, packed); | ||
const unsetExtension = Extendable.getExtension(result, packed); | ||
|
||
expect(unsetExtension).toEqual(undefined); | ||
}); | ||
expect(unsetExtension).toEqual(undefined); | ||
}); | ||
|
||
it('works with repeated fields', () => { | ||
const test: Extendable = { | ||
field: 'repeated', | ||
it("works with repeated fields", () => { | ||
const test: Extendable = { | ||
field: "repeated", | ||
|
||
_unknownFields: { | ||
[(6 << 3) | 2]: [Buffer.from([1, 1]), Buffer.from([1, 1])], | ||
[(6 << 3) | 0]: [Buffer.from([2]), Buffer.from([3]), Buffer.from([5])] | ||
} | ||
}; | ||
_unknownFields: { | ||
[(6 << 3) | 2]: [Buffer.from([1, 1]), Buffer.from([1, 1])], | ||
[(6 << 3) | 0]: [Buffer.from([2]), Buffer.from([3]), Buffer.from([5])], | ||
}, | ||
}; | ||
|
||
const extensionData = [1, 2, 3, 4, 5]; | ||
const extensionData = [1, 2, 3, 4, 5]; | ||
|
||
Extendable.setExtension(test, packed, extensionData); | ||
Extendable.setExtension(test, packed, extensionData); | ||
|
||
const encoded = Extendable.encode(test).finish(); | ||
const result = Extendable.decode(encoded); | ||
const encoded = Extendable.encode(test).finish(); | ||
const result = Extendable.decode(encoded); | ||
|
||
expect(result).toEqual(test); | ||
expect(result).toEqual(test); | ||
|
||
const extension = Extendable.getExtension(result, packed); | ||
const extension = Extendable.getExtension(result, packed); | ||
|
||
expect(extension).toEqual(extensionData); | ||
expect(extension).toEqual(extensionData); | ||
|
||
expect(Extendable.getExtension(result, repeated)).toEqual([1, 1, 2, 3, 5]); | ||
expect(Extendable.getExtension(result, repeated)).toEqual([1, 1, 2, 3, 5]); | ||
|
||
const unsetExtension = Extendable.getExtension(result, Nested.message); | ||
const unsetExtension = Extendable.getExtension(result, Nested.message); | ||
|
||
expect(unsetExtension).toEqual(undefined); | ||
}); | ||
expect(unsetExtension).toEqual(undefined); | ||
}); | ||
|
||
it('works with various field types', () => { | ||
const test: Extendable = { | ||
field: 'various' | ||
}; | ||
it("works with various field types", () => { | ||
const test: Extendable = { | ||
field: "various", | ||
}; | ||
|
||
const bytesExtensionData = Buffer.from([2, 3, 5, 7, 11]); | ||
const stringExtensionData = "this is a string"; | ||
const longExtensionData = new Long(0x89ABCDEF, 0x01234567, false); | ||
const fixedExtensionData = new Long(0x01234567, 0x89ABCDEF, true); | ||
const enumExtensionData = Enum.ENUM_ONE; | ||
const groupExtensionData = { | ||
name: 'this is', | ||
value: 'a group' | ||
}; | ||
const bytesExtensionData = Buffer.from([2, 3, 5, 7, 11]); | ||
const stringExtensionData = "this is a string"; | ||
const longExtensionData = new Long(0x89abcdef, 0x01234567, false); | ||
const fixedExtensionData = new Long(0x01234567, 0x89abcdef, true); | ||
const enumExtensionData = Enum.ENUM_ONE; | ||
const groupExtensionData = { | ||
name: "this is", | ||
value: "a group", | ||
}; | ||
|
||
Extendable.setExtension(test, bytes, bytesExtensionData); | ||
Extendable.setExtension(test, string, stringExtensionData); | ||
Extendable.setExtension(test, long, longExtensionData); | ||
Extendable.setExtension(test, fixed, fixedExtensionData); | ||
Extendable.setExtension(test, enumField, enumExtensionData); | ||
Extendable.setExtension(test, group, groupExtensionData); | ||
Extendable.setExtension(test, bytes, bytesExtensionData); | ||
Extendable.setExtension(test, string, stringExtensionData); | ||
Extendable.setExtension(test, long, longExtensionData); | ||
Extendable.setExtension(test, fixed, fixedExtensionData); | ||
Extendable.setExtension(test, enumField, enumExtensionData); | ||
Extendable.setExtension(test, group, groupExtensionData); | ||
|
||
const encoded = Extendable.encode(test).finish(); | ||
const result = Extendable.decode(encoded); | ||
const encoded = Extendable.encode(test).finish(); | ||
const result = Extendable.decode(encoded); | ||
|
||
expect(result).toEqual(test); | ||
expect(result).toEqual(test); | ||
|
||
expect( Extendable.getExtension(result, bytes) ).toEqual(bytesExtensionData); | ||
expect( Extendable.getExtension(result, string) ).toEqual(stringExtensionData); | ||
expect( Extendable.getExtension(result, long) ).toEqual(longExtensionData); | ||
expect( Extendable.getExtension(result, fixed) ).toEqual(fixedExtensionData); | ||
expect( Extendable.getExtension(result, enumField) ).toEqual(enumExtensionData); | ||
expect( Extendable.getExtension(result, group) ).toEqual(groupExtensionData); | ||
expect(Extendable.getExtension(result, bytes)).toEqual(bytesExtensionData); | ||
expect(Extendable.getExtension(result, string)).toEqual(stringExtensionData); | ||
expect(Extendable.getExtension(result, long)).toEqual(longExtensionData); | ||
expect(Extendable.getExtension(result, fixed)).toEqual(fixedExtensionData); | ||
expect(Extendable.getExtension(result, enumField)).toEqual(enumExtensionData); | ||
expect(Extendable.getExtension(result, group)).toEqual(groupExtensionData); | ||
|
||
const unsetExtension = Extendable.getExtension(result, Nested.message); | ||
const unsetExtension = Extendable.getExtension(result, Nested.message); | ||
|
||
expect(unsetExtension).toEqual(undefined); | ||
}); | ||
expect(unsetExtension).toEqual(undefined); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.