addons/shared/textmate-lib/FilepathClassifier.test.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {grammars, languages} from '../../isl/src/generated/textmate/TextMateGrammarManifest';
b69ab319import FilepathClassifier from './FilepathClassifier';
b69ab3110
b69ab3111describe('findScopeNameForPath', () => {
b69ab3112 test('map paths to scope names', () => {
b69ab3113 const classifier = new FilepathClassifier(grammars, languages);
b69ab3114 const findScopeNameForPath = (path: string) => classifier.findScopeNameForPath(path);
b69ab3115 expect(findScopeNameForPath('foo/BUCK')).toBe(null);
b69ab3116 expect(findScopeNameForPath('foo/Bar.php')).toBe('source.hack');
b69ab3117 expect(findScopeNameForPath('foo/Bar.java')).toBe('source.java');
b69ab3118 expect(findScopeNameForPath('foo/bar.js')).toBe('source.js');
b69ab3119 expect(findScopeNameForPath('foo/Makefile')).toBe('source.makefile');
b69ab3120 expect(findScopeNameForPath('foo/bar.py')).toBe('source.python');
b69ab3121 expect(findScopeNameForPath('foo/CHANGELOG.md')).toBe('text.html.markdown');
b69ab3122 });
b69ab3123});
b69ab3124
b69ab3125describe('findScopeNameForAlias', () => {
b69ab3126 test('verify amended aliases are mapped correctly', () => {
b69ab3127 const classifier = new FilepathClassifier(grammars, languages);
b69ab3128 const findScopeNameForAlias = (alias: string) => classifier.findScopeNameForAlias(alias);
b69ab3129 expect(findScopeNameForAlias('rs')).toBe('source.rust');
b69ab3130 });
b69ab3131});
b69ab3132
b69ab3133describe('getDisplayNameForLanguageId', () => {
b69ab3134 it('verify tags from fenced code blocks get mapped to a human-readable name', () => {
b69ab3135 const classifier = new FilepathClassifier(grammars, languages);
b69ab3136 const getDisplayNameForLanguageId = (alias: string) =>
b69ab3137 classifier.getDisplayNameForLanguageId(alias);
b69ab3138 expect(getDisplayNameForLanguageId('')).toBe('');
b69ab3139 expect(getDisplayNameForLanguageId('cpp')).toBe('C++');
b69ab3140 expect(getDisplayNameForLanguageId('csharp')).toBe('C#');
b69ab3141 expect(getDisplayNameForLanguageId('fsharp')).toBe('F#');
b69ab3142 expect(getDisplayNameForLanguageId('javascript')).toBe('JavaScript');
b69ab3143 expect(getDisplayNameForLanguageId('js')).toBe('JavaScript');
b69ab3144 expect(getDisplayNameForLanguageId('kotlin')).toBe('Kotlin');
b69ab3145 expect(getDisplayNameForLanguageId('objective-c')).toBe('Objective-C');
b69ab3146 expect(getDisplayNameForLanguageId('php')).toBe('Hack');
b69ab3147 expect(getDisplayNameForLanguageId('py')).toBe('Python');
b69ab3148 expect(getDisplayNameForLanguageId('python')).toBe('Python');
b69ab3149 expect(getDisplayNameForLanguageId('rs')).toBe('Rust');
b69ab3150 expect(getDisplayNameForLanguageId('rust')).toBe('Rust');
b69ab3151 expect(getDisplayNameForLanguageId('swift')).toBe('Swift');
b69ab3152 });
b69ab3153});