From 7159fcee007d42eb9f6fa529e7c566845d056dc9 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Tue, 15 Apr 2025 18:25:46 -0700 Subject: [PATCH 1/4] fix: update format-tokenize to handle escaped percent signs --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/console/log-each-map/test/test.js | 30 +++++++++++++++++ .../@stdlib/console/log-each/test/test.js | 32 ++++++++++++++++++ .../base/format-tokenize/examples/index.js | 4 +++ .../string/base/format-tokenize/lib/main.js | 6 +++- .../string/base/format-tokenize/test/test.js | 33 +++++++++++++++++++ 5 files changed, 104 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/console/log-each-map/test/test.js b/lib/node_modules/@stdlib/console/log-each-map/test/test.js index b758bf72e00e..acf98cc70234 100644 --- a/lib/node_modules/@stdlib/console/log-each-map/test/test.js +++ b/lib/node_modules/@stdlib/console/log-each-map/test/test.js @@ -639,3 +639,33 @@ tape( 'the function supports providing a callback execution context', function t actual.push( str ); } }); + +tape( 'the function handles escaped percent signs (%%)', function test( t ) { + var logEachMap; + var expected; + var actual; + var x; + var y; + + logEachMap = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + x = [ 4, 5, 6 ]; + y = [ 1, 2, 3 ]; + expected = [ '4%1 = 0', '5%2 = 1', '6%3 = 0' ]; + actual = []; + + logEachMap( '%d%%%d = %d', x, y, mod ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function mod( v1, v2 ) { + return v1 % v2; + } + + function logger( str ) { + actual.push( str ); + } +}); diff --git a/lib/node_modules/@stdlib/console/log-each/test/test.js b/lib/node_modules/@stdlib/console/log-each/test/test.js index 3def3b72d2ef..9e1ef53faf32 100644 --- a/lib/node_modules/@stdlib/console/log-each/test/test.js +++ b/lib/node_modules/@stdlib/console/log-each/test/test.js @@ -520,3 +520,35 @@ tape( 'the function prints a formatted message when only provided two scalar arg j += 1; } }); + +tape( 'the function handles escaped percent signs (%%)', function test( t ) { + var expected; + var logEach; + var j; + + logEach = proxyquire( './../lib/main.js', { + '@stdlib/console/log': logger + }); + + expected = [ + 'Progress: 100% complete', + 'Rate: 75% success', + '50.0% + 25.0% = 75.0%', + '5%2 = 1' + ]; + + j = 0; + + logEach( 'Progress: 100%% complete' ); + logEach( 'Rate: %d%% success', 75 ); + logEach( '%0.1f%% + %0.1f%% = %.1f%%', 50.00, 25.00, 75.00 ); + logEach( '%d%%%d = %d', 5, 2, 1 ); + + t.strictEqual( j, expected.length, 'returns expected value' ); + t.end(); + + function logger( str ) { + t.equal( str, expected[ j ], 'returns expected value' ); + j += 1; + } +}); diff --git a/lib/node_modules/@stdlib/string/base/format-tokenize/examples/index.js b/lib/node_modules/@stdlib/string/base/format-tokenize/examples/index.js index e0aac7731c94..70ca4596b70d 100644 --- a/lib/node_modules/@stdlib/string/base/format-tokenize/examples/index.js +++ b/lib/node_modules/@stdlib/string/base/format-tokenize/examples/index.js @@ -31,3 +31,7 @@ console.log( out ); out = formatTokenize( 'Multiple flags: %#+s' ); console.log( out ); // => [ 'Multiple flags: ', {...} ] + +out = formatTokenize( 'Percent: %d%%' ); +console.log( out ); +// => [ 'Percent: ', {...}, '%' ] diff --git a/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js b/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js index 207c12822174..7f8da94002ca 100644 --- a/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js @@ -73,7 +73,11 @@ function formatTokenize( str ) { if ( content.length ) { tokens.push( content ); } - tokens.push( parse( match ) ); + if ( match[ 6 ] === '%' ) { + tokens.push( '%' ); + } else { + tokens.push( parse( match ) ); + } prev = RE.lastIndex; match = RE.exec( str ); } diff --git a/lib/node_modules/@stdlib/string/base/format-tokenize/test/test.js b/lib/node_modules/@stdlib/string/base/format-tokenize/test/test.js index 002e684a327b..5df5c69386b0 100644 --- a/lib/node_modules/@stdlib/string/base/format-tokenize/test/test.js +++ b/lib/node_modules/@stdlib/string/base/format-tokenize/test/test.js @@ -271,3 +271,36 @@ tape( 'the function tokenizes a string (extracting precision)', function test( t t.end(); }); + +tape( 'the function tokenizes a string (extracting escaped percent sign)', function test( t ) { + var expected; + var actual; + var str; + + str = 'Progress: 100%% complete'; + expected = [ + 'Progress: 100', + '%', + ' complete' + ]; + actual = formatTokenize( str ); + t.deepEqual( actual, expected, 'deep equal' ); + + str = 'Rate: %d%% success'; + expected = [ + 'Rate: ', + { + 'flags': '', + 'mapping': void 0, + 'width': void 0, + 'precision': void 0, + 'specifier': 'd' + }, + '%', + ' success' + ]; + actual = formatTokenize( str ); + t.deepEqual( actual, expected, 'deep equal' ); + + t.end(); +}); From 617f7bdc739bdf147999782764175a14745ca0b9 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 18 Apr 2025 16:09:48 -0700 Subject: [PATCH 2/4] docs: add comment explaining check for escaped percent sign --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js b/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js index 7f8da94002ca..07ef03e28372 100644 --- a/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js @@ -73,6 +73,7 @@ function formatTokenize( str ) { if ( content.length ) { tokens.push( content ); } + // Check for an escaped percent sign %%... if ( match[ 6 ] === '%' ) { tokens.push( '%' ); } else { From db6fa151de7efb24bac32c79797e160d33f24a0f Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 18 Apr 2025 16:11:23 -0700 Subject: [PATCH 3/4] test: add additional edge cases --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../string/base/format-tokenize/test/test.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/node_modules/@stdlib/string/base/format-tokenize/test/test.js b/lib/node_modules/@stdlib/string/base/format-tokenize/test/test.js index 5df5c69386b0..aec6be29862b 100644 --- a/lib/node_modules/@stdlib/string/base/format-tokenize/test/test.js +++ b/lib/node_modules/@stdlib/string/base/format-tokenize/test/test.js @@ -286,6 +286,16 @@ tape( 'the function tokenizes a string (extracting escaped percent sign)', funct actual = formatTokenize( str ); t.deepEqual( actual, expected, 'deep equal' ); + str = 'Testing %%%% complete'; + expected = [ + 'Testing ', + '%', + '%', + ' complete' + ]; + actual = formatTokenize( str ); + t.deepEqual( actual, expected, 'deep equal' ); + str = 'Rate: %d%% success'; expected = [ 'Rate: ', @@ -302,5 +312,22 @@ tape( 'the function tokenizes a string (extracting escaped percent sign)', funct actual = formatTokenize( str ); t.deepEqual( actual, expected, 'deep equal' ); + str = 'Testing %%%d%% complete'; + expected = [ + 'Testing ', + '%', + { + 'flags': '', + 'mapping': void 0, + 'width': void 0, + 'precision': void 0, + 'specifier': 'd' + }, + '%', + ' complete' + ]; + actual = formatTokenize( str ); + t.deepEqual( actual, expected, 'deep equal' ); + t.end(); }); From 1e534c7296b589b07e5f645c073d16c14a1eff52 Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Fri, 18 Apr 2025 16:14:33 -0700 Subject: [PATCH 4/4] docs: use backticks for clarity --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/string/base/format-tokenize/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js b/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js index 07ef03e28372..f7366ec046ba 100644 --- a/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/format-tokenize/lib/main.js @@ -73,7 +73,7 @@ function formatTokenize( str ) { if ( content.length ) { tokens.push( content ); } - // Check for an escaped percent sign %%... + // Check for an escaped percent sign `%%`... if ( match[ 6 ] === '%' ) { tokens.push( '%' ); } else {