-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrt-toolkit.test.js
More file actions
52 lines (47 loc) · 1.6 KB
/
srt-toolkit.test.js
File metadata and controls
52 lines (47 loc) · 1.6 KB
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
const { processSrt } = require("./srt-processor");
describe("SRT Toolkit", () => {
test("should correctly parse a valid SRT file", () => {
const srtData = `1
00:00:01,000 --> 00:00:03,000
Hello, world!`;
const { outputContent, errors, warnings } = processSrt(srtData);
expect(errors.length).toBe(0);
expect(warnings.length).toBe(0);
expect(outputContent).toBe(srtData);
});
test("should handle invalid timecodes (start >= end)", () => {
const srtData = `1
00:00:03,000 --> 00:00:01,000
Invalid timecode.`;
const { errors } = processSrt(srtData);
expect(errors.length).toBe(1);
expect(errors[0]).toContain("Invalid timecode (start >= end)");
});
test("should handle single-digit time components", () => {
const srtData = `1
0:1:5,000 --> 0:1:10,500
Valid timecode.`;
const { errors } = processSrt(srtData);
expect(errors.length).toBe(0);
});
test("should correctly substitute variables with Unicode characters", () => {
const srtData = `1
00:00:01,000 --> 00:00:03,000
欢迎来到{{小茅棚}}!`;
const variables = { 小茅棚: "我的世界" };
const { outputContent } = processSrt(srtData, variables);
expect(outputContent).toContain("欢迎来到我的世界!");
});
test("should add new variables to the variables object", () => {
const srtData = `1
00:00:01,000 --> 00:00:03,000
Hello, {{user}}!`;
const variables = {};
const { newVariablesCount, variables: updatedVariables } = processSrt(
srtData,
variables
);
expect(newVariablesCount).toBe(1);
expect(updatedVariables).toHaveProperty("user", "");
});
});