mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 14:01:37 +00:00
Refactor TODO list and enhance slugification for reserved names
- Updated the TODO list to consolidate and clarify tasks, removing outdated entries while retaining relevant ones. - Enhanced the slugification logic to treat "init" and its case variations as reserved names, ensuring they are properly suffixed with an underscore. - Added tests to verify the slugification behavior for reserved names, improving code reliability. These changes aim to streamline task management and ensure consistent handling of reserved names in the application.
This commit is contained in:
parent
d2f739ece6
commit
a15f4f1aa8
2 changed files with 67 additions and 13 deletions
|
|
@ -197,6 +197,9 @@ pub fn name_needs_slugify(name: &str) -> bool {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
if name_lower == "init" {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
|
|
@ -259,6 +262,9 @@ pub fn slugify_name(name: &str) -> String {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if result_lower == "init" {
|
||||
result.push('_');
|
||||
}
|
||||
|
||||
// If the result is empty or all underscores, use a fallback
|
||||
if result.is_empty() || result.chars().all(|c| c == '_') {
|
||||
|
|
@ -465,6 +471,13 @@ mod tests {
|
|||
assert_eq!(slugify_name("LPT1 "), "LPT1_");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slugify_init_reserved() {
|
||||
assert_eq!(slugify_name("init"), "init_");
|
||||
assert_eq!(slugify_name("Init"), "Init_");
|
||||
assert_eq!(slugify_name("INIT"), "INIT_");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slugify_trailing_dot() {
|
||||
// Trailing dots are stripped (invalid on Windows)
|
||||
|
|
@ -668,6 +681,14 @@ mod tests {
|
|||
assert!(name_needs_slugify("NUL"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn needs_slugify_init_reserved() {
|
||||
assert!(name_needs_slugify("init"));
|
||||
assert!(name_needs_slugify("Init"));
|
||||
assert!(name_needs_slugify("INIT"));
|
||||
assert!(!name_needs_slugify("init_"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn needs_slugify_leading_or_trailing_space() {
|
||||
assert!(name_needs_slugify("hello ")); // trailing
|
||||
|
|
@ -981,6 +1002,37 @@ mod tests {
|
|||
assert!(m);
|
||||
}
|
||||
|
||||
// ── Init reserved name through name_for_inst ─────────────────────
|
||||
|
||||
#[test]
|
||||
fn nfi_init_module_script() {
|
||||
let (f, m) = nfi("init", Middleware::ModuleScript, &[]);
|
||||
assert_eq!(f, "init_.luau");
|
||||
assert!(m, "init is reserved, needs meta name");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nfi_init_server_script() {
|
||||
let (f, m) = nfi("init", Middleware::ServerScript, &[]);
|
||||
assert_eq!(f, "init_.server.luau");
|
||||
assert!(m);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nfi_init_dir() {
|
||||
let (f, m) = nfi("init", Middleware::Dir, &[]);
|
||||
assert_eq!(f, "init_");
|
||||
assert!(m);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn nfi_init_case_insensitive_Init() {
|
||||
let (f, m) = nfi("Init", Middleware::ModuleScript, &[]);
|
||||
assert_eq!(f, "Init_.luau");
|
||||
assert!(m);
|
||||
}
|
||||
|
||||
// ── Safe dots pass through ───────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue