Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for asm instructions without whitespace #1393

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 151 additions & 0 deletions src/grammar/next/__snapshots__/grammar.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,157 @@ exports[`grammar should parse abstract-const 1`] = `
}
`;

exports[`grammar should parse asm-instruction-no-whitespace-1 1`] = `
{
"id": 6,
"imports": [],
"items": [
{
"attributes": [],
"id": 3,
"instructions": [
"b{00} PUSHSLICE",
],
"kind": "asm_function_def",
"loc": asm fun Bar(): Address { b{00} PUSHSLICE},
"name": {
"id": 1,
"kind": "id",
"loc": Bar,
"text": "Bar",
},
"params": [],
"return": {
"id": 2,
"kind": "type_id",
"loc": Address,
"text": "Address",
},
"shuffle": {
"args": [],
"ret": [],
},
},
{
"attributes": [],
"declarations": [],
"id": 5,
"kind": "contract",
"loc": contract Foo { },
"name": {
"id": 4,
"kind": "id",
"loc": Foo,
"text": "Foo",
},
"traits": [],
},
],
"kind": "module",
}
`;

exports[`grammar should parse asm-instruction-no-whitespace-2 1`] = `
{
"id": 6,
"imports": [],
"items": [
{
"attributes": [],
"id": 3,
"instructions": [
"42 PUSHINT",
],
"kind": "asm_function_def",
"loc": asm fun push42(): Int {
42 PUSHINT},
"name": {
"id": 1,
"kind": "id",
"loc": push42,
"text": "push42",
},
"params": [],
"return": {
"id": 2,
"kind": "type_id",
"loc": Int,
"text": "Int",
},
"shuffle": {
"args": [],
"ret": [],
},
},
{
"attributes": [],
"declarations": [],
"id": 5,
"kind": "contract",
"loc": contract Foo { },
"name": {
"id": 4,
"kind": "id",
"loc": Foo,
"text": "Foo",
},
"traits": [],
},
],
"kind": "module",
}
`;

exports[`grammar should parse asm-instruction-no-whitespace-3 1`] = `
{
"id": 6,
"imports": [],
"items": [
{
"attributes": [],
"id": 3,
"instructions": [
"-ROT ADD MUL",
],
"kind": "asm_function_def",
"loc": asm fun Bar(): Int {-ROT ADD MUL},
"name": {
"id": 1,
"kind": "id",
"loc": Bar,
"text": "Bar",
},
"params": [],
"return": {
"id": 2,
"kind": "type_id",
"loc": Int,
"text": "Int",
},
"shuffle": {
"args": [],
"ret": [],
},
},
{
"attributes": [],
"declarations": [],
"id": 5,
"kind": "contract",
"loc": contract Foo { },
"name": {
"id": 4,
"kind": "id",
"loc": Foo,
"text": "Foo",
},
"traits": [],
},
],
"kind": "module",
}
`;

exports[`grammar should parse block-statements 1`] = `
{
"id": 10,
Expand Down
16 changes: 10 additions & 6 deletions src/grammar/next/grammar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ expect.addSnapshotSerializer({
});

describe("grammar", () => {
for (const r of loadCases(__dirname + "/../test/")) {
it("should parse " + r.name, () => {
const ast = getAstFactory();
const { parse } = getParser(ast, "new");
expect(parse(r.code, "<unknown>", "user")).toMatchSnapshot();
});
const shouldParsePaths = [__dirname + "/../test/", __dirname + "/test/"];

for (const path of shouldParsePaths) {
for (const r of loadCases(path)) {
it("should parse " + r.name, () => {
const ast = getAstFactory();
const { parse } = getParser(ast, "new");
anton-trunov marked this conversation as resolved.
Show resolved Hide resolved
expect(parse(r.code, "<unknown>", "user")).toMatchSnapshot();
});
}
}

for (const r of loadCases(__dirname + "/../test-failed/")) {
Expand Down
3 changes: 3 additions & 0 deletions src/grammar/next/test/asm-instruction-no-whitespace-1.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
asm fun Bar(): Address { b{00} PUSHSLICE}

contract Foo { }
4 changes: 4 additions & 0 deletions src/grammar/next/test/asm-instruction-no-whitespace-2.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
asm fun push42(): Int {
42 PUSHINT}

contract Foo { }
3 changes: 3 additions & 0 deletions src/grammar/next/test/asm-instruction-no-whitespace-3.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
asm fun Bar(): Int {-ROT ADD MUL}

contract Foo { }
Loading