build(deps): updated vitest

This commit is contained in:
alina 🌸 2024-03-17 21:46:51 +03:00
parent 68689c27c3
commit 3074e9bbf5
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
9 changed files with 1685 additions and 258 deletions

View file

@ -40,9 +40,9 @@
"@types/ws": "8.5.4", "@types/ws": "8.5.4",
"@typescript-eslint/eslint-plugin": "6.4.0", "@typescript-eslint/eslint-plugin": "6.4.0",
"@typescript-eslint/parser": "6.4.0", "@typescript-eslint/parser": "6.4.0",
"@vitest/browser": "0.34.6", "@vitest/browser": "1.4.0",
"@vitest/coverage-v8": "0.34.6", "@vitest/coverage-v8": "1.4.0",
"@vitest/ui": "0.34.6", "@vitest/ui": "1.4.0",
"cjs-module-lexer": "1.2.3", "cjs-module-lexer": "1.2.3",
"dotenv-flow": "3.2.0", "dotenv-flow": "3.2.0",
"dpdm": "3.14.0", "dpdm": "3.14.0",
@ -65,8 +65,8 @@
"tsconfig-paths": "4.2.0", "tsconfig-paths": "4.2.0",
"typedoc": "0.25.3", "typedoc": "0.25.3",
"typescript": "5.1.6", "typescript": "5.1.6",
"vite": "5.0.3", "vite": "5.1.6",
"vitest": "0.34.6" "vitest": "1.4.0"
}, },
"prettier": "./.config/prettier.cjs", "prettier": "./.config/prettier.cjs",
"eslintConfig": { "eslintConfig": {

View file

@ -15,15 +15,11 @@ describe('isProbablyPlainText', () => {
it('should return true for buffers only containing printable ascii', () => { it('should return true for buffers only containing printable ascii', () => {
expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text'))).to.be.true expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text'))).to.be.true
expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text\nwith unix new lines'))).to.be.true expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text\nwith unix new lines'))).to.be.true
expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text\r\nwith windows new lines'))).to.be expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text\r\nwith windows new lines'))).to.be.true
expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text\n\twith unix new lines and tabs'))).to.be
.true .true
expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text\n\twith unix new lines and tabs'))) expect(isProbablyPlainText(p.utf8Encode('hello this is some ascii text\r\n\twith windows new lines and tabs')))
.to.be.true .to.be.true
expect(
isProbablyPlainText(
p.utf8Encode('hello this is some ascii text\r\n\twith windows new lines and tabs'),
),
).to.be.true
}) })
it('should return false for buffers containing some binary data', () => { it('should return false for buffers containing some binary data', () => {
@ -55,7 +51,7 @@ describe('svgPathToFile', () => {
const path = 'M 0 0 L 100 0 L 100 100 L 0 100 L 0 0 Z' const path = 'M 0 0 L 100 0 L 100 100 L 0 100 L 0 0 Z'
expect(p.utf8Decode(svgPathToFile(path))).toMatchInlineSnapshot( expect(p.utf8Decode(svgPathToFile(path))).toMatchInlineSnapshot(
'"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?><svg version=\\"1.1\\" xmlns=\\"http://www.w3.org/2000/svg\\" xmlns:xlink=\\"http://www.w3.org/1999/xlink\\"viewBox=\\"0 0 512 512\\" xml:space=\\"preserve\\"><path d=\\"M 0 0 L 100 0 L 100 100 L 0 100 L 0 0 Z\\"/></svg>"', '"<?xml version="1.0" encoding="utf-8"?><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"viewBox="0 0 512 512" xml:space="preserve"><path d="M 0 0 L 100 0 L 100 100 L 0 100 L 0 0 Z"/></svg>"',
) )
}) })
}) })

View file

