Skip to content

Commit 074ced4

Browse files
committed
test(native): add unit tests for extract_inline_new_type edge cases
Cover the string-parsing logic in extract_inline_new_type: (new Foo), (new Foo('arg')), no-parens form, _ and $ prefixes, lowercase rejection, plain identifier, and the newFoo-not-a-keyword case.
1 parent 4e579b0 commit 074ced4

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

crates/codegraph-core/src/edge_builder.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,3 +1406,52 @@ mod call_edge_tests {
14061406
assert_eq!(receiver_edge.unwrap().target_id, 2);
14071407
}
14081408
}
1409+
1410+
#[cfg(test)]
1411+
mod inline_new_type_tests {
1412+
use super::extract_inline_new_type;
1413+
1414+
#[test]
1415+
fn parens_new_uppercase() {
1416+
assert_eq!(extract_inline_new_type("(new Foo)"), Some("Foo".to_string()));
1417+
}
1418+
1419+
#[test]
1420+
fn parens_new_with_args() {
1421+
// (new Foo('arg')) — parens and constructor args
1422+
assert_eq!(extract_inline_new_type("(new Foo('arg'))"), Some("Foo".to_string()));
1423+
}
1424+
1425+
#[test]
1426+
fn no_parens_new_uppercase() {
1427+
assert_eq!(extract_inline_new_type("new Bar"), Some("Bar".to_string()));
1428+
}
1429+
1430+
#[test]
1431+
fn underscore_prefix_accepted() {
1432+
assert_eq!(extract_inline_new_type("new _Factory"), Some("_Factory".to_string()));
1433+
}
1434+
1435+
#[test]
1436+
fn dollar_prefix_accepted() {
1437+
assert_eq!(extract_inline_new_type("new $Service"), Some("$Service".to_string()));
1438+
}
1439+
1440+
#[test]
1441+
fn lowercase_constructor_rejected() {
1442+
// `new foo()` — lowercase, should return None to avoid false positives
1443+
assert_eq!(extract_inline_new_type("new foo"), None);
1444+
}
1445+
1446+
#[test]
1447+
fn not_a_new_expression() {
1448+
// plain receiver name — no `new` keyword
1449+
assert_eq!(extract_inline_new_type("myVar"), None);
1450+
}
1451+
1452+
#[test]
1453+
fn new_without_whitespace_is_not_new_keyword() {
1454+
// `newFoo` — not a `new` keyword, just an identifier
1455+
assert_eq!(extract_inline_new_type("newFoo"), None);
1456+
}
1457+
}

0 commit comments

Comments
 (0)