|
| 1 | +/* |
| 2 | + * Jest tests for inspectTokenScopesHandler functionality in VSCode extension. |
| 3 | + * Uses real vscode-textmate and vscode-oniguruma libraries for actual grammar testing. |
| 4 | + */ |
| 5 | + |
| 6 | +import * as path from 'path'; |
| 7 | +import * as fs from 'fs'; |
| 8 | +import { tokenizeContent } from '../commands/inspectTokenScopes'; |
| 9 | + |
| 10 | +// Read the actual app.jac file |
| 11 | +const appJacPath = path.join(process.cwd(), 'examples', 'app.jac'); |
| 12 | +const appJacContent = fs.readFileSync(appJacPath, 'utf-8'); |
| 13 | + |
| 14 | +// Paths for grammar and wasm |
| 15 | +const grammarPath = path.join(process.cwd(), 'syntaxes', 'jac.tmLanguage.json'); |
| 16 | +const wasmPath = path.join(process.cwd(), 'node_modules', 'vscode-oniguruma', 'release', 'onig.wasm'); |
| 17 | + |
| 18 | +describe('inspectTokenScopesHandler', () => { |
| 19 | + test('should tokenize Jac keywords correctly', async () => { |
| 20 | + const tokenMap = await tokenizeContent(appJacContent, grammarPath, wasmPath); |
| 21 | + |
| 22 | + // Check 'with' keyword (storage.type.function.jac) |
| 23 | + const withScopes = tokenMap.get('with'); |
| 24 | + expect(withScopes).toBeDefined(); |
| 25 | + expect(withScopes).toContain('source.jac'); |
| 26 | + expect(withScopes).toContain('storage.type.function.jac'); |
| 27 | + |
| 28 | + // Check 'entry' keyword |
| 29 | + const entryScopes = tokenMap.get('entry'); |
| 30 | + expect(entryScopes).toBeDefined(); |
| 31 | + expect(entryScopes).toContain('keyword.control.flow.jac'); |
| 32 | + |
| 33 | + // Check 'lambda' keyword |
| 34 | + const lambdaScopes = tokenMap.get('lambda'); |
| 35 | + expect(lambdaScopes).toBeDefined(); |
| 36 | + expect(lambdaScopes).toContain('keyword.control.flow.jac'); |
| 37 | + |
| 38 | + // Check 'print' builtin |
| 39 | + const printScopes = tokenMap.get('print'); |
| 40 | + expect(printScopes).toBeDefined(); |
| 41 | + expect(printScopes).toContain('support.function.builtin.jac'); |
| 42 | + }); |
| 43 | + |
| 44 | + test('should tokenize JSX elements correctly', async () => { |
| 45 | + const tokenMap = await tokenizeContent(appJacContent, grammarPath, wasmPath); |
| 46 | + |
| 47 | + // Check that we have JSX-related tokens |
| 48 | + const allScopes = Array.from(tokenMap.values()).flat(); |
| 49 | + |
| 50 | + // Check for meta.jsx scope or entity.name.tag for JSX elements |
| 51 | + const hasJsxScopes = allScopes.some(s => |
| 52 | + s.includes('jsx') || |
| 53 | + s.includes('entity.name.tag') || |
| 54 | + s.includes('punctuation.definition.tag') |
| 55 | + ); |
| 56 | + expect(hasJsxScopes).toBe(true); |
| 57 | + |
| 58 | + // Check specific JSX HTML tags |
| 59 | + const divScopes = tokenMap.get('div'); |
| 60 | + expect(divScopes).toBeDefined(); |
| 61 | + expect(divScopes).toContain('entity.name.tag.html.jsx.jac'); |
| 62 | + |
| 63 | + const h1Scopes = tokenMap.get('h1'); |
| 64 | + expect(h1Scopes).toBeDefined(); |
| 65 | + expect(h1Scopes).toContain('entity.name.tag.html.jsx.jac'); |
| 66 | + |
| 67 | + const buttonScopes = tokenMap.get('button'); |
| 68 | + expect(buttonScopes).toBeDefined(); |
| 69 | + expect(buttonScopes).toContain('entity.name.tag.html.jsx.jac'); |
| 70 | + |
| 71 | + // Check JSX attributes |
| 72 | + const onClickScopes = tokenMap.get('onClick'); |
| 73 | + expect(onClickScopes).toBeDefined(); |
| 74 | + expect(onClickScopes).toContain('entity.other.attribute-name.jsx.jac'); |
| 75 | + |
| 76 | + // Check PascalCase component names |
| 77 | + const buttonComponentScopes = tokenMap.get('ButtonComponent'); |
| 78 | + expect(buttonComponentScopes).toBeDefined(); |
| 79 | + expect(buttonComponentScopes).toContain('support.class.component.jsx.jac'); |
| 80 | + |
| 81 | + const navLinkScopes = tokenMap.get('NavLink'); |
| 82 | + expect(navLinkScopes).toBeDefined(); |
| 83 | + expect(navLinkScopes).toContain('support.class.component.jsx.jac'); |
| 84 | + }); |
| 85 | +}); |
0 commit comments