MCPcopy Create free account
hub / github.com/KingOfBugbounty/enumrust / is_test_code

Function is_test_code

src/secret_validators.rs:143–163  ·  view source on GitHub ↗
(content: &str, position: usize)

Source from the content-addressed store, hash-verified

141/// Detect if code is in a test file or test context
142#[allow(dead_code)]
143pub fn is_test_code(content: &str, position: usize) -> bool {
144 let test_indicators = [
145 "describe(", "it(", "test(", "expect(",
146 "jest.mock", "sinon.stub", "chai.",
147 "beforeEach", "afterEach", "beforeAll", "afterAll",
148 "// Test", "// Example", "// Demo",
149 "__tests__", ".test.js", ".spec.js",
150 "mocha", "jasmine", "qunit", "vitest",
151 "TestCase", "unittest", "pytest",
152 "Mock", "Stub", "Spy", "Fake",
153 ];
154
155 // Check within 500 chars before position
156 let start = position.saturating_sub(500);
157 let end = (position + 100).min(content.len());
158 let nearby_content = &content[start..end];
159
160 test_indicators.iter().any(|indicator| {
161 nearby_content.contains(indicator)
162 })
163}
164
165/// Detect if content contains example/documentation indicators
166#[allow(dead_code)]

Callers 1

analyze_contextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected