Skip to content

Commit

Permalink
Expand macro tests
Browse files Browse the repository at this point in the history
commit-id:bcac35f1
  • Loading branch information
Draggu committed Dec 13, 2024
1 parent 4d06c54 commit f2455cc
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
98 changes: 98 additions & 0 deletions ui-test/expand_macro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { EditorView, TextEditor, VSBrowser, Workbench } from "vscode-extension-tester";
import { expect } from "chai";
import { isScarbAvailable } from "../test-support/scarb";
import * as path from "path";

describe("Expand macro test", function () {
this.timeout(50000);

let editorView: EditorView;

before(async function () {
if (!isScarbAvailable) {
this.skip();
}

editorView = new EditorView();

await VSBrowser.instance.openResources(path.join("ui-test", "fixtures", "expand_macro"));
});

afterEach(async function () {
await editorView.closeAllEditors();
});

it("checks if macro correctly expands", async function () {
assertExpandAt(
editorView,
1,
1,
`// lib.cairo
// ---------
#[generate_trait]
impl A of ATrait {
fn lol() -> u32 {
12
}
}
// generate_trait
// --------------
trait ATrait {
fn lol() -> u32;
}`,
);
});
it("checks if inline macro correctly expands", async function () {
assertExpandAt(
editorView,
9,
8,
`// lib.cairo
// ---------
{
let mut __formatter_for_print_macros__: core::fmt::Formatter = core::traits::Default::default();
core::result::ResultTrait::<
(), core::fmt::Error,
>::unwrap(
{
core::byte_array::ByteArrayTrait::append_word(
ref __formatter_for_print_macros__.buffer, 0x617364660a, 5,
);
core::result::Result::<(), core::fmt::Error>::Ok(())
},
);
core::debug::print_byte_array_as_string(@__formatter_for_print_macros__.buffer);
}`,
);
});
});

async function assertExpandAt(
editorView: EditorView,
line: number,
column: number,
expansionCode: string,
) {
await VSBrowser.instance.openResources(
path.join("ui-test", "fixtures", "expand_macro", "src", "lib.cairo"),
);

// This points to current active editor.
const editor = new TextEditor();

await editor.moveCursor(line, column);

const workbench = new Workbench();

await workbench.executeCommand("Cairo: Recursively expand macros for item at caret");

const expansion = await editorView.openEditor("[EXPANSION].cairo", 1);

const expansionText = await expansion.getText();

expect(expansionText).to.be.eq(expansionCode);
}
6 changes: 6 additions & 0 deletions ui-test/fixtures/expand_macro/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "expand_macro"
version = "0.1.0"
3 changes: 3 additions & 0 deletions ui-test/fixtures/expand_macro/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "expand_macro"
version = "0.1.0"
10 changes: 10 additions & 0 deletions ui-test/fixtures/expand_macro/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[generate_trait]
impl A of ATrait {
fn lol() -> u32 {
12
}
}

fn b() {
println!("asdf");
}

0 comments on commit f2455cc

Please sign in to comment.