use sdivi_patterns::queries::{classify_hint, http_routing};
use sdivi_patterns::PatternHintInput;
fn call_expr(text: &str) -> PatternHintInput {
PatternHintInput {
node_kind: "call_expression".to_string(),
text: text.to_string(),
}
}
#[test]
fn nextjs_app_router_bare_get_is_not_http_routing() {
assert!(
!http_routing::matches_callee("GET(request)", "typescript"),
"bare GET() without a receiver must not match http_routing"
);
}
#[test]
fn nextjs_app_router_bare_post_is_not_http_routing() {
assert!(
!http_routing::matches_callee("POST(request)", "typescript"),
"bare POST() without a receiver must not match http_routing"
);
}
#[test]
fn nextjs_app_router_bare_put_is_not_http_routing() {
assert!(!http_routing::matches_callee("PUT(request)", "typescript"));
}
#[test]
fn nextjs_app_router_bare_delete_is_not_http_routing() {
assert!(!http_routing::matches_callee(
"DELETE(request)",
"typescript"
));
}
#[test]
fn nextjs_app_router_bare_patch_is_not_http_routing() {
assert!(!http_routing::matches_callee(
"PATCH(request)",
"typescript"
));
}
#[test]
fn classify_hint_bare_get_is_not_http_routing() {
let result = classify_hint(&call_expr("GET(request)"), "typescript");
assert!(
!result.contains(&"http_routing"),
"classify_hint must not return http_routing for bare GET(); got {result:?}"
);
}
#[test]
fn idiosyncratic_api_receiver_is_not_http_routing() {
assert!(
!http_routing::matches_callee("api.get('/path', h)", "typescript"),
"receiver `api` is not in the allowlist"
);
}
#[test]
fn idiosyncratic_hono_variable_is_not_http_routing() {
assert!(!http_routing::matches_callee(
"hono.get('/path', h)",
"typescript"
));
}
#[test]
fn idiosyncratic_my_router_variable_is_not_http_routing() {
assert!(!http_routing::matches_callee(
"myRouter.get('/path', h)",
"typescript"
));
}
#[test]
fn idiosyncratic_app2_variable_is_not_http_routing() {
assert!(!http_routing::matches_callee(
"app2.get('/path', h)",
"typescript"
));
}
#[test]
fn classify_hint_idiosyncratic_receiver_falls_through_to_data_access() {
let result = classify_hint(&call_expr("api.get('/path', h)"), "typescript");
assert!(
!result.contains(&"http_routing"),
"idiosyncratic receiver `api` must not resolve to http_routing; got {result:?}"
);
}
#[test]
fn go_engine_group_via_classify_hint() {
assert_eq!(
classify_hint(&call_expr("engine.Group(\"/api\")"), "go"),
vec!["http_routing"]
);
}
#[test]
fn go_g_get_via_classify_hint() {
assert_eq!(
classify_hint(&call_expr("g.GET(\"/users\", h)"), "go"),
vec!["http_routing"]
);
}
#[test]
fn go_rg_post_via_classify_hint() {
assert_eq!(
classify_hint(&call_expr("rg.POST(\"/user\", h)"), "go"),
vec!["http_routing"]
);
}
#[test]
fn go_router_delete_via_classify_hint() {
assert_eq!(
classify_hint(&call_expr("router.DELETE(\"/user/:id\", h)"), "go"),
vec!["http_routing"]
);
}
#[test]
fn go_mux_any_via_classify_hint() {
assert_eq!(
classify_hint(&call_expr("mux.Any(\"/\", h)"), "go"),
vec!["http_routing"]
);
}
#[test]
fn go_e_patch_via_classify_hint() {
assert_eq!(
classify_hint(&call_expr("e.PATCH(\"/item/:id\", h)"), "go"),
vec!["http_routing"]
);
}
#[test]
fn python_blueprint_add_url_rule_via_classify_hint() {
assert_eq!(
classify_hint(
&call_expr("bp.add_url_rule('/users', view_func=h)"),
"python"
),
vec!["http_routing"]
);
}
#[test]
fn python_any_receiver_add_url_rule_matches_callee() {
assert!(http_routing::matches_callee(
"x.add_url_rule('/p', view_func=h)",
"python"
));
}