forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpolate.js
58 lines (44 loc) · 1.94 KB
/
interpolate.js
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
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const assert = require("chai").assert;
const { getPlaceholderMatcher, interpolate } = require("../../../lib/linter/interpolate");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("getPlaceholderMatcher", () => {
it("returns a global regular expression", () => {
const matcher = getPlaceholderMatcher();
assert.strictEqual(matcher.global, true);
});
it("matches text with placeholders", () => {
const matcher = getPlaceholderMatcher();
assert.match("{{ placeholder }}", matcher);
});
it("does not match text without placeholders", () => {
const matcher = getPlaceholderMatcher();
assert.notMatch("no placeholders in sight", matcher);
});
it("captures the text inside the placeholder", () => {
const matcher = getPlaceholderMatcher();
const text = "{{ placeholder }}";
const matches = Array.from(text.matchAll(matcher));
assert.deepStrictEqual(matches, [[text, " placeholder "]]);
});
});
describe("interpolate()", () => {
it("passes through text without {{ }}", () => {
const message = "This is a very important message!";
assert.strictEqual(interpolate(message, {}), message);
});
it("passes through text with {{ }} that don’t match a key", () => {
const message = "This is a very important {{ message }}!";
assert.strictEqual(interpolate(message, {}), message);
});
it("Properly interpolates keys in {{ }}", () => {
assert.strictEqual(interpolate("This is a very important {{ message }}!", {
message: "test"
}), "This is a very important test!");
});
});