-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-extract.js
More file actions
55 lines (52 loc) · 1.4 KB
/
test-extract.js
File metadata and controls
55 lines (52 loc) · 1.4 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
53
54
55
// Test script for extractCodeFromResponse function
import { extractCodeFromResponse } from "./dist/utils/ai-utils.js";
import { logger } from "./dist/logger.js";
// Test cases
const testCases = [
{
name: "With code block",
input: "Here is the code:\n```typescript\nconst x = 1;\n```",
expected: "const x = 1;",
},
{
name: "With multiple code blocks",
input:
"First block:\n```typescript\nconst x = 1;\n```\nSecond block:\n```typescript\nconst y = 2;\n```",
expected: "const x = 1;\n\nconst y = 2;",
},
{
name: "With standalone backticks",
input: "Here is some code: ```const x = 1;```",
expected: "Here is some code: const x = 1;",
},
{
name: "No code blocks",
input: "Just plain text without any code blocks",
expected: "Just plain text without any code blocks",
},
{
name: "Empty string",
input: "",
expected: "",
},
];
// Run tests
let allPassed = true;
testCases.forEach(test => {
const result = extractCodeFromResponse(test.input);
const passed = result === test.expected;
if (!passed) {
allPassed = false;
logger.error(`Test failed: ${test.name}`);
logger.error(`Result: "${result}"`);
logger.error(`Expected: "${test.expected}"`);
} else {
logger.info(`Test passed: ${test.name}`);
}
});
if (allPassed) {
logger.info("All tests passed!");
} else {
logger.error("Some tests failed!");
process.exit(1);
}