Skip to content

Commit 6355a66

Browse files
committed
Auto-generated commit
1 parent 82def67 commit 6355a66

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This release closes the following issue:
3535

3636
<details>
3737

38+
- [`f501596`](https://github.com/stdlib-js/stdlib/commit/f501596714b0f5d5d54416aefba7fff57b000760) - **test:** add tests for `toString` method in `dstructs/named-typed-tuple` [(#8041)](https://github.com/stdlib-js/stdlib/pull/8041) _(by Gaurav Kaushik, Athan Reines)_
3839
- [`5d9761c`](https://github.com/stdlib-js/stdlib/commit/5d9761cfdea3389f82ca75aa262a9fc3ddf89439) - **feat:** implement `toLocaleString` method in `dstructs/named-typed-tuple` [(#8009)](https://github.com/stdlib-js/stdlib/pull/8009) _(by Gaurav Kaushik, Athan Reines, stdlib-bot)_
3940
- [`90b8f5a`](https://github.com/stdlib-js/stdlib/commit/90b8f5a00c6a252d4f66b3d3e22ad8009efa96d6) - **test:** update test messages _(by Athan Reines)_
4041
- [`389cecc`](https://github.com/stdlib-js/stdlib/commit/389cecc1b8f977b3923e2f2ed13aa119c25f5bc0) - **test:** fix variable name _(by Athan Reines)_

test/test.to_string.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var hasOwnProp = require( '@stdlib/assert-has-own-property' );
25+
var isFunction = require( '@stdlib/assert-is-function' );
26+
var namedtypedtuple = require( './../lib' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a function', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' );
34+
t.end();
35+
});
36+
37+
tape( 'a tuple has a `toString` method', function test( t ) {
38+
var Point;
39+
var p;
40+
41+
Point = namedtypedtuple( [ 'x', 'y' ], {
42+
'name': 'Point'
43+
});
44+
p = new Point( [ 10, 20 ] );
45+
46+
t.strictEqual( hasOwnProp( p, 'toString' ), true, 'returns expected value' );
47+
t.strictEqual( isFunction( p.toString ), true, 'returns expected value' );
48+
t.end();
49+
});
50+
51+
tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) {
52+
var values;
53+
var Point;
54+
var p;
55+
var i;
56+
57+
Point = namedtypedtuple( [ 'x', 'y' ], {
58+
'name': 'Point'
59+
});
60+
p = new Point( [ 10, 20 ] );
61+
62+
values = [
63+
'5',
64+
5,
65+
NaN,
66+
true,
67+
false,
68+
null,
69+
void 0,
70+
{},
71+
[],
72+
function noop() {},
73+
{
74+
'name': 'Bob'
75+
}
76+
];
77+
for ( i = 0; i < values.length; i++ ) {
78+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
79+
}
80+
t.end();
81+
82+
function badValue( value ) {
83+
return function badValue() {
84+
return p.toString.call( value );
85+
};
86+
}
87+
});
88+
89+
tape( 'the method returns a string representation for a tuple with one field', function test( t ) {
90+
var expected;
91+
var Single;
92+
var actual;
93+
var s;
94+
95+
Single = namedtypedtuple( [ 'id' ], {
96+
'name': 'Single'
97+
});
98+
s = new Single( [ 12345 ] );
99+
100+
expected = 'Single(id=12345)';
101+
actual = s.toString();
102+
103+
t.strictEqual( actual, expected, 'returns expected value' );
104+
t.end();
105+
});
106+
107+
tape( 'the method returns a string representation of a tuple with multiple fields', function test( t ) {
108+
var expected;
109+
var actual;
110+
var Point;
111+
var p;
112+
113+
Point = namedtypedtuple( [ 'price', 'quantity' ] );
114+
p = new Point( [ 123456.789, 9876 ] );
115+
116+
expected = 'tuple(price=123456.789, quantity=9876)';
117+
actual = p.toString();
118+
119+
t.strictEqual( actual, expected, 'returns expected value' );
120+
t.end();
121+
});

0 commit comments

Comments
 (0)