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???
134 lines
3.8 KiB
TypeScript
134 lines
3.8 KiB
TypeScript
import { expect } from 'chai'
|
|
import { describe, it } from 'mocha'
|
|
|
|
import { writeTlEntriesToString } from '../src/schema.js'
|
|
import { TlEntry } from '../src/types.js'
|
|
|
|
describe('writeTlEntriesToString', () => {
|
|
const test = (entries: TlEntry[], params: Parameters<typeof writeTlEntriesToString>[1], ...expected: string[]) => {
|
|
expect(
|
|
writeTlEntriesToString(entries, {
|
|
omitPrimitives: true,
|
|
...params,
|
|
}),
|
|
).eq(expected.join('\n'))
|
|
}
|
|
|
|
it('computes missing ids', () => {
|
|
const obj: TlEntry = {
|
|
kind: 'class',
|
|
name: 'error',
|
|
type: 'Error',
|
|
id: 0,
|
|
arguments: [
|
|
{
|
|
name: 'code',
|
|
type: 'int',
|
|
},
|
|
{
|
|
name: 'text',
|
|
type: 'string',
|
|
},
|
|
],
|
|
}
|
|
|
|
test([obj], { computeIds: false }, 'error code:int text:string = Error;')
|
|
test([obj], {}, 'error#c4b9f9bb code:int text:string = Error;')
|
|
})
|
|
|
|
it('writes comments along with the constructor', () => {
|
|
const obj: TlEntry = {
|
|
kind: 'class',
|
|
name: 'error',
|
|
type: 'Error',
|
|
id: 0,
|
|
arguments: [
|
|
{
|
|
name: 'code',
|
|
type: 'int',
|
|
comment: 'Error code',
|
|
},
|
|
{
|
|
name: 'text',
|
|
type: 'string',
|
|
comment: 'Error description',
|
|
},
|
|
],
|
|
comment: 'An error',
|
|
}
|
|
|
|
test([obj], {}, '// An error', 'error#c4b9f9bb code:int text:string = Error;')
|
|
|
|
obj.comment += '\nVery error'
|
|
test([obj], {}, '// An error', '//- Very error', 'error#c4b9f9bb code:int text:string = Error;')
|
|
})
|
|
|
|
it('writes tdlib-style comments', () => {
|
|
const obj: TlEntry = {
|
|
kind: 'class',
|
|
name: 'error',
|
|
type: 'Error',
|
|
id: 0,
|
|
arguments: [
|
|
{
|
|
name: 'code',
|
|
type: 'int',
|
|
comment: 'Error code',
|
|
},
|
|
{
|
|
name: 'text',
|
|
type: 'string',
|
|
comment: 'Error description',
|
|
},
|
|
],
|
|
comment: 'An error\nVery error',
|
|
}
|
|
|
|
test(
|
|
[obj],
|
|
{ tdlibComments: true },
|
|
'// @description An error',
|
|
'//- Very error',
|
|
'// @code Error code',
|
|
'// @text Error description',
|
|
'error#c4b9f9bb code:int text:string = Error;',
|
|
)
|
|
})
|
|
|
|
it('inserts kind annotation when kind changes', () => {
|
|
const cls: TlEntry = {
|
|
kind: 'class',
|
|
name: 'error',
|
|
type: 'Error',
|
|
id: 0,
|
|
arguments: [
|
|
{
|
|
name: 'code',
|
|
type: 'int',
|
|
},
|
|
{
|
|
name: 'text',
|
|
type: 'string',
|
|
},
|
|
],
|
|
}
|
|
const method: TlEntry = {
|
|
...cls,
|
|
kind: 'method',
|
|
}
|
|
|
|
test(
|
|
[method, cls, cls, method, cls],
|
|
{},
|
|
'---functions---',
|
|
'error#c4b9f9bb code:int text:string = Error;',
|
|
'---types---',
|
|
'error#c4b9f9bb code:int text:string = Error;',
|
|
'error#c4b9f9bb code:int text:string = Error;',
|
|
'---functions---',
|
|
'error#c4b9f9bb code:int text:string = Error;',
|
|
'---types---',
|
|
'error#c4b9f9bb code:int text:string = Error;',
|
|
)
|
|
})
|
|
})
|