-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48e986e
commit bad4cb8
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
||
}) | ||
}) |