Skip to content

Commit

Permalink
Normlize to sh
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Oct 31, 2022
1 parent 880b798 commit dd0a12a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/extension/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { ParsedDocument } from '../types'
import executor from './executors'
import Languages from './languages'
import { PLATFORM_OS } from './constants'
import { normalizeLanguage } from './utils'

declare var globalThis: any

Expand Down Expand Up @@ -87,13 +88,13 @@ export class Serializer implements vscode.NotebookSerializer {
const isSupported = Object.keys(executor).includes(s.language || '')
if (s.lines && isSupported) {
const lines = s.lines.join('\n')
const language = s.language === 'shell' ? 'sh' : s.language
const language = normalizeLanguage(s.language)
const cell = new vscode.NotebookCellData(
vscode.NotebookCellKind.Code,
/**
* for JS content we want to keep indentation
*/
LANGUAGES_WITH_INDENTATION.includes(s.language || '')
LANGUAGES_WITH_INDENTATION.includes(language || '')
? (s.content || '').trim()
: lines.trim(),
/**
Expand Down
10 changes: 10 additions & 0 deletions src/extension/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ export function getCmdShellSeq(cellText: string, os: string): string {

return `set -e; ${trimmed}`
}

export function normalizeLanguage(l?: string) {
switch (l) {
case 'zsh':
case 'shell':
return 'sh'
default:
return l
}
}
17 changes: 17 additions & 0 deletions tests/extension/utilts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
resetEnv,
getKey,
getCmdShellSeq,
normalizeLanguage,
} from '../../src/extension/utils'
import { ENV_STORE, DEFAULT_ENV } from '../../src/extension/constants'

Expand Down Expand Up @@ -124,3 +125,19 @@ suite('getCmdShellSeq', () => {
})
})

suite('normalizeLanguage', () => {
test('with zsh', () => {
const lang = normalizeLanguage('zsh')
expect(lang).toBe('sh')
})

test('with shell', () => {
const lang = normalizeLanguage('shell')
expect(lang).toBe('sh')
})

test('with sh', () => {
const lang = normalizeLanguage('sh')
expect(lang).toBe('sh')
})
})

0 comments on commit dd0a12a

Please sign in to comment.