Spaces:
Sleeping
Sleeping
File size: 3,106 Bytes
9bd4ce5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #[allow(unused_imports)]
use engine_rust::core::logic::{ActionFactory, CardDatabase, GameState, PendingInteraction, Phase};
use std::fs;
use std::path::Path;
#[test]
fn test_q103_dynamic_condition_resolution() {
let json_content = std::fs::read_to_string("../data/cards_compiled.json")
.expect("Failed to read cards_compiled.json");
let mut _db = CardDatabase::from_json(&json_content).unwrap();
}
/// Anti-drift test: Verify that legacy filter shift constants are NOT used
/// in engine source files outside of generated_constants.rs and generated_layout.rs.
/// All filter constants should use their canonical names (e.g., FILTER_GROUP_ID_SHIFT).
#[test]
fn test_filter_constant_usage_canonical_names_only() {
let src_dir = "../src";
let forbidden_patterns = vec![
"FILTER_GROUP_SHIFT", // Should be FILTER_GROUP_ID_SHIFT
"FILTER_UNIT_SHIFT", // Should be FILTER_UNIT_ID_SHIFT
"FILTER_SPECIAL_SHIFT", // Should be FILTER_SPECIAL_ID_SHIFT
"FILTER_COST_SHIFT", // Should be FILTER_VALUE_THRESHOLD_SHIFT
];
let generated_files = vec![
"generated_constants.rs",
"generated_layout.rs",
];
let mut violations = Vec::new();
fn scan_directory(
dir: &Path,
forbidden_patterns: &[&str],
generated_files: &[&str],
violations: &mut Vec<String>,
) {
if let Ok(entries) = fs::read_dir(dir) {
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
scan_directory(&path, forbidden_patterns, generated_files, violations);
} else if path.extension().map_or(false, |ext| ext == "rs") {
// Skip generated files
let filename = path.file_name().unwrap().to_string_lossy();
if generated_files.iter().any(|&gf| filename.contains(gf)) {
continue;
}
if let Ok(content) = fs::read_to_string(&path) {
for (line_num, line) in content.lines().enumerate() {
for pattern in forbidden_patterns {
if line.contains(pattern) {
violations.push(format!(
"{}:{}: Found forbidden pattern '{}' (use canonical name instead)",
path.display(),
line_num + 1,
pattern
));
}
}
}
}
}
}
}
}
scan_directory(Path::new(src_dir), &forbidden_patterns, &generated_files, &mut violations);
if !violations.is_empty() {
panic!(
"Anti-drift test FAILED: Found {} legacy filter constant usage(s):\n{}",
violations.len(),
violations.join("\n")
);
}
}
|