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