From 3bace4dfd60922aeae6782344e3e0b75fabbd9b5 Mon Sep 17 00:00:00 2001 From: Piotr Figiela <77412592+Draggu@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:16:04 +0100 Subject: [PATCH] Expand macro tests commit-id:bcac35f1 --- ui-test/expand_macro.ts | 98 +++++++++++++++++++++ ui-test/fixtures/expand_macro/Scarb.lock | 6 ++ ui-test/fixtures/expand_macro/Scarb.toml | 3 + ui-test/fixtures/expand_macro/src/lib.cairo | 10 +++ 4 files changed, 117 insertions(+) create mode 100644 ui-test/expand_macro.ts create mode 100644 ui-test/fixtures/expand_macro/Scarb.lock create mode 100644 ui-test/fixtures/expand_macro/Scarb.toml create mode 100644 ui-test/fixtures/expand_macro/src/lib.cairo diff --git a/ui-test/expand_macro.ts b/ui-test/expand_macro.ts new file mode 100644 index 0000000..55df596 --- /dev/null +++ b/ui-test/expand_macro.ts @@ -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 (!(await 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); +} diff --git a/ui-test/fixtures/expand_macro/Scarb.lock b/ui-test/fixtures/expand_macro/Scarb.lock new file mode 100644 index 0000000..79c3d36 --- /dev/null +++ b/ui-test/fixtures/expand_macro/Scarb.lock @@ -0,0 +1,6 @@ +# Code generated by scarb DO NOT EDIT. +version = 1 + +[[package]] +name = "expand_macro" +version = "0.1.0" diff --git a/ui-test/fixtures/expand_macro/Scarb.toml b/ui-test/fixtures/expand_macro/Scarb.toml new file mode 100644 index 0000000..966a020 --- /dev/null +++ b/ui-test/fixtures/expand_macro/Scarb.toml @@ -0,0 +1,3 @@ +[package] +name = "expand_macro" +version = "0.1.0" diff --git a/ui-test/fixtures/expand_macro/src/lib.cairo b/ui-test/fixtures/expand_macro/src/lib.cairo new file mode 100644 index 0000000..a080af9 --- /dev/null +++ b/ui-test/fixtures/expand_macro/src/lib.cairo @@ -0,0 +1,10 @@ +#[generate_trait] +impl A of ATrait { + fn lol() -> u32 { + 12 + } +} + +fn b() { + println!("asdf"); +}