f5976a2d74
* feat: moved tl-runtime to esm and native ArrayBuffers * feat: migration to esm * fix(core): web-related fixes * test: finally, some good fucking e2e * chore: fixed linters etc * ci: added e2e to ci * build(tl): fixed gen-code on node 20 * fix: codegen Uint8Array, not Buffer never `git reset --hard` kids * build: only do type-aware linting for `packages/*` * build: ignore no-unresolved in ci for e2e * fix: node 16 doesn't have subtle crypto apparently? * fix(tests): use Uint8Array for gods sake please can i just merge this already * ci: don't parallel tasks in ci because machines are utter garbage and it may just randomly break * ci: pass secrets to e2e tests * ci: separate cli command for ci apparently im retarded * fix: run codegen in e2e im actually retarded * ci: more fixes for e2e * ci: debugging stuff * ci: still debugging * ci: hopefully fix ci???
109 lines
3.5 KiB
TypeScript
109 lines
3.5 KiB
TypeScript
import { expect } from 'chai'
|
|
import { describe, it } from 'mocha'
|
|
|
|
import { writeTlEntryToString } from '../src/stringify.js'
|
|
import { TlArgument, TlEntry } from '../src/types.js'
|
|
|
|
describe('writeTlEntryToString', () => {
|
|
const make = (name: string, type: string, ...args: string[]): TlEntry => ({
|
|
kind: 'class',
|
|
id: 0,
|
|
name,
|
|
type,
|
|
arguments: args.map((arg) => {
|
|
const a = arg.split(':')
|
|
const t = a[1].split('?')
|
|
|
|
if (t[1]) {
|
|
return {
|
|
name: a[0],
|
|
type: t[1],
|
|
typeModifiers: {
|
|
predicate: t[0],
|
|
},
|
|
} satisfies TlArgument
|
|
}
|
|
|
|
return {
|
|
name: a[0],
|
|
type: t[0],
|
|
} satisfies TlArgument
|
|
}),
|
|
})
|
|
|
|
const test = (tl: TlEntry, expected: string) => {
|
|
expect(writeTlEntryToString(tl)).eq(expected)
|
|
}
|
|
|
|
it('writes constructors without parameters', () => {
|
|
test(make('auth.logOut', 'Bool'), 'auth.logOut = Bool;')
|
|
test(make('auth.resetAuthorizations', 'Bool'), 'auth.resetAuthorizations = Bool;')
|
|
})
|
|
|
|
it('writes constructor id if available', () => {
|
|
const entry = make('auth.logOut', 'Bool')
|
|
entry.id = 0xaef001df
|
|
test(entry, 'auth.logOut#aef001df = Bool;')
|
|
})
|
|
|
|
it('writes constructors with simple parameters', () => {
|
|
test(
|
|
make('auth.exportAuthorization', 'auth.ExportedAuthorization', 'dc_id:int'),
|
|
'auth.exportAuthorization dc_id:int = auth.ExportedAuthorization;',
|
|
)
|
|
})
|
|
|
|
it('computes for constructors with vector parameters', () => {
|
|
test(
|
|
make('account.deleteSecureValue', 'Bool', 'types:Vector<SecureValueType>'),
|
|
'account.deleteSecureValue types:Vector<SecureValueType> = Bool;',
|
|
)
|
|
})
|
|
|
|
it('computes for constructors with vector return type', () => {
|
|
test(
|
|
make('account.getSecureValue', 'Vector<SecureValue>', 'types:Vector<SecureValueType>'),
|
|
'account.getSecureValue types:Vector<SecureValueType> = Vector<SecureValue>;',
|
|
)
|
|
})
|
|
|
|
it('computes for constructors with optional parameters', () => {
|
|
test(
|
|
make(
|
|
'account.uploadTheme',
|
|
'Document',
|
|
'flags:#',
|
|
'file:InputFile',
|
|
'thumb:flags.0?InputFile',
|
|
'file_name:string',
|
|
'mime_type:string',
|
|
),
|
|
'account.uploadTheme flags:# file:InputFile thumb:flags.0?InputFile file_name:string mime_type:string = Document;',
|
|
)
|
|
})
|
|
|
|
it('computes for constructors with optional true parameters', () => {
|
|
test(
|
|
make(
|
|
'account.installTheme',
|
|
'Bool',
|
|
'flags:#',
|
|
'dark:flags.0?true',
|
|
'format:flags.1?string',
|
|
'theme:flags.1?InputTheme',
|
|
),
|
|
'account.installTheme flags:# dark:flags.0?true format:flags.1?string theme:flags.1?InputTheme = Bool;',
|
|
)
|
|
})
|
|
|
|
it('computes for constructors with generics', () => {
|
|
const entry = make('invokeAfterMsg', 'X', 'msg_id:long', 'query:!X')
|
|
entry.generics = [
|
|
{
|
|
name: 'X',
|
|
type: 'Type',
|
|
},
|
|
]
|
|
test(entry, 'invokeAfterMsg {X:Type} msg_id:long query:!X = X;')
|
|
})
|
|
})
|