Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
fix(macros): Make {{InlineBadges}} preserve the argument case
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Sep 1, 2019
1 parent d91549c commit 76091c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
14 changes: 9 additions & 5 deletions macros/InlineBadges.ejs
Expand Up @@ -2,11 +2,14 @@
/**
* The `{{InlineBadges}}` macro inserts inline indicators into a page
* in the correct order.
*
*/
if (!arguments.length) {
return '';
}
/** @type {string[]} */
const indicatorsRaw = $$.map(i => i.toLowerCase());
const indicatorsRaw = arguments.map(i => i.toLowerCase());
let output = '';
const ICONS = {
Expand All @@ -23,10 +26,11 @@ const BADGES = {
let errors = '';
const indicators = [];
for (const indicator of indicatorsRaw) {
for (let i = 0; i < indicatorsRaw.length; i++) {
const indicator = indicatorsRaw[i];
if (indicators.includes(indicator)) {
errors += `
- Duplicate badge: ${indicator}`;
- Duplicate badge: ${arguments[i]}`;
continue;
}
Expand All @@ -36,7 +40,7 @@ for (const indicator of indicatorsRaw) {
}
errors += `
- Unknown badge: ${indicator}`;
- Unknown badge: ${arguments[i]}`;
}
if (errors) {
Expand Down
13 changes: 11 additions & 2 deletions tests/macros/InlineBadges.test.js
Expand Up @@ -34,6 +34,10 @@ const TEST_CASES = [
];

describeMacro('InlineBadges', () => {
itMacro('Early return when no arguments are provided', async macro => {
await expect(macro.call()).resolves.toBeFalsy();
});

for (const t of TEST_CASES) {
itMacro(t.title, async macro => {
let result = await macro.call(...t.args);
Expand All @@ -45,7 +49,12 @@ describeMacro('InlineBadges', () => {
await expect(macro.call('experimental', 'experimental')).rejects.toThrow(TypeError);
});

itMacro('Unknown badge throws error', async macro => {
await expect(macro.call('__invalid__')).rejects.toThrow(TypeError);
itMacro('Unknown badge throws error (reports used case)', async macro => {
// eslint-disable-next-line jest/valid-expect
let rejects = expect(macro.call('__INVALID__')).rejects;
await Promise.all([
rejects.toThrow(TypeError),
rejects.toThrow('Unknown badge: __INVALID__'),
]);
});
});

0 comments on commit 76091c6

Please sign in to comment.