|
1 | 1 | import path from 'node:path' |
2 | 2 | import process from 'node:process' |
3 | 3 | import { describe, test } from 'vitest' |
4 | | -import { generateExports } from './exports.ts' |
| 4 | +import { detectIndent, generateExports } from './exports.ts' |
5 | 5 | import type { OutputChunk } from 'rolldown' |
6 | 6 |
|
7 | 7 | const cwd = process.cwd() |
@@ -402,6 +402,29 @@ describe.concurrent('generateExports', () => { |
402 | 402 | }) |
403 | 403 | }) |
404 | 404 |
|
| 405 | +describe('detectIndent', () => { |
| 406 | + test('two spaces', ({ expect }) => { |
| 407 | + expect(detectIndent(stringifyJson(2))).toBe(2) |
| 408 | + }) |
| 409 | + test('four spaces', ({ expect }) => { |
| 410 | + expect(detectIndent(stringifyJson(4))).toBe(4) |
| 411 | + }) |
| 412 | + test('tab', ({ expect }) => { |
| 413 | + expect(detectIndent(stringifyJson('\t'))).toBe('\t') |
| 414 | + }) |
| 415 | + test('empty', ({ expect }) => { |
| 416 | + expect(detectIndent('')).toBe(2) |
| 417 | + }) |
| 418 | + test('empty line', ({ expect }) => { |
| 419 | + expect(detectIndent('{\n\n "foo": 42 }')).toBe(2) |
| 420 | + }) |
| 421 | +}) |
| 422 | + |
| 423 | +function stringifyJson(indentation: string | number): string { |
| 424 | + const contents = JSON.stringify({ foo: 42 }, null, indentation) |
| 425 | + return contents |
| 426 | +} |
| 427 | + |
405 | 428 | function genChunk(fileName: string) { |
406 | 429 | // eslint-disable-next-line @typescript-eslint/consistent-type-assertions |
407 | 430 | return { |
|
0 commit comments