mtcute/packages/tl-utils/tests/calculator.spec.ts
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* 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???
2023-10-16 19:23:53 +03:00

66 lines
2.3 KiB
TypeScript

import { expect } from 'chai'
import { describe, it } from 'mocha'
import { calculateStaticSizes } from '../src/calculator.js'
import { parseTlToEntries } from '../src/parse.js'
describe('calculateStaticSizes', () => {
const test = (tl: string, expected: object) => {
expect(calculateStaticSizes(parseTlToEntries(tl))).eql(expected)
}
it('computes for constructors without parameters', () => {
test('auth.logOut = Bool;', { 'auth.logOut': 4 })
})
it('computes for constructors with static parameters', () => {
test('auth.exportAuthorization#e5bfffcd dc_id:int = auth.ExportedAuthorization;', {
'auth.exportAuthorization': 8,
})
})
it('correctly skips true fields', () => {
test('help.promoData#8c39793f flags:# proxy:flags.0?true expires:int = help.PromoData;', {
'help.promoData': 12,
})
})
it('correctly skips constructors with predicated fields', () => {
test(
'help.promoData#8c39793f flags:# proxy:flags.0?true expires:int peer:Peer psa_type:flags.1?string psa_message:flags.2?string = help.PromoData;',
{},
)
})
it('correctly skips constructors with non-static fields', () => {
test('help.promoData#8c39793f psa_type:string psa_message:string = help.PromoData;', {})
})
it('correctly skips constructors with vector fields', () => {
test('help.promoData#8c39793f psa_type:Vector<int> = help.PromoData;', {})
})
it('correctly handles static-sized children', () => {
test(
'peerUser#9db1bc6d user_id:int53 = Peer;\n' +
'help.promoData#8c39793f flags:# proxy:flags.0?true expires:int peer:peerUser = help.PromoData;',
{
peerUser: 12,
'help.promoData': 20,
},
)
})
it('correctly handles static-sized union children', () => {
test(
'peerUser#9db1bc6d user_id:int53 = Peer;\n' +
'peerChannel#9db1bc6d channel_id:int53 = Peer;\n' +
'help.promoData#8c39793f flags:# proxy:flags.0?true expires:int peer:Peer = help.PromoData;',
{
peerUser: 12,
peerChannel: 12,
'help.promoData': 24,
},
)
})
})