File size: 1,247 Bytes
7a1ad33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { describe, it, expect } from 'vitest';
import { getProgrammingLanguage } from './telemetry-utils.js';

describe('getProgrammingLanguage', () => {
  type ProgrammingLanguageTestCase = {
    name: string;
    args: Record<string, string>;
    expected: string | undefined;
  };

  it.each<ProgrammingLanguageTestCase>([
    {
      name: 'file_path is present',
      args: { file_path: 'src/test.ts' },
      expected: 'typescript',
    },
    {
      name: 'absolute_path is present',
      args: { absolute_path: 'src/test.py' },
      expected: 'python',
    },
    { name: 'path is present', args: { path: 'src/test.go' }, expected: 'go' },
    {
      name: 'no file path is present',
      args: {},
      expected: undefined,
    },
    {
      name: 'unknown file extensions',
      args: { file_path: 'src/test.unknown' },
      expected: undefined,
    },
    {
      name: 'files with no extension',
      args: { file_path: 'src/test' },
      expected: undefined,
    },
  ])('should return $expected when $name', ({ args, expected }) => {
    const language = getProgrammingLanguage(args);
    expect(language).toBe(expected);
  });
});