@ -572,3 +572,576 @@ exports[`generateTlSchemasDifference > shows removed unions 1`] = `
}, },
} }
`; `;
exports[`generateTlSchemasDifference shows added constructors 1`] = `
{
"classes": {
"added": [
{
"arguments": [],
"id": 3847402009,
"kind": "class",
"name": "test2",
"type": "Test",
},
],
"modified": [],
"removed": [],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"unions": {
"added": [],
"modified": [
{
"classes": {
"added": [
{
"arguments": [],
"id": 3847402009,
"kind": "class",
"name": "test2",
"type": "Test",
},
],
"modified": [],
"removed": [],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"name": "Test",
},
],
"removed": [],
},
}
`;
exports[`generateTlSchemasDifference shows removed constructors 1`] = `
{
"classes": {
"added": [],
"modified": [],
"removed": [
{
"arguments": [],
"id": 3847402009,
"kind": "class",
"name": "test2",
"type": "Test",
},
],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"unions": {
"added": [],
"modified": [
{
"classes": {
"added": [],
"modified": [],
"removed": [
{
"arguments": [],
"id": 3847402009,
"kind": "class",
"name": "test2",
"type": "Test",
},
],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"name": "Test",
},
],
"removed": [],
},
}
`;
exports[`generateTlSchemasDifference shows modified constructors 1`] = `
{
"classes": {
"added": [],
"modified": [
{
"arguments": {
"added": [],
"modified": [
{
"name": "foo",
"type": {
"new": "Foo",
"old": "int",
},
},
],
"removed": [],
},
"id": {
"new": 3348640942,
"old": 1331975629,
},
"name": "test",
},
],
"removed": [],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"unions": {
"added": [],
"modified": [],
"removed": [],
},
}
`;
exports[`generateTlSchemasDifference shows removed unions 1`] = `
{
"classes": {
"added": [],
"modified": [
{
"arguments": {
"added": [],
"modified": [
{
"name": "foo",
"type": {
"new": "Foo",
"old": "int",
},
},
],
"removed": [],
},
"id": {
"new": 3348640942,
"old": 1331975629,
},
"name": "test",
},
],
"removed": [
{
"arguments": [],
"id": 3739166976,
"kind": "class",
"name": "test1",
"type": "Test1",
},
],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"unions": {
"added": [],
"modified": [],
"removed": [
{
"classes": [
{
"arguments": [],
"id": 3739166976,
"kind": "class",
"name": "test1",
"type": "Test1",
},
],
"name": "Test1",
},
],
},
}
`;
exports[`generateTlSchemasDifference shows added unions 1`] = `
{
"classes": {
"added": [
{
"arguments": [],
"id": 3739166976,
"kind": "class",
"name": "test1",
"type": "Test1",
},
],
"modified": [
{
"arguments": {
"added": [],
"modified": [
{
"name": "foo",
"type": {
"new": "Foo",
"old": "int",
},
},
],
"removed": [],
},
"id": {
"new": 3348640942,
"old": 1331975629,
},
"name": "test",
},
],
"removed": [],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"unions": {
"added": [
{
"classes": [
{
"arguments": [],
"id": 3739166976,
"kind": "class",
"name": "test1",
"type": "Test1",
},
],
"name": "Test1",
},
],
"modified": [],
"removed": [],
},
}
`;
exports[`generateTlSchemasDifference shows modified unions 1`] = `
{
"classes": {
"added": [
{
"arguments": [],
"id": 3847402009,
"kind": "class",
"name": "test2",
"type": "Test",
},
],
"modified": [
{
"arguments": {
"added": [],
"modified": [
{
"name": "foo",
"type": {
"new": "Foo",
"old": "int",
},
},
],
"removed": [],
},
"id": {
"new": 3348640942,
"old": 1331975629,
},
"name": "test",
},
],
"removed": [
{
"arguments": [],
"id": 1809692154,
"kind": "class",
"name": "test1",
"type": "Test",
},
],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"unions": {
"added": [],
"modified": [
{
"classes": {
"added": [
{
"arguments": [],
"id": 3847402009,
"kind": "class",
"name": "test2",
"type": "Test",
},
],
"modified": [],
"removed": [
{
"arguments": [],
"id": 1809692154,
"kind": "class",
"name": "test1",
"type": "Test",
},
],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"name": "Test",
},
],
"removed": [],
},
}
`;
exports[`generateTlSchemasDifference shows modified unions 2`] = `
{
"classes": {
"added": [
{
"arguments": [
{
"name": "foo",
"type": "Foo",
},
],
"id": 711487159,
"kind": "class",
"name": "test2",
"type": "Test",
},
{
"arguments": [],
"id": 704164487,
"kind": "class",
"name": "test3",
"type": "Test",
},
],
"modified": [],
"removed": [
{
"arguments": [
{
"name": "foo",
"type": "int",
},
],
"id": 1331975629,
"kind": "class",
"name": "test",
"type": "Test",
},
{
"arguments": [],
"id": 1809692154,
"kind": "class",
"name": "test1",
"type": "Test",
},
],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"unions": {
"added": [],
"modified": [
{
"classes": {
"added": [
{
"arguments": [
{
"name": "foo",
"type": "Foo",
},
],
"id": 711487159,
"kind": "class",
"name": "test2",
"type": "Test",
},
{
"arguments": [],
"id": 704164487,
"kind": "class",
"name": "test3",
"type": "Test",
},
],
"modified": [],
"removed": [
{
"arguments": [
{
"name": "foo",
"type": "int",
},
],
"id": 1331975629,
"kind": "class",
"name": "test",
"type": "Test",
},
{
"arguments": [],
"id": 1809692154,
"kind": "class",
"name": "test1",
"type": "Test",
},
],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"name": "Test",
},
],
"removed": [],
},
}
`;
exports[`generateTlSchemasDifference shows modified unions 3`] = `
{
"classes": {
"added": [],
"modified": [
{
"id": {
"new": 1997819349,
"old": 471282454,
},
"name": "test",
},
{
"id": {
"new": 3739166976,
"old": 1809692154,
},
"name": "test1",
},
],
"removed": [],
},
"methods": {
"added": [],
"modified": [],
"removed": [],
},
"unions": {
"added": [
{
"classes": [
{
"arguments": [],
"id": 1997819349,
"kind": "class",
"name": "test",
"type": "Test1",
},
{
"arguments": [],
"id": 3739166976,
"kind": "class",
"name": "test1",
"type": "Test1",
},
],
"name": "Test1",
},
],
"modified": [],
"removed": [
{
"classes": [
{
"arguments": [],
"id": 471282454,
"kind": "class",
"name": "test",
"type": "Test",
},
{
"arguments": [],
"id": 1809692154,
"kind": "class",
"name": "test1",
"type": "Test",
},
],
"name": "Test",
},
],
},
}
`;
exports[`generateTlSchemasDifference shows modified methods 1`] = `
{
"classes": {
"added": [],
"modified": [],
"removed": [],
},
"methods": {
"added": [],
"modified": [
{
"id": {
"new": 3994885231,
"old": 471282454,
},
"name": "test",
},
],
"removed": [],
},
"unions": {
"added": [
undefined,
],
"modified": [],
"removed": [
undefined,
],
},
}
`;

View file

@ -29,3 +29,24 @@ exports[`groupTlEntriesByNamespace > should group entries correctly 1`] = `
], ],
} }
`; `;
exports[`groupTlEntriesByNamespace should group entries correctly 1`] = `
{
"foo": [
{
"arguments": [],
"id": 0,
"kind": "class",
"name": "foo.bar",
"type": "FooBar",
},
{
"arguments": [],
"id": 0,
"kind": "class",
"name": "foo.baz",
"type": "FooBaz",
},
],
}
`;

View file

@ -32,7 +32,7 @@ export class RpcError extends Error {
static fromTl(obj: object): RpcError; static fromTl(obj: object): RpcError;
} }
", ",
"const _descriptionsMap = JSON.parse('{\\"FLOOD_WAIT_%d\\":\\"Wait %d seconds\\"}') "const _descriptionsMap = JSON.parse('{"FLOOD_WAIT_%d":"Wait %d seconds"}')
class RpcError extends Error { class RpcError extends Error {
constructor(code, text, description) { constructor(code, text, description) {
super(description || 'Unknown RPC error: [' + code + ':' + text + ']'); super(description || 'Unknown RPC error: [' + code + ':' + text + ']');
@ -50,7 +50,7 @@ RpcError.fromTl = function (obj) {
var err = new RpcError(obj.errorCode, obj.errorMessage); var err = new RpcError(obj.errorCode, obj.errorMessage);
var match, param; var match, param;
if ((match=err.text.match(/^FLOOD_WAIT_(\\\\d+)$/))!=null){ err.text = 'FLOOD_WAIT_%d'; param = err.duration = parseInt(match[1]) } if ((match=err.text.match(/^FLOOD_WAIT_(\\d+)$/))!=null){ err.text = 'FLOOD_WAIT_%d'; param = err.duration = parseInt(match[1]) }
else return err else return err
@ -71,3 +71,79 @@ exports.RpcError = RpcError;
", ",
] ]
`; `;
exports[`generateCodeForErrors should correctly generate errors 1`] = `
[
"type MtErrorText =
| 'USER_NOT_FOUND'
| 'FLOOD_WAIT_%d'
| (string & {}) // to keep hints
interface MtErrorArgMap {
'FLOOD_WAIT_%d': { duration: number },
}
type RpcErrorWithArgs<T extends string> =
RpcError & { text: T } & (T extends keyof MtErrorArgMap ? (RpcError & MtErrorArgMap[T]) : {});
export class RpcError extends Error {
static BAD_REQUEST: 400;
readonly code: number;
readonly text: MtErrorText;
readonly unknown: boolean;
constructor(code: number, text: MtErrorText);
is<const T extends MtErrorText>(text: T): this is RpcErrorWithArgs<T>;
static is<const T extends MtErrorText>(err: unknown): err is RpcError;
static is<const T extends MtErrorText>(err: unknown, text: T): err is RpcErrorWithArgs<T>;
static create<const T extends MtErrorText>(code: number, text: T): RpcErrorWithArgs<T>;
static fromTl(obj: object): RpcError;
}
"
,
"const _descriptionsMap = JSON.parse('{"FLOOD_WAIT_%d":"Wait %d seconds"}')
class RpcError extends Error {
constructor(code, text, description) {
super(description || 'Unknown RPC error: [' + code + ':' + text + ']');
this.code = code;
this.text = text;
}
static is(err, text) { return err.constructor === RpcError && (!text || err.text === text); }
is(text) { return this.text === text; }
}
RpcError.fromTl = function (obj) {
if (obj.errorMessage in _descriptionsMap) {
return new RpcError(obj.errorCode, obj.errorMessage, _descriptionsMap[obj.errorMessage]);
}
var err = new RpcError(obj.errorCode, obj.errorMessage);
var match, param;
if ((match=err.text.match(/^FLOOD_WAIT_(\d+)$/))!=null){ err.text = 'FLOOD_WAIT_%d'; param = err.duration = parseInt(match[1]) }
else return err
err.message = _descriptionsMap[err.text].replace('%d', param);
return err
}
RpcError.create = function(code, text) {
var desc = _descriptionsMap[text];
var err = new RpcError(code, text, desc);
if (!desc) {
err.unknown = true;
}
return err;
}
RpcError.BAD_REQUEST = 400;
exports.RpcError = RpcError;
"
,
]
`;

View file

@ -88,3 +88,92 @@ exports[`generateReaderCodeForTlEntry > generates code for constructors with vec
exports[`generateReaderCodeForTlEntry > generates code for constructors without arguments 1`] = `"2875595611:function(r){return{_:'topPeerCategoryBotsPM'}},"`; exports[`generateReaderCodeForTlEntry > generates code for constructors without arguments 1`] = `"2875595611:function(r){return{_:'topPeerCategoryBotsPM'}},"`;
exports[`generateReaderCodeForTlEntry > generates code with raw flags for constructors with flags 1`] = `"1554225816:function(r){var flags=r.uint(),flags2=r.uint();return{_:'test',flags:flags,flags2:flags2,}},"`; exports[`generateReaderCodeForTlEntry > generates code with raw flags for constructors with flags 1`] = `"1554225816:function(r){var flags=r.uint(),flags2=r.uint();return{_:'test',flags:flags,flags2:flags2,}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors without arguments 1`] = `"2875595611:function(r){return{_:'topPeerCategoryBotsPM'}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with simple arguments 1`] = `"2299280777:function(r){return{_:'inputBotInlineMessageID',dcId:r.int(),id:r.long(),accessHash:r.long(),}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with simple arguments 2`] = `"341499403:function(r){return{_:'contact',userId:r.long(),mutual:r.boolean(),}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with simple arguments 3`] = `"2933316530:function(r){return{_:'maskCoords',n:r.int(),x:r.double(),y:r.double(),zoom:r.double(),}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with true flags 1`] = `"649453030:function(r){var flags=r.uint();return{_:'messages.messageEditData',caption:!!(flags&1),}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with optional arguments 1`] = `"1041346555:function(r){var flags=r.uint();return{_:'updates.channelDifferenceEmpty',final:!!(flags&1),pts:r.int(),timeout:flags&2?r.int():void 0,}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with arguments before flags field 1`] = `"2262925665:function(r){var id=r.long(),flags=r.uint();return{_:'poll',id:id,quiz:!!(flags&8),question:r.string(),}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with multiple flags fields 1`] = `"1041346555:function(r){var flags=r.uint(),pts=r.int(),timeout=flags&2?r.int():void 0,flags2=r.uint();return{_:'updates.channelDifferenceEmpty',final:!!(flags&1),pts:pts,timeout:timeout,canDeleteChannel:!!(flags2&1),}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with vector arguments 1`] = `"2131196633:function(r){return{_:'contacts.resolvedPeer',peer:r.object(),chats:r.vector(r.object),users:r.vector(r.object),}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with optional vector arguments 1`] = `"2338894028:function(r){var flags=r.uint();return{_:'messages.getWebPagePreview',message:r.string(),entities:flags&8?r.vector(r.object):void 0,}},"`;
exports[`generateReaderCodeForTlEntry generates code for constructors with generics 1`] = `"3667594509:function(r){return{_:'invokeWithLayer',layer:r.int(),query:r.object(),}},"`;
exports[`generateReaderCodeForTlEntry generates code for bare types 1`] = `"1945237724:function(r){return{_:'msg_container',messages:r.vector(m[155834844],1),}},"`;
exports[`generateReaderCodeForTlEntry generates code for bare types 2`] = `"2924480661:function(r){return{_:'future_salts',salts:r.vector(m[155834844]),current:r.object(),}},"`;
exports[`generateReaderCodeForTlEntry generates code for bare types 3`] = `"2924480661:function(r){return{_:'future_salts',salts:r.vector(m[155834844],1),current:m[155834844](r),}},"`;
exports[`generateReaderCodeForTlEntry generates code with raw flags for constructors with flags 1`] = `"1554225816:function(r){var flags=r.uint(),flags2=r.uint();return{_:'test',flags:flags,flags2:flags2,}},"`;
exports[`generateReaderCodeForTlEntries method return readers includes primitive return type parsing info 1`] = `
"var m={
1809692154:function(r){return{_:'test1'}},
_results:{
'test':function(r){return r.int()},
},
}"
`;
exports[`generateReaderCodeForTlEntries method return readers includes primitive vectors return type parsing info 1`] = `
"var m={
_results:{
'test':function(r){return r.vector(r.int)},
},
}"
`;
exports[`generateReaderCodeForTlEntries method return readers includes primitive vectors return type parsing info 2`] = `
"var m={
_results:{
'test':function(r){return r.vector(r.int)},
},
}"
`;
exports[`generateReaderCodeForTlEntries method return readers doesn't include Bool parsing 1`] = `
"var m={
_results:{
},
}"
`;
exports[`generateReaderCodeForTlEntries generates code for multiple entries 1`] = `
"var m={
471282454:function(r){return{_:'test'}},
2119910527:function(r){return{_:'test2'}},
}"
`;
exports[`generateReaderCodeForTlEntries doesn't generate code for methods by default 1`] = `
"var m={
471282454:function(r){return{_:'test'}},
}"
`;
exports[`generateReaderCodeForTlEntries generates code for methods if asked to 1`] = `
"var m={
471282454:function(r){return{_:'test'}},
2119910527:function(r){return{_:'test2'}},
}"
`;
exports[`generateReaderCodeForTlEntries updates readers used in bare vectors 1`] = `
"var m={
471282454:function(r=this){return{_:'test'}},
3562390222:function(r){return{_:'test2',a:r.vector(m[471282454],1),}},
}"
`;

View file

@ -188,7 +188,7 @@ type TlObject =
exports[`generateTypescriptDefinitionsForTlSchema > writes schemas with methods 2`] = ` exports[`generateTypescriptDefinitionsForTlSchema > writes schemas with methods 2`] = `
"ns.isAnyTest = _isAny('Test'); "ns.isAnyTest = _isAny('Test');
_types = JSON.parse('{\\"test\\":\\"Test\\"}');" _types = JSON.parse('{"test":"Test"}');"
`; `;
exports[`generateTypescriptDefinitionsForTlSchema > writes schemas with multi-unions 1`] = ` exports[`generateTypescriptDefinitionsForTlSchema > writes schemas with multi-unions 1`] = `
@ -210,7 +210,7 @@ type TlObject =
exports[`generateTypescriptDefinitionsForTlSchema > writes schemas with multi-unions 2`] = ` exports[`generateTypescriptDefinitionsForTlSchema > writes schemas with multi-unions 2`] = `
"ns.isAnyTest = _isAny('Test'); "ns.isAnyTest = _isAny('Test');
_types = JSON.parse('{\\"test\\":\\"Test\\",\\"test2\\":\\"Test\\"}');" _types = JSON.parse('{"test":"Test","test2":"Test"}');"
`; `;
exports[`generateTypescriptDefinitionsForTlSchema > writes schemas with namespaces 1`] = ` exports[`generateTypescriptDefinitionsForTlSchema > writes schemas with namespaces 1`] = `
@ -270,7 +270,7 @@ ns.test = {};
(function(ns){ (function(ns){
ns.isAnyTest = _isAny('test.Test'); ns.isAnyTest = _isAny('test.Test');
})(ns.test); })(ns.test);
_types = JSON.parse('{\\"test\\":\\"Test\\",\\"test2\\":\\"Test\\",\\"test.test\\":\\"test.Test\\",\\"test.test2\\":\\"test.Test\\"}');" _types = JSON.parse('{"test":"Test","test2":"Test","test.test":"test.Test","test.test2":"test.Test"}');"
`; `;
exports[`generateTypescriptDefinitionsForTlSchema > writes simple schemas 1`] = ` exports[`generateTypescriptDefinitionsForTlSchema > writes simple schemas 1`] = `
@ -288,5 +288,296 @@ type TlObject =
exports[`generateTypescriptDefinitionsForTlSchema > writes simple schemas 2`] = ` exports[`generateTypescriptDefinitionsForTlSchema > writes simple schemas 2`] = `
"ns.isAnyTest = _isAny('Test'); "ns.isAnyTest = _isAny('Test');
_types = JSON.parse('{\\"test\\":\\"Test\\"}');" _types = JSON.parse('{"test":"Test"}');"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments adds tl style comments 1`] = `
"/**
* This is a test constructor
*/
interface RawTest {
_: 'test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments adds return type comments 1`] = `
"/**
* This is a test method
*
* RPC method returns {@link tl.TypeTest}
*/
interface RawTestRequest {
_: 'test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments adds return type comments 2`] = `
"/**
* This is a test method
*
* RPC method returns {@link tl.TypeTest}
*/
interface RawTestRequest {
_: 'test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments adds return type comments 3`] = `
"/**
* RPC method returns {@link tl.TypeTest} array
*/
interface RawTestRequest {
_: 'test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments adds usage info comments 1`] = `
"/**
* RPC method returns {@link tl.TypeTest}
*
* This method is **not** available for bots
*
* This method *may* throw one of these errors: FOO, BAR
*/
interface RawTestRequest {
_: 'test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments adds usage info comments 2`] = `
"/**
* RPC method returns {@link tl.TypeTest}
*
* This method is **not** available for normal users
*/
interface RawTestBotRequest {
_: 'testBot';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments adds tdlib style comments 1`] = `
"/**
* This is a test constructor
*/
interface RawTest {
_: 'test';
/**
* Some field
*/
field: number;
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments wraps long comments 1`] = `
"/**
* This is a test constructor with a very very very very very
* very very very long comment
*/
interface RawTest {
_: 'test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments wraps long comments 2`] = `
"/**
* This is a test method with a very very very very very very
* very very long comment
*
* RPC method returns {@link tl.TypeTest}
*/
interface RawTestRequest {
_: 'test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry comments should not break @link tags 1`] = `
"/**
* This is a test constructor with a very long comment
* {@link whatever} more text
*/
interface RawTest {
_: 'test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry replaces primitive types 1`] = `
"interface RawTest {
_: 'test';
a: number;
b: Long;
c: Double;
d: string;
e: Uint8Array;
f: boolean;
g: number[];
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry ignores namespace for name 1`] = `
"interface RawTest {
_: 'test.test';
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry renames non-primitive types 1`] = `
"interface RawTest {
_: 'test';
foo: tl.TypeFoo;
bar: tl.TypeBar[];
baz: tl.namespace.TypeBaz;
egg: tl.namespace.TypeEgg[];
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry marks optional fields as optional 1`] = `
"interface RawTest {
_: 'test';
a?: boolean;
b?: string;
c?: tl.TypeFoo;
d?: tl.namespace.TypeFoo[];
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry writes generic types 1`] = `
"interface RawInvokeWithoutUpdatesRequest<X extends tl.TlObject = tl.TlObject> {
_: 'invokeWithoutUpdates';
query: X;
}"
`;
exports[`generateTypescriptDefinitionsForTlEntry generates code with raw flags for constructors with flags 1`] = `
"interface RawTest {
_: 'test';
flags: number;
flags2: number;
}"
`;
exports[`generateTypescriptDefinitionsForTlSchema writes simple schemas 1`] = `
"interface RawTest {
_: 'test';
}
interface RpcCallReturn {
}
type TypeTest = tl.RawTest
function isAnyTest(o: object): o is TypeTest
type TlObject =
| tl.RawTest"
`;
exports[`generateTypescriptDefinitionsForTlSchema writes simple schemas 2`] = `
"ns.isAnyTest = _isAny('Test');
_types = JSON.parse('{"test":"Test"}');"
`;
exports[`generateTypescriptDefinitionsForTlSchema writes schemas with multi-unions 1`] = `
"interface RawTest {
_: 'test';
}
interface RawTest2 {
_: 'test2';
}
interface RpcCallReturn {
}
type TypeTest = tl.RawTest | tl.RawTest2
function isAnyTest(o: object): o is TypeTest
type TlObject =
| tl.RawTest
| tl.RawTest2"
`;
exports[`generateTypescriptDefinitionsForTlSchema writes schemas with multi-unions 2`] = `
"ns.isAnyTest = _isAny('Test');
_types = JSON.parse('{"test":"Test","test2":"Test"}');"
`;
exports[`generateTypescriptDefinitionsForTlSchema writes schemas with methods 1`] = `
"interface RawTest {
_: 'test';
}
/**
* RPC method returns {@link tl.TypeTest}
*/
interface RawGetTestRequest {
_: 'getTest';
}
interface RpcCallReturn {
'getTest': tl.TypeTest
}
type TypeTest = tl.RawTest
function isAnyTest(o: object): o is TypeTest
type RpcMethod =
| tl.RawGetTestRequest
type TlObject =
| tl.RawTest
| tl.RawGetTestRequest"
`;
exports[`generateTypescriptDefinitionsForTlSchema writes schemas with methods 2`] = `
"ns.isAnyTest = _isAny('Test');
_types = JSON.parse('{"test":"Test"}');"
`;
exports[`generateTypescriptDefinitionsForTlSchema writes schemas with namespaces 1`] = `
"interface RawTest {
_: 'test';
}
interface RawTest2 {
_: 'test2';
}
/**
* RPC method returns {@link tl.TypeTest}
*/
interface RawGetTestRequest {
_: 'getTest';
}
interface RpcCallReturn extends test.RpcCallReturn {
'getTest': tl.TypeTest
}
type TypeTest = tl.RawTest | tl.RawTest2
function isAnyTest(o: object): o is TypeTest
namespace test {
interface RawTest {
_: 'test.test';
}
interface RawTest2 {
_: 'test.test2';
}
/**
* RPC method returns {@link tl.test.TypeTest}
*/
interface RawGetTestRequest {
_: 'test.getTest';
}
interface RpcCallReturn {
'test.getTest': tl.test.TypeTest
}
type TypeTest = tl.test.RawTest | tl.test.RawTest2
function isAnyTest(o: object): o is TypeTest
}
type RpcMethod =
| tl.RawGetTestRequest
| tl.test.RawGetTestRequest
type TlObject =
| tl.RawTest
| tl.RawTest2
| tl.test.RawTest
| tl.test.RawTest2
| tl.RawGetTestRequest
| tl.test.RawGetTestRequest"
`;
exports[`generateTypescriptDefinitionsForTlSchema writes schemas with namespaces 2`] = `
"ns.isAnyTest = _isAny('Test');
ns.test = {};
(function(ns){
ns.isAnyTest = _isAny('test.Test');
})(ns.test);
_types = JSON.parse('{"test":"Test","test2":"Test","test.test":"test.Test","test.test2":"test.Test"}');"
`; `;

View file

@ -58,3 +58,62 @@ exports[`generateWriterCodeForTlEntry > generates code for constructors with vec
exports[`generateWriterCodeForTlEntry > generates code for constructors without arguments 1`] = `"'topPeerCategoryBotsPM':function(w){w.uint(2875595611);},"`; exports[`generateWriterCodeForTlEntry > generates code for constructors without arguments 1`] = `"'topPeerCategoryBotsPM':function(w){w.uint(2875595611);},"`;
exports[`generateWriterCodeForTlEntry > generates code with raw flags for constructors with flags 1`] = `"'test':function(w,v){w.uint(1554225816);var flags=v.flags;w.uint(flags);var flags2=v.flags2;w.uint(flags2);},"`; exports[`generateWriterCodeForTlEntry > generates code with raw flags for constructors with flags 1`] = `"'test':function(w,v){w.uint(1554225816);var flags=v.flags;w.uint(flags);var flags2=v.flags2;w.uint(flags2);},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors without arguments 1`] = `"'topPeerCategoryBotsPM':function(w){w.uint(2875595611);},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with simple arguments 1`] = `"'inputBotInlineMessageID':function(w,v){w.uint(2299280777);w.int(h(v,'dcId'));w.long(h(v,'id'));w.long(h(v,'accessHash'));},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with simple arguments 2`] = `"'contact':function(w,v){w.uint(341499403);w.long(h(v,'userId'));w.boolean(h(v,'mutual'));},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with simple arguments 3`] = `"'maskCoords':function(w,v){w.uint(2933316530);w.int(h(v,'n'));w.double(h(v,'x'));w.double(h(v,'y'));w.double(h(v,'zoom'));},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with true flags 1`] = `"'messages.messageEditData':function(w,v){w.uint(649453030);var flags=0;if(v.caption===true)flags|=1;w.uint(flags);},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with optional arguments 1`] = `"'updates.channelDifferenceEmpty':function(w,v){w.uint(1041346555);var flags=0;if(v.final===true)flags|=1;var _timeout=v.timeout!==undefined;if(_timeout)flags|=2;w.uint(flags);w.int(h(v,'pts'));if(_timeout)w.int(v.timeout);},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with multiple flags fields 1`] = `"'updates.channelDifferenceEmpty':function(w,v){w.uint(1041346555);var flags=0;if(v.final===true)flags|=1;var _timeout=v.timeout!==undefined;if(_timeout)flags|=2;w.uint(flags);w.int(h(v,'pts'));if(_timeout)w.int(v.timeout);var flags2=0;if(v.canDeleteChannel===true)flags2|=1;w.uint(flags2);},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with multiple fields using the same flag 1`] = `"'inputMediaPoll':function(w,v){w.uint(261416433);var flags=0;var _solution=v.solution!==undefined;var _solutionEntities=v.solutionEntities&&v.solutionEntities.length;var _flags_1=_solution||_solutionEntities;if(_flags_1)flags|=2;w.uint(flags);if(_flags_1)w.string(v.solution);if(_flags_1)w.vector(w.object,v.solutionEntities);},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with vector arguments 1`] = `"'contacts.resolvedPeer':function(w,v){w.uint(2131196633);w.object(h(v,'peer'));w.vector(w.object,h(v,'chats'));w.vector(w.object,h(v,'users'));},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with optional vector arguments 1`] = `"'messages.getWebPagePreview':function(w,v){w.uint(2338894028);var flags=0;var _entities=v.entities&&v.entities.length;if(_entities)flags|=8;w.uint(flags);w.string(h(v,'message'));if(_entities)w.vector(w.object,v.entities);},"`;
exports[`generateWriterCodeForTlEntry generates code for constructors with generics 1`] = `"'invokeWithLayer':function(w,v){w.uint(3667594509);w.int(h(v,'layer'));w.object(h(v,'query'));},"`;
exports[`generateWriterCodeForTlEntry generates code for bare vectors 1`] = `"'msg_container':function(w,v){w.uint(1945237724);w.vector(m._bare[155834844],h(v,'messages'),1);},"`;
exports[`generateWriterCodeForTlEntry generates code for bare vectors 2`] = `"'future_salts':function(w,v){w.uint(2924480661);w.vector(m._bare[155834844],h(v,'salts'));w.object(h(v,'current'));},"`;
exports[`generateWriterCodeForTlEntry generates code with raw flags for constructors with flags 1`] = `"'test':function(w,v){w.uint(1554225816);var flags=v.flags;w.uint(flags);var flags2=v.flags2;w.uint(flags2);},"`;
exports[`generateWriterCodeForTlEntry automatically computes constructor ID if needed 1`] = `"'topPeerCategoryBotsPM':function(w){w.uint(2875595611);},"`;
exports[`generateWriterCodeForTlEntries generates code for bare types 1`] = `
"var m={
'future_salt':function(w,v){w.uint(155834844);w.bytes(h(v,'salt'));},
'future_salts':function(w,v){w.uint(2924480661);w.vector(m._bare[155834844],h(v,'salts'),1);m._bare[155834844](w,h(v,'current'));},
_bare:{
155834844:function(w=this,v){w.bytes(h(v,'salt'));},
},
}"
`;
exports[`generateWriterCodeForTlEntries should include prelude by default 1`] = `
"function h(o,p){var q=o[p];if(q===void 0)throw Error('Object '+o._+' is missing required property '+p);return q}
var m={
}"
`;
exports[`generateWriterCodeForTlEntries should include static sizes calculations 1`] = `
"function h(o,p){var q=o[p];if(q===void 0)throw Error('Object '+o._+' is missing required property '+p);return q}
var m={
'test1':function(w,v){w.uint(102026291);w.int(h(v,'foo'));w.int(h(v,'bar'));},
'test2':function(w,v){w.uint(2926357645);w.int(h(v,'foo'));w.double(h(v,'bar'));},
'test3':function(w,v){w.uint(3373702963);w.int(h(v,'foo'));w.bytes(h(v,'bar'));},
_staticSize:{
'test1':12,
'test2':16,
},
}"
`;

File diff suppressed because it is too large Load diff