Welcome to mirror list, hosted at ThFree Co, Russian Federation.

rules_mapper_spec.js « editorconfig « lib « ide « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 536b14094354b1a3ef054008b47c5db2b618b69f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import mapRulesToMonaco from '~/ide/lib/editorconfig/rules_mapper';

describe('mapRulesToMonaco', () => {
  const multipleEntries = {
    input: { indent_style: 'tab', indent_size: '4', insert_final_newline: 'true' },
    output: { insertSpaces: false, tabSize: 4, insertFinalNewline: true },
  };

  // tab width takes precedence
  const tabWidthAndIndent = {
    input: { indent_style: 'tab', indent_size: '4', tab_width: '3' },
    output: { insertSpaces: false, tabSize: 3 },
  };

  it.each`
    rule                                     | monacoOption
    ${{ indent_style: 'tab' }}               | ${{ insertSpaces: false }}
    ${{ indent_style: 'space' }}             | ${{ insertSpaces: true }}
    ${{ indent_style: 'unset' }}             | ${{}}
    ${{ indent_size: '4' }}                  | ${{ tabSize: 4 }}
    ${{ indent_size: '4.4' }}                | ${{ tabSize: 4 }}
    ${{ indent_size: '0' }}                  | ${{}}
    ${{ indent_size: '-10' }}                | ${{}}
    ${{ indent_size: 'NaN' }}                | ${{}}
    ${{ tab_width: '4' }}                    | ${{ tabSize: 4 }}
    ${{ tab_width: '5.4' }}                  | ${{ tabSize: 5 }}
    ${{ tab_width: '-10' }}                  | ${{}}
    ${{ trim_trailing_whitespace: 'true' }}  | ${{ trimTrailingWhitespace: true }}
    ${{ trim_trailing_whitespace: 'false' }} | ${{ trimTrailingWhitespace: false }}
    ${{ trim_trailing_whitespace: 'unset' }} | ${{}}
    ${{ end_of_line: 'lf' }}                 | ${{ endOfLine: 0 }}
    ${{ end_of_line: 'crlf' }}               | ${{ endOfLine: 1 }}
    ${{ end_of_line: 'cr' }}                 | ${{}}
    ${{ end_of_line: 'unset' }}              | ${{}}
    ${{ insert_final_newline: 'true' }}      | ${{ insertFinalNewline: true }}
    ${{ insert_final_newline: 'false' }}     | ${{ insertFinalNewline: false }}
    ${{ insert_final_newline: 'unset' }}     | ${{}}
    ${multipleEntries.input}                 | ${multipleEntries.output}
    ${tabWidthAndIndent.input}               | ${tabWidthAndIndent.output}
  `('correctly maps editorconfig rule to monaco option: $rule', ({ rule, monacoOption }) => {
    expect(mapRulesToMonaco(rule)).toEqual(monacoOption);
  });
});