|
| 1 | +import { format } from 'prettier' |
| 2 | +import { LangVariant } from 'sh-syntax' |
| 3 | +import { describe, expect, it } from 'vitest' |
| 4 | + |
| 5 | +import * as sh from 'prettier-plugin-sh' |
| 6 | + |
| 7 | +/* |
| 8 | + * Regression test for zsh support, tracking: |
| 9 | + * - sh-syntax issue: https://github.com/un-ts/sh-syntax/issues/135 |
| 10 | + * - sh-syntax fix PR: https://github.com/un-ts/sh-syntax/pull/136 |
| 11 | + * |
| 12 | + * `${0:A:h:h}` is valid zsh (modifier chain: :A absolute path, :h head/dirname) |
| 13 | + * but is rejected by the bash grammar with "ternary operator missing ? before :". |
| 14 | + * sh-syntax >= 0.6.0 rebuilds the WASM against mvdan/sh v3.13 and exposes a |
| 15 | + * dedicated `LangZsh` variant that parses it correctly. |
| 16 | + * |
| 17 | + * Expected results by installed sh-syntax version: |
| 18 | + * - 0.5.8 (before): RED - `LangZsh` is undefined and format() throws. |
| 19 | + * - 0.6.0 (after): GREEN - the zsh variant parses and prints the input. |
| 20 | + */ |
| 21 | +describe('zsh support (sh-syntax >= 0.6.0)', () => { |
| 22 | + const ZSH_SOURCE = 'DIR=${0:A:h:h}\n' |
| 23 | + |
| 24 | + it('exposes the LangZsh variant constant', () => { |
| 25 | + expect(LangVariant.LangZsh).toBeDefined() |
| 26 | + }) |
| 27 | + |
| 28 | + it('formats a zsh modifier chain when using the zsh variant', async () => { |
| 29 | + const output = await format(ZSH_SOURCE, { |
| 30 | + filepath: 'script.zsh', |
| 31 | + plugins: [sh], |
| 32 | + variant: LangVariant.LangZsh, |
| 33 | + }) |
| 34 | + |
| 35 | + expect(output).toContain('${0:A:h:h}') |
| 36 | + }) |
| 37 | +}) |
0 commit comments