feat: Added option to rename struct in Lua

This commit is contained in:
2025-09-17 01:04:37 +02:00
parent cef241546e
commit 6086dec859
6 changed files with 72 additions and 2 deletions

23
tests/rename.rs Normal file
View File

@@ -0,0 +1,23 @@
use lua_typed::Typed;
#[derive(Typed)]
#[typed(as = "Lua")]
struct Rust;
#[derive(Typed)]
struct Other {
pub rust: Rust,
}
#[test]
fn rename() {
insta::assert_snapshot!(<Rust as Typed>::generate_full().unwrap(), @"---@class Lua");
}
#[test]
fn rename_nested() {
insta::assert_snapshot!(<Other as Typed>::generate_full().unwrap(), @r"
---@class Other
---@field rust Lua
");
}

7
tests/ui/empty_rename.rs Normal file
View File

@@ -0,0 +1,7 @@
use lua_typed::Typed;
#[derive(Typed)]
#[typed(as = "")]
struct A;
fn main() {}

View File

@@ -0,0 +1,5 @@
error: Name is not allowed to be empty
--> tests/ui/empty_rename.rs:4:14
|
4 | #[typed(as = "")]
| ^^

View File

@@ -0,0 +1,7 @@
use lua_typed::Typed;
#[derive(Typed)]
#[typed(cool)]
struct A;
fn main() {}

View File

@@ -0,0 +1,5 @@
error: Unknown attribute
--> tests/ui/unknown_attribute.rs:4:9
|
4 | #[typed(cool)]
| ^^^^