|
1 | 1 | import { describe, it, expect } from 'vitest'; |
2 | 2 | import { |
3 | | - clamp, formatRows, formatBytes, timeAgo, sqlString, inferQueryName, isNumericType, shortVersion, userShortName, withStatementBreak, detectSqlFormat, |
| 3 | + clamp, formatRows, formatBytes, timeAgo, sqlString, inferQueryName, isNumericType, shortVersion, userShortName, withStatementBreak, detectSqlFormat, isExplain, |
4 | 4 | } from '../../src/core/format.js'; |
5 | 5 |
|
6 | 6 | describe('clamp', () => { |
@@ -101,6 +101,20 @@ describe('detectSqlFormat', () => { |
101 | 101 | }); |
102 | 102 | }); |
103 | 103 |
|
| 104 | +describe('isExplain', () => { |
| 105 | + it('detects a leading EXPLAIN (any variant), ignoring leading whitespace/case', () => { |
| 106 | + expect(isExplain('EXPLAIN SELECT 1')).toBe(true); |
| 107 | + expect(isExplain(' explain pipeline SELECT 1')).toBe(true); |
| 108 | + expect(isExplain('EXPLAIN AST SELECT 1')).toBe(true); |
| 109 | + }); |
| 110 | + it('is false for non-EXPLAIN statements', () => { |
| 111 | + expect(isExplain('SELECT 1')).toBe(false); |
| 112 | + expect(isExplain('SELECT explain FROM t')).toBe(false); // EXPLAIN not the leading keyword |
| 113 | + expect(isExplain('')).toBe(false); |
| 114 | + expect(isExplain(null)).toBe(false); |
| 115 | + }); |
| 116 | +}); |
| 117 | + |
104 | 118 | describe('inferQueryName', () => { |
105 | 119 | it('uses FROM table when present', () => { |
106 | 120 | expect(inferQueryName('SELECT * FROM system.tables')).toBe('Query · system.tables'); |
|
0 commit comments