From b3bc57f520454719c18cbe1488fbd81634d6d710 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <76155456+pulkit-30@users.noreply.github.com> Date: Thu, 8 Dec 2022 18:54:53 +0530 Subject: [PATCH] added test for tapEscape function --- lib/internal/test_runner/tap_stream.js | 2 +- test/parallel/test-runner-tap-parser-stream.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/internal/test_runner/tap_stream.js b/lib/internal/test_runner/tap_stream.js index c501f177085885..72fb2334f5b267 100644 --- a/lib/internal/test_runner/tap_stream.js +++ b/lib/internal/test_runner/tap_stream.js @@ -270,4 +270,4 @@ function isAssertionLike(value) { return value && typeof value === 'object' && 'expected' in value && 'actual' in value; } -module.exports = { TapStream }; +module.exports = { TapStream, tapEscape }; diff --git a/test/parallel/test-runner-tap-parser-stream.js b/test/parallel/test-runner-tap-parser-stream.js index bd10af29d88279..52b4112161e208 100644 --- a/test/parallel/test-runner-tap-parser-stream.js +++ b/test/parallel/test-runner-tap-parser-stream.js @@ -4,6 +4,7 @@ const common = require('../common'); const assert = require('node:assert'); const { TapParser } = require('internal/test_runner/tap_parser'); const { TapChecker } = require('internal/test_runner/tap_checker'); +const { tapEscape } = require('internal/test_runner/tap_stream'); const cases = [ { @@ -627,3 +628,17 @@ ok 1 - test 1 expected.map((item) => ({ __proto__: null, ...item })) ); })().then(common.mustCall()); + +(async () => { + [{ escapeChar: '\\', tappedEscape: '\\\\' }, + { escapeChar: '#', tappedEscape: '\\#' }, + { escapeChar: '\n', tappedEscape: '\\n' }, + { escapeChar: '\t', tappedEscape: '\\t' }, + { escapeChar: '\r', tappedEscape: '\\r' }, + { escapeChar: '\f', tappedEscape: '\\f' }, + { escapeChar: '\b', tappedEscape: '\\b' }, + { escapeChar: '\v', tappedEscape: '\\v' }, + ].forEach(({ escapeChar, tappedEscape }) => { + assert.strictEqual(tapEscape(escapeChar), tappedEscape); + }); +})().then(common.mustCall());