| 141 | /// Detect if code is in a test file or test context |
| 142 | #[allow(dead_code)] |
| 143 | pub 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)] |