Skip to content

Commit 92b58db

Browse files
committed
test(native): cover arrow-function path and assert C.bar metrics (#1347)
- Add prototype_arrow_function_method_emits_definition test for the arrow_function RHS branch of emit_js_prototype_method, which was fixed but had no test coverage - Assert complexity.is_some() and cfg.is_some() for C.bar in prototype_object_literal_emits_definitions, matching the assertions already added for C.foo
1 parent e720083 commit 92b58db

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

crates/codegraph-core/src/extractors/javascript.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,6 +2454,20 @@ mod tests {
24542454
assert!(def.cfg.is_some(), "C.foo should have a CFG");
24552455
}
24562456

2457+
#[test]
2458+
fn prototype_arrow_function_method_emits_definition() {
2459+
let s = parse_js(
2460+
"function C() {}\n\
2461+
C.prototype.foo = () => { return 1; };",
2462+
);
2463+
let def = s.definitions.iter().find(|d| d.name == "C.foo");
2464+
assert!(def.is_some(), "C.foo definition missing; got: {:?}", s.definitions.iter().map(|d| &d.name).collect::<Vec<_>>());
2465+
let def = def.unwrap();
2466+
assert_eq!(def.kind, "method");
2467+
assert!(def.complexity.is_some(), "C.foo (arrow) should have complexity metrics");
2468+
assert!(def.cfg.is_some(), "C.foo (arrow) should have a CFG");
2469+
}
2470+
24572471
#[test]
24582472
fn prototype_identifier_alias_seeds_type_map() {
24592473
let s = parse_js(
@@ -2483,6 +2497,10 @@ mod tests {
24832497
assert!(foo.complexity.is_some(), "C.foo should have complexity metrics");
24842498
assert!(foo.cfg.is_some(), "C.foo should have a CFG");
24852499
assert!(bar.is_some(), "C.bar missing");
2500+
let bar = bar.unwrap();
2501+
assert_eq!(bar.kind, "method");
2502+
assert!(bar.complexity.is_some(), "C.bar should have complexity metrics");
2503+
assert!(bar.cfg.is_some(), "C.bar should have a CFG");
24862504
}
24872505

24882506
#[test]

0 commit comments

Comments
 (0)