-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathprocessing.test.mjs
More file actions
63 lines (54 loc) · 1.88 KB
/
processing.test.mjs
File metadata and controls
63 lines (54 loc) · 1.88 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
56
57
58
59
60
61
62
63
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { populateWithEvaluation } from '../processing.mjs';
describe('populateWithEvaluation', () => {
it('substitutes simple ${variable} placeholders', () => {
const result = populateWithEvaluation('Hello ${name}!', { name: 'World' });
assert.strictEqual(result, 'Hello World!');
});
it('supports multiple variables', () => {
const result = populateWithEvaluation('${greeting} ${name}!', {
greeting: 'Hi',
name: 'Node',
});
assert.strictEqual(result, 'Hi Node!');
});
it('supports JavaScript expressions', () => {
const result = populateWithEvaluation('${value > 5 ? "big" : "small"}', {
value: 10,
});
assert.strictEqual(result, 'big');
});
it('supports ternary expressions for conditional content', () => {
const result = populateWithEvaluation(
'${showExtra ? "extra content" : ""}',
{ showExtra: false }
);
assert.strictEqual(result, '');
});
it('handles JSON.stringify for objects', () => {
const obj = { key: 'value' };
const result = populateWithEvaluation('${JSON.stringify(data)}', {
data: obj,
});
assert.strictEqual(result, '{"key":"value"}');
});
it('preserves surrounding HTML content', () => {
const result = populateWithEvaluation(
'<title>${title}</title><link href="${root}styles.css" />',
{ title: 'Test Page', root: '../' }
);
assert.strictEqual(
result,
'<title>Test Page</title><link href="../styles.css" />'
);
});
it('handles empty string values', () => {
const result = populateWithEvaluation('[${content}]', { content: '' });
assert.strictEqual(result, '[]');
});
it('handles numeric values', () => {
const result = populateWithEvaluation('count: ${count}', { count: 42 });
assert.strictEqual(result, 'count: 42');
});
});