-
-
Notifications
You must be signed in to change notification settings - Fork 874
test: add tests for toString
method in dstructs/named-typed-tuple
#8041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kgryte
merged 5 commits into
stdlib-js:develop
from
Gauravkaushik-1206:create-test-file-named-typed-array
Sep 8, 2025
+121
−0
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d2fa0ab
test: add a test file for toString() method of dstructs/named-typed-t...
Gauravkaushik-1206 4945063
test: update description
kgryte 7ed4e84
test: update messages
kgryte 8284eed
test: update description
kgryte 5c14fed
test: update require path
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
lib/node_modules/@stdlib/dstructs/named-typed-tuple/test/test.to_string.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); | ||
var isFunction = require( '@stdlib/assert/is-function' ); | ||
var namedtypedtuple = require( './../lib' ); | ||
|
||
|
||
// TESTS // | ||
|
||
tape( 'main export is a function', function test( t ) { | ||
t.ok( true, __filename ); | ||
t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'a tuple has a `toString` method', function test( t ) { | ||
var Point; | ||
var p; | ||
|
||
Point = namedtypedtuple( [ 'x', 'y' ], { | ||
'name': 'Point' | ||
}); | ||
p = new Point( [ 10, 20 ] ); | ||
|
||
t.strictEqual( hasOwnProp( p, 'toString' ), true, 'returns expected value' ); | ||
t.strictEqual( isFunction( p.toString ), true, 'returns expected value' ); | ||
t.end(); | ||
}); | ||
|
||
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 = namedtypedtuple( [ 'x', 'y' ], { | ||
'name': 'Point' | ||
}); | ||
p = new Point( [ 10, 20 ] ); | ||
|
||
values = [ | ||
'5', | ||
5, | ||
NaN, | ||
true, | ||
false, | ||
null, | ||
void 0, | ||
{}, | ||
[], | ||
function noop() {}, | ||
{ | ||
'name': 'Bob' | ||
} | ||
]; | ||
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.toString.call( value ); | ||
}; | ||
} | ||
}); | ||
|
||
tape( 'the method returns a string representation for a tuple with one field', function test( t ) { | ||
var expected; | ||
var Single; | ||
var actual; | ||
var s; | ||
|
||
Single = namedtypedtuple( [ 'id' ], { | ||
'name': 'Single' | ||
}); | ||
s = new Single( [ 12345 ] ); | ||
|
||
expected = 'Single(id=12345)'; | ||
actual = s.toString(); | ||
|
||
t.strictEqual( actual, expected, 'returns expected value' ); | ||
t.end(); | ||
}); | ||
|
||
tape( 'the method returns a string representation of a tuple with multiple fields', function test( t ) { | ||
var expected; | ||
var actual; | ||
var Point; | ||
var p; | ||
|
||
Point = namedtypedtuple( [ 'price', 'quantity' ] ); | ||
p = new Point( [ 123456.789, 9876 ] ); | ||
|
||
expected = 'tuple(price=123456.789, quantity=9876)'; | ||
actual = p.toString(); | ||
|
||
t.strictEqual( actual, expected, 'returns expected value' ); | ||
t.end(); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.