forked from readmeio/httpsnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-builder.test.ts
More file actions
44 lines (34 loc) · 1.34 KB
/
code-builder.test.ts
File metadata and controls
44 lines (34 loc) · 1.34 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
import { describe, it, expect } from 'vitest';
import { CodeBuilder } from './code-builder.js';
describe('codeBuilder', () => {
describe('indentLine', () => {
const indent = '\t';
const builder = new CodeBuilder({ indent });
const line = 'console.log("hello world")';
it('handles a single argument', () => {
const result = builder.indentLine(line);
expect(result).toStrictEqual(line);
});
it('handels indentation', () => {
const result = builder.indentLine(line, 2);
expect(result).toBe(`${indent.repeat(2)}${line}`);
});
});
describe('addPostProcessor', () => {
it('replaces accordingly with one replacer', () => {
const indent = '\t';
const { join, addPostProcessor, push } = new CodeBuilder({ indent });
push('console.log("hello world")');
addPostProcessor(code => code.replace(/console/, 'REPLACED'));
expect(join()).toBe('REPLACED.log("hello world")');
});
it('replaces accordingly with multiple replacers', () => {
const indent = '\t';
const { join, addPostProcessor, push } = new CodeBuilder({ indent });
push('console.log("hello world")');
addPostProcessor(code => code.replace(/world/, 'nurse!!'));
addPostProcessor(code => code.toUpperCase());
expect(join()).toBe('CONSOLE.LOG("HELLO NURSE!!")');
});
});
});