From e2cda3ff26fef7f2a4c243b4e449c16a719da5aa Mon Sep 17 00:00:00 2001 From: Gaurav Date: Tue, 9 Sep 2025 02:17:24 +0530 Subject: [PATCH 1/3] test: create a test file for forEach() method of dstructs/named-type-tuple --- 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 --- --- .../named-typed-tuple/test/test.for_each.js | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js new file mode 100644 index 000000000000..c0d5992c9884 --- /dev/null +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js @@ -0,0 +1,188 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasProp = require( '@stdlib/assert/has-property' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var namedtypetuple = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof namedtypetuple, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'a tuple has a `forEach` method', function test( t ) { + var Point; + var p; + + Point = namedtypetuple( [ 'x', 'y' ] ); + p = new Point(); + + t.strictEqual( hasProp( p, 'forEach' ), true, 'has property' ); + t.strictEqual( isFunction( p.forEach ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a namedtypetuple instance', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypetuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.forEach.call( value, fcn ); + }; + } + + function fcn( v ) { + void v; + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var Point; + var p; + var i; + + Point = namedtypetuple( [ 'x', 'y' ] ); + p = new Point( [ 1, 2 ] ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return p.forEach( value ); + }; + } +}); + +tape( 'the method returns `undefined`', function test( t ) { + var Point; + var out; + var p; + + Point = namedtypetuple( [ 'x', 'y' ] ); + p = new Point( [ 10, 20 ] ); + out = p.forEach( fcn ); + + t.strictEqual( out, void 0, 'returns expected value' ); + t.end(); + + function fcn( v ) { + void v; + } +}); + +tape( 'the method invokes a provided function for each element in a tuple', function test( t ) { + var fieldNames; + var indices; + var values; + var tuples; + var Point; + var p; + + indices = []; + values = []; + fieldNames = []; + tuples = []; + + Point = namedtypetuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.forEach( fcn ); + + t.deepEqual( values, [ 1, 2, 3 ], 'returns expected values' ); + t.deepEqual( indices, [ 0, 1, 2 ], 'returns expected indices' ); + t.deepEqual( fieldNames, [ 'x', 'y', 'z' ], 'returns expected field names' ); + t.strictEqual( tuples[ 0 ], p, 'returns expected tuple reference' ); + t.strictEqual( tuples[ 1 ], p, 'returns expected tuple reference' ); + t.strictEqual( tuples[ 2 ], p, 'returns expected tuple reference' ); + + t.end(); + + function fcn( v, i, fieldName, tuple ) { + values.push( v ); + indices.push( i ); + fieldNames.push( fieldName ); + tuples.push( tuple ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var Point; + var ctx; + var p; + + ctx = { + 'count': 0 + }; + Point = namedtypetuple( [ 'x', 'y', 'z' ] ); + p = new Point( [ 1, 2, 3 ] ); + p.forEach( fcn, ctx ); + + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function fcn() { + this.count += 1; // eslint-disable-line no-invalid-this + } +}); From d45e350552bddbbd82fe1c57dfd8afe4275d44c4 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 8 Sep 2025 15:28:11 -0700 Subject: [PATCH 2/3] chore: clean-up Signed-off-by: Athan --- .../named-typed-tuple/test/test.for_each.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js index c0d5992c9884..9c8a558939d7 100644 --- a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js @@ -23,14 +23,14 @@ var tape = require( 'tape' ); var hasProp = require( '@stdlib/assert/has-property' ); var isFunction = require( '@stdlib/assert/is-function' ); -var namedtypetuple = require( './../lib' ); +var namedtypedtuple = require( './../lib' ); // TESTS // tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof namedtypetuple, 'function', 'main export is a function' ); + t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); t.end(); }); @@ -38,21 +38,21 @@ tape( 'a tuple has a `forEach` method', function test( t ) { var Point; var p; - Point = namedtypetuple( [ 'x', 'y' ] ); + Point = namedtypedtuple( [ 'x', 'y' ] ); p = new Point(); - t.strictEqual( hasProp( p, 'forEach' ), true, 'has property' ); - t.strictEqual( isFunction( p.forEach ), true, 'has method' ); + t.strictEqual( hasProp( p, 'forEach' ), true, 'returns expected value' ); + t.strictEqual( isFunction( p.forEach ), true, 'returns expected value' ); t.end(); }); -tape( 'the method throws an error if invoked with a `this` context which is not a namedtypetuple instance', function test( t ) { +tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) { var values; var Point; var p; var i; - Point = namedtypetuple( [ 'x', 'y' ] ); + Point = namedtypedtuple( [ 'x', 'y' ] ); p = new Point( [ 1, 2 ] ); values = [ @@ -89,7 +89,7 @@ tape( 'the method throws an error if provided a first argument which is not a fu var p; var i; - Point = namedtypetuple( [ 'x', 'y' ] ); + Point = namedtypedtuple( [ 'x', 'y' ] ); p = new Point( [ 1, 2 ] ); values = [ @@ -120,7 +120,7 @@ tape( 'the method returns `undefined`', function test( t ) { var out; var p; - Point = namedtypetuple( [ 'x', 'y' ] ); + Point = namedtypedtuple( [ 'x', 'y' ] ); p = new Point( [ 10, 20 ] ); out = p.forEach( fcn ); @@ -128,7 +128,7 @@ tape( 'the method returns `undefined`', function test( t ) { t.end(); function fcn( v ) { - void v; + return v; } }); @@ -145,7 +145,7 @@ tape( 'the method invokes a provided function for each element in a tuple', func fieldNames = []; tuples = []; - Point = namedtypetuple( [ 'x', 'y', 'z' ] ); + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); p = new Point( [ 1, 2, 3 ] ); p.forEach( fcn ); @@ -174,7 +174,7 @@ tape( 'the method supports providing an execution context', function test( t ) { ctx = { 'count': 0 }; - Point = namedtypetuple( [ 'x', 'y', 'z' ] ); + Point = namedtypedtuple( [ 'x', 'y', 'z' ] ); p = new Point( [ 1, 2, 3 ] ); p.forEach( fcn, ctx ); From 310be6423f18bb32d2d06332ab78c52f06d7e0b5 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 8 Sep 2025 15:29:10 -0700 Subject: [PATCH 3/3] test: fix return value Signed-off-by: Athan --- .../@stdlib/dstructs/named-typed-tuple/test/test.for_each.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js index 9c8a558939d7..39c99d237837 100644 --- a/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js +++ b/lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.for_each.js @@ -79,7 +79,7 @@ tape( 'the method throws an error if invoked with a `this` context which is not } function fcn( v ) { - void v; + return v; } });