| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import {grammars, languages} from '../../isl/src/generated/textmate/TextMateGrammarManifest'; |
| 9 | import FilepathClassifier from './FilepathClassifier'; |
| 10 | |
| 11 | describe('findScopeNameForPath', () => { |
| 12 | test('map paths to scope names', () => { |
| 13 | const classifier = new FilepathClassifier(grammars, languages); |
| 14 | const findScopeNameForPath = (path: string) => classifier.findScopeNameForPath(path); |
| 15 | expect(findScopeNameForPath('foo/BUCK')).toBe(null); |
| 16 | expect(findScopeNameForPath('foo/Bar.php')).toBe('source.hack'); |
| 17 | expect(findScopeNameForPath('foo/Bar.java')).toBe('source.java'); |
| 18 | expect(findScopeNameForPath('foo/bar.js')).toBe('source.js'); |
| 19 | expect(findScopeNameForPath('foo/Makefile')).toBe('source.makefile'); |
| 20 | expect(findScopeNameForPath('foo/bar.py')).toBe('source.python'); |
| 21 | expect(findScopeNameForPath('foo/CHANGELOG.md')).toBe('text.html.markdown'); |
| 22 | }); |
| 23 | }); |
| 24 | |
| 25 | describe('findScopeNameForAlias', () => { |
| 26 | test('verify amended aliases are mapped correctly', () => { |
| 27 | const classifier = new FilepathClassifier(grammars, languages); |
| 28 | const findScopeNameForAlias = (alias: string) => classifier.findScopeNameForAlias(alias); |
| 29 | expect(findScopeNameForAlias('rs')).toBe('source.rust'); |
| 30 | }); |
| 31 | }); |
| 32 | |
| 33 | describe('getDisplayNameForLanguageId', () => { |
| 34 | it('verify tags from fenced code blocks get mapped to a human-readable name', () => { |
| 35 | const classifier = new FilepathClassifier(grammars, languages); |
| 36 | const getDisplayNameForLanguageId = (alias: string) => |
| 37 | classifier.getDisplayNameForLanguageId(alias); |
| 38 | expect(getDisplayNameForLanguageId('')).toBe(''); |
| 39 | expect(getDisplayNameForLanguageId('cpp')).toBe('C++'); |
| 40 | expect(getDisplayNameForLanguageId('csharp')).toBe('C#'); |
| 41 | expect(getDisplayNameForLanguageId('fsharp')).toBe('F#'); |
| 42 | expect(getDisplayNameForLanguageId('javascript')).toBe('JavaScript'); |
| 43 | expect(getDisplayNameForLanguageId('js')).toBe('JavaScript'); |
| 44 | expect(getDisplayNameForLanguageId('kotlin')).toBe('Kotlin'); |
| 45 | expect(getDisplayNameForLanguageId('objective-c')).toBe('Objective-C'); |
| 46 | expect(getDisplayNameForLanguageId('php')).toBe('Hack'); |
| 47 | expect(getDisplayNameForLanguageId('py')).toBe('Python'); |
| 48 | expect(getDisplayNameForLanguageId('python')).toBe('Python'); |
| 49 | expect(getDisplayNameForLanguageId('rs')).toBe('Rust'); |
| 50 | expect(getDisplayNameForLanguageId('rust')).toBe('Rust'); |
| 51 | expect(getDisplayNameForLanguageId('swift')).toBe('Swift'); |
| 52 | }); |
| 53 | }); |
| 54 | |