From 851db567bf914d8a3b6857c45284b736c772d57a Mon Sep 17 00:00:00 2001 From: Aaron Francis Date: Mon, 23 Aug 2021 17:54:24 -0500 Subject: [PATCH] Fix replacement issue with dollar signs. --- package.json | 7 ++++++- src/commands/highlight.js | 4 ++-- tests/__snapshots__/highlight.test.js.snap | 17 +++++++++++++++++ tests/fixtures/keygen.html | 13 +++++++++++++ tests/highlight.test.js | 4 +++- tests/support/helpers.js | 7 +++++++ 6 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/keygen.html diff --git a/package.json b/package.json index 549743d..db77833 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@torchlight-api/torchlight-cli", - "version": "0.0.7", + "version": "0.0.8", "description": "A CLI for Torchlight - the syntax highlighting API", "main": "index.js", "scripts": { @@ -14,6 +14,11 @@ "highlighting", "torchlight" ], + "standard": { + "ignore": [ + "tests" + ] + }, "author": "Aaron Francis (https://torchlight.dev)", "license": "MIT", "dependencies": { diff --git a/src/commands/highlight.js b/src/commands/highlight.js index 8bbeb59..f94fa6e 100644 --- a/src/commands/highlight.js +++ b/src/commands/highlight.js @@ -22,7 +22,7 @@ module.exports = function (torchlight, options) { *************************************** * Torchlight is watching files... * *************************************** - `) +`) } const input = path.resolve(options.input) @@ -142,7 +142,7 @@ function highlight (torchlight, source) { } Object.keys(swap).forEach(key => { - highlighted = highlighted.replace(key, swap[key]) + highlighted = highlighted.replace(key, () => swap[key]) }) }) diff --git a/tests/__snapshots__/highlight.test.js.snap b/tests/__snapshots__/highlight.test.js.snap index 7fc84b4..4924512 100644 --- a/tests/__snapshots__/highlight.test.js.snap +++ b/tests/__snapshots__/highlight.test.js.snap @@ -147,6 +147,23 @@ exports[`decipher-language.html -------- it deciphers languages based on attribu
foobar
" `; +exports[`keygen.html ------------------- fixes zekes issue: keygen.html keygen.html ------------------- fixes zekes issue 1`] = ` +"
using RestSharp;
using System;
using System.Text;
var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes("{EMAIL}:{PASSWORD}"));
var client = new RestClient("https://api.keygen.sh/v1/accounts/{ACCOUNT}");
var request = new RestRequest("tokens", Method.POST);
request.AddHeader("Accept", "application/vnd.api+json");
request.AddHeader("Authorization", $"Basic {credentials}");
var response = client.Execute(request);
+" +`; + exports[`multiple-blocks.html ---------- three blocks in one pre tag: multiple-blocks.html multiple-blocks.html ---------- three blocks in one pre tag 1`] = ` "
php
html
js
" diff --git a/tests/fixtures/keygen.html b/tests/fixtures/keygen.html new file mode 100644 index 0000000..b481c78 --- /dev/null +++ b/tests/fixtures/keygen.html @@ -0,0 +1,13 @@ +
using RestSharp;
+using System;
+using System.Text;
+
+var credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes("{EMAIL}:{PASSWORD}"));
+
+var client = new RestClient("https://api.keygen.sh/v1/accounts/{ACCOUNT}");
+var request = new RestRequest("tokens", Method.POST);
+
+request.AddHeader("Accept", "application/vnd.api+json");
+request.AddHeader("Authorization", $"Basic {credentials}");
+
+var response = client.Execute(request);
diff --git a/tests/highlight.test.js b/tests/highlight.test.js index 39d58fa..894b2d3 100644 --- a/tests/highlight.test.js +++ b/tests/highlight.test.js @@ -10,6 +10,8 @@ beforeEach(() => { torchlight.initialized = false }) +fixture('keygen: fixes zekes issue') + fixture('multiple-blocks: three blocks in one pre tag', () => { const mock = mockApi(data => { expect(data.blocks).toHaveLength(3) @@ -91,4 +93,4 @@ fixture('decipher-language: it deciphers languages based on attributes', () => { }) return () => expect(mock).toHaveBeenCalledTimes(1) -}) +}) \ No newline at end of file diff --git a/tests/support/helpers.js b/tests/support/helpers.js index 9f9f7f0..12359b5 100644 --- a/tests/support/helpers.js +++ b/tests/support/helpers.js @@ -18,6 +18,13 @@ function fixture (file, callback, options = {}) { description = `${path} ${dashes} ${description.trim()}` + // If there was no callback, it's just a snapshot test. + callback = callback ?? function () { + const mock = mockApi(() => []) + + return () => expect(mock).toHaveBeenCalledTimes(1) + } + test(description, done => { const after = callback()