diff --git a/tools/challenge-parser/translation-parser/translation-parser.js b/tools/challenge-parser/translation-parser/translation-parser.js index c5dd7e525fa..5589f93aa07 100644 --- a/tools/challenge-parser/translation-parser/translation-parser.js +++ b/tools/challenge-parser/translation-parser/translation-parser.js @@ -137,8 +137,8 @@ function translateGeneric(text, config, regexBefore, regexAfter) { for (const [match, before, comment, after] of matches) { if (knownComments.includes(comment)) { text = text.replace(match, `${before}${dict[comment][lang]}${after}`); - } else { - console.warn(`${comment} does not appear in the comment dictionary`); + } else if (comment.trim()) { + throw `${comment} does not appear in the comment dictionary`; } } diff --git a/tools/challenge-parser/translation-parser/translation-parser.test.js b/tools/challenge-parser/translation-parser/translation-parser.test.js index c642c90bea5..47a1a978062 100644 --- a/tools/challenge-parser/translation-parser/translation-parser.test.js +++ b/tools/challenge-parser/translation-parser/translation-parser.test.js @@ -235,6 +235,14 @@ describe('translation parser', () => { ); }); + it('ignores empty comments', () => { + expect.assertions(1); + const seed = '//'; + expect(translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js')).toBe( + seed + ); + }); + it('only replaces text inside comments, not between them', () => { const seed = `multiline comment /* Add your code below this line */ /* Add your code above this line */ Add your code below this line /* */ `; @@ -363,33 +371,36 @@ describe('translation parser', () => { ).toBe(seed); }); - it('only replaces exact matches (js)', () => { + it('throws if there is not an exact match (js)', () => { + expect.assertions(2); const seedMulti = `/* Add your code below this line Add your code above this line */ change code below this line `; const seedInline = `// Add your code below this line, please`; - expect( + expect(() => translateComments(seedMulti, 'chinese', SIMPLE_TRANSLATION, 'js') - ).toBe(seedMulti); - expect( + ).toThrow(); + expect(() => translateComments(seedInline, 'chinese', SIMPLE_TRANSLATION, 'js') - ).toBe(seedInline); + ).toThrow(); }); it('only replaces exact matches (jsx)', () => { + expect.assertions(1); const seedMulti = `{ /* Add your code below this line Add your code above this line */ } change code below this line `; - expect( + expect(() => translateComments(seedMulti, 'chinese', SIMPLE_TRANSLATION, 'jsx') - ).toBe(seedMulti); + ).toThrow(); }); it('only replaces exact matches (html)', () => { + expect.assertions(1); const seed = `