obfuskator/crates/noxis-analysis/tests/keep.rs
loki5512344 c3acc0baf4
analysis: lock DTO fields passed as X.class to databind calls
Gson/Jackson/fastjson2/Moshi bind fields by reflection from a Class
literal, with no field-name string for the string-based detection:
renaming such a field silently breaks deserialization. Absorb_databind
finds the nearest Const::Class before fromJson/readValue/parseObject/
adapter calls (10-insn window, control-flow boundaries stop the search)
and keeps every field of that class; the class itself still renames.

Tests: noxis-analysis/tests/dto.rs (red first), keep unit tests moved
to tests/keep.rs (file budget). Code comments migrated to English.
2026-10-09 13:51:35 +02:00

33 lines
992 B
Rust

//! Keep-rule unit tests: globs and exact names.
#![allow(clippy::expect_used, clippy::unwrap_used)]
use noxis_analysis::KeepRules;
use noxis_core::Config;
fn rules_with_patterns() -> KeepRules {
KeepRules::from_config(&Config {
keep: vec!["com/example/*".to_string(), "**/internal/**".to_string()],
keep_resources: vec!["META-INF/services/*".to_string()],
..Config::default()
})
.expect("patterns")
}
#[test]
fn glob_semantics() {
let rules = rules_with_patterns();
assert!(rules.keeps_class("com/example/Main"));
assert!(!rules.keeps_class("com/example/sub/Main"));
assert!(rules.keeps_class("x/internal/y/Z"));
assert!(rules.keeps_resource("META-INF/services/a.b.C"));
assert!(!rules.keeps_resource("assets/mc/mod.json"));
}
#[test]
fn exact_names_win() {
let mut rules = KeepRules::default();
rules.keep_exact("app/Main");
assert!(rules.keeps_class("app/Main"));
assert!(!rules.keeps_class("app/Other"));
}