办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { describe, expect, it } from 'vitest';
 
import {
  capitalizeFirstLetter,
  kebabToCamelCase,
  toCamelCase,
  toLowerCaseFirstLetter,
} from '../letter';
 
describe('capitalizeFirstLetter', () => {
  it('should capitalize the first letter of a string', () => {
    expect(capitalizeFirstLetter('hello')).toBe('Hello');
    expect(capitalizeFirstLetter('world')).toBe('World');
  });
 
  it('should handle empty strings', () => {
    expect(capitalizeFirstLetter('')).toBe('');
  });
 
  it('should handle single character strings', () => {
    expect(capitalizeFirstLetter('a')).toBe('A');
    expect(capitalizeFirstLetter('b')).toBe('B');
  });
 
  it('should not change the case of other characters', () => {
    expect(capitalizeFirstLetter('hElLo')).toBe('HElLo');
  });
});
 
describe('toLowerCaseFirstLetter', () => {
  it('should convert the first letter to lowercase', () => {
    expect(toLowerCaseFirstLetter('CommonAppName')).toBe('commonAppName');
    expect(toLowerCaseFirstLetter('AnotherKeyExample')).toBe(
      'anotherKeyExample',
    );
  });
 
  it('should return the same string if the first letter is already lowercase', () => {
    expect(toLowerCaseFirstLetter('alreadyLowerCase')).toBe('alreadyLowerCase');
  });
 
  it('should handle empty strings', () => {
    expect(toLowerCaseFirstLetter('')).toBe('');
  });
 
  it('should handle single character strings', () => {
    expect(toLowerCaseFirstLetter('A')).toBe('a');
    expect(toLowerCaseFirstLetter('a')).toBe('a');
  });
 
  it('should handle strings with only one uppercase letter', () => {
    expect(toLowerCaseFirstLetter('A')).toBe('a');
  });
 
  it('should handle strings with special characters', () => {
    expect(toLowerCaseFirstLetter('!Special')).toBe('!Special');
    expect(toLowerCaseFirstLetter('123Number')).toBe('123Number');
  });
});
 
describe('toCamelCase', () => {
  it('should return the key if parentKey is empty', () => {
    expect(toCamelCase('child', '')).toBe('child');
  });
 
  it('should combine parentKey and key in camel case', () => {
    expect(toCamelCase('child', 'parent')).toBe('parentChild');
  });
 
  it('should handle empty key and parentKey', () => {
    expect(toCamelCase('', '')).toBe('');
  });
 
  it('should handle key with capital letters', () => {
    expect(toCamelCase('Child', 'parent')).toBe('parentChild');
    expect(toCamelCase('Child', 'Parent')).toBe('ParentChild');
  });
});
 
describe('kebabToCamelCase', () => {
  it('should convert kebab-case to camelCase correctly', () => {
    expect(kebabToCamelCase('my-component-name')).toBe('myComponentName');
  });
 
  it('should handle multiple consecutive hyphens', () => {
    expect(kebabToCamelCase('my--component--name')).toBe('myComponentName');
  });
 
  it('should trim leading and trailing hyphens', () => {
    expect(kebabToCamelCase('-my-component-name-')).toBe('myComponentName');
  });
 
  it('should preserve the case of the first word', () => {
    expect(kebabToCamelCase('My-component-name')).toBe('MyComponentName');
  });
 
  it('should convert a single word correctly', () => {
    expect(kebabToCamelCase('component')).toBe('component');
  });
 
  it('should return an empty string if input is empty', () => {
    expect(kebabToCamelCase('')).toBe('');
  });
 
  it('should handle strings with no hyphens', () => {
    expect(kebabToCamelCase('mycomponentname')).toBe('mycomponentname');
  });
 
  it('should handle strings with only hyphens', () => {
    expect(kebabToCamelCase('---')).toBe('');
  });
 
  it('should handle mixed case inputs', () => {
    expect(kebabToCamelCase('my-Component-Name')).toBe('myComponentName');
  });
});