From bad4cb87d3d52500efae6a76742f53c45a0501c2 Mon Sep 17 00:00:00 2001 From: polyprogrammist Date: Tue, 21 Nov 2023 09:43:55 -0500 Subject: [PATCH] first test --- tests/tlbgen.spec.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/tlbgen.spec.ts diff --git a/tests/tlbgen.spec.ts b/tests/tlbgen.spec.ts new file mode 100644 index 0000000..a1096e6 --- /dev/null +++ b/tests/tlbgen.spec.ts @@ -0,0 +1,54 @@ +import fs from 'fs' +import path from 'path' +import util from 'util' + +import { parse } from '../src' +import { ast } from '../src' +import { generate } from '../src/codegen/main' +import { Program } from '../src/ast/nodes' + +import { X, loadX, storeX } from '../generated_test' +import { beginCell } from 'ton' + +const fixturesDir = path.resolve(__dirname, 'fixtures') + +function deepEqual(object1: any, object2: any) { + const keys1 = Object.keys(object1); + const keys2 = Object.keys(object2); + + if (keys1.length !== keys2.length) { + return false; + } + + for (const key of keys1) { + const val1 = object1[key]; + const val2 = object2[key]; + const areObjects = isObject(val1) && isObject(val2); + if ( + areObjects && !deepEqual(val1, val2) || + !areObjects && val1 !== val2 + ) { + return false; + } + } + + return true; + } + + function isObject(object: any) { + return object != null && typeof object === 'object'; + } + +describe('parsing into intermediate representation using grammar', () => { + test('test.tlb can be parsed', () => { + expect.hasAssertions() + + + let xExpected: X = { kind: 'X', a: 827, b: 387 } + let cell = beginCell(); + storeX(xExpected)(cell); + let xActual: X = loadX(cell.endCell().beginParse()) + expect(deepEqual(xExpected, xActual)).toBeTruthy() + + }) +})