|
1 | 1 | /**
|
2 | 2 | * @license Apache-2.0
|
3 | 3 | *
|
4 |
| -* Copyright (c) 2018 The Stdlib Authors. |
| 4 | +* Copyright (c) 2023 The Stdlib Authors. |
5 | 5 | *
|
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | 7 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | // MODULES //
|
22 | 22 |
|
23 | 23 | var tape = require( 'tape' );
|
24 |
| -var rpad = require( './../../dist' ); |
| 24 | +var main = require( './../../dist' ); |
25 | 25 |
|
26 | 26 |
|
27 | 27 | // TESTS //
|
28 | 28 |
|
29 |
| -tape( 'main export is a function', function test( t ) { |
| 29 | +tape( 'main export is defined', function test( t ) { |
30 | 30 | t.ok( true, __filename );
|
31 |
| - t.strictEqual( typeof rpad, 'function', 'main export is a function' ); |
32 |
| - t.end(); |
33 |
| -}); |
34 |
| - |
35 |
| -tape( 'if the first argument is not a string primitive, the function will throw an error', function test( t ) { |
36 |
| - var values; |
37 |
| - var i; |
38 |
| - |
39 |
| - values = [ |
40 |
| - 5, |
41 |
| - true, |
42 |
| - NaN, |
43 |
| - null, |
44 |
| - void 0, |
45 |
| - [], |
46 |
| - {}, |
47 |
| - function noop() {} |
48 |
| - ]; |
49 |
| - |
50 |
| - for ( i = 0; i < values.length; i++ ) { |
51 |
| - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); |
52 |
| - } |
53 |
| - t.end(); |
54 |
| - function badValue( value ) { |
55 |
| - return function badValue() { |
56 |
| - rpad( value, 10 ); |
57 |
| - }; |
58 |
| - } |
59 |
| -}); |
60 |
| - |
61 |
| -tape( 'if the second argument is not a nonnegative integer, the function will throw an error', function test( t ) { |
62 |
| - var values; |
63 |
| - var i; |
64 |
| - |
65 |
| - values = [ |
66 |
| - '5', |
67 |
| - 3.14, |
68 |
| - -5, |
69 |
| - true, |
70 |
| - NaN, |
71 |
| - null, |
72 |
| - void 0, |
73 |
| - [], |
74 |
| - {}, |
75 |
| - function noop() {} |
76 |
| - ]; |
77 |
| - |
78 |
| - for ( i = 0; i < values.length; i++ ) { |
79 |
| - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); |
80 |
| - } |
81 |
| - t.end(); |
82 |
| - function badValue( value ) { |
83 |
| - return function badValue() { |
84 |
| - rpad( 'beep', value ); |
85 |
| - }; |
86 |
| - } |
87 |
| -}); |
88 |
| - |
89 |
| -tape( 'if the third argument is not a string primitive, the function will throw an error', function test( t ) { |
90 |
| - var values; |
91 |
| - var i; |
92 |
| - |
93 |
| - values = [ |
94 |
| - 5, |
95 |
| - true, |
96 |
| - NaN, |
97 |
| - null, |
98 |
| - void 0, |
99 |
| - [], |
100 |
| - {}, |
101 |
| - function noop() {} |
102 |
| - ]; |
103 |
| - |
104 |
| - for ( i = 0; i < values.length; i++ ) { |
105 |
| - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); |
106 |
| - } |
107 |
| - t.end(); |
108 |
| - function badValue( value ) { |
109 |
| - return function badValue() { |
110 |
| - rpad( 'beep', 10, value ); |
111 |
| - }; |
112 |
| - } |
113 |
| -}); |
114 |
| - |
115 |
| -tape( 'if the output string will exceed the maximum allowed string length, the function will throw an error', function test( t ) { |
116 |
| - t.throws( foo, RangeError, 'throws RangeError' ); |
117 |
| - t.end(); |
118 |
| - function foo() { |
119 |
| - rpad( 'beep', 1e300 ); |
120 |
| - } |
121 |
| -}); |
122 |
| - |
123 |
| -tape( 'if provided an empty pad string, the function throws an error', function test( t ) { |
124 |
| - t.throws( foo, RangeError, 'throws RangeError' ); |
125 |
| - t.end(); |
126 |
| - function foo() { |
127 |
| - rpad( 'beep', 10, '' ); |
128 |
| - } |
129 |
| -}); |
130 |
| - |
131 |
| -tape( 'by default, the function right pads a string with spaces', function test( t ) { |
132 |
| - var str = rpad( 'a', 5 ); |
133 |
| - t.equal( str, 'a ', 'right padded with spaces' ); |
134 |
| - t.end(); |
135 |
| -}); |
136 |
| - |
137 |
| -tape( 'the function supports right padding a string with a custom pad string', function test( t ) { |
138 |
| - var str = rpad( 'beep', 10, 'p' ); |
139 |
| - t.equal( str, 'beeppppppp', 'right padded to desired length' ); |
140 |
| - t.end(); |
141 |
| -}); |
142 |
| - |
143 |
| -tape( 'the function right pads a string such that an output string may exceed the specified length (minimum bound)', function test( t ) { |
144 |
| - var str = rpad( 'a', 5, 'beepboop' ); |
145 |
| - t.equal( str, 'abeepboop', 'right padded and length exceeds minimum length' ); |
146 |
| - t.end(); |
147 |
| -}); |
148 |
| - |
149 |
| -tape( 'if the specified string length is less than or equal to the input string length, the function returns the input string', function test( t ) { |
150 |
| - t.equal( rpad( 'beep', 2, 'boop' ), 'beep', 'returns input string (<)' ); |
151 |
| - t.equal( rpad( 'beep', 4, 'boop' ), 'beep', 'returns input string (=)' ); |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
152 | 32 | t.end();
|
153 | 33 | });
|
0 commit comments