|
1 | 1 | /** |
2 | 2 | * @license Apache-2.0 |
3 | 3 | * |
4 | | -* Copyright (c) 2020 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 codePointAt = 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 codePointAt, 'function', 'main export is a function' ); |
32 | | - t.end(); |
33 | | -}); |
34 | | - |
35 | | -tape( 'the function throws an error if the first argument is not a string', function test( t ) { |
36 | | - var values; |
37 | | - var i; |
38 | | - |
39 | | - values = [ |
40 | | - -5, |
41 | | - 3.14, |
42 | | - -1.0, |
43 | | - NaN, |
44 | | - true, |
45 | | - false, |
46 | | - null, |
47 | | - void 0, |
48 | | - [ 'beep', 'boop' ], |
49 | | - [ 1, 2, 3 ], |
50 | | - {}, |
51 | | - function noop() {} |
52 | | - ]; |
53 | | - |
54 | | - for ( i = 0; i < values.length; i++ ) { |
55 | | - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
56 | | - } |
57 | | - t.end(); |
58 | | - |
59 | | - function badValue( value ) { |
60 | | - return function badValue() { |
61 | | - codePointAt( value, 0 ); |
62 | | - }; |
63 | | - } |
64 | | -}); |
65 | | - |
66 | | -tape( 'the function throws an error if the second argument is not an integer', function test( t ) { |
67 | | - var values; |
68 | | - var i; |
69 | | - |
70 | | - values = [ |
71 | | - 'bar', |
72 | | - 3.14, |
73 | | - -3.14, |
74 | | - NaN, |
75 | | - true, |
76 | | - false, |
77 | | - null, |
78 | | - void 0, |
79 | | - [ 'beep', 'boop' ], |
80 | | - [ 1, 2, 3 ], |
81 | | - {}, |
82 | | - function noop() {} |
83 | | - ]; |
84 | | - for ( i = 0; i < values.length; i++ ) { |
85 | | - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
86 | | - } |
87 | | - t.end(); |
88 | | - |
89 | | - function badValue( value ) { |
90 | | - return function badValue() { |
91 | | - codePointAt( 'foo', value ); |
92 | | - }; |
93 | | - } |
94 | | -}); |
95 | | - |
96 | | -tape( 'the function throws an error if the third argument is not a boolean', function test( t ) { |
97 | | - var values; |
98 | | - var i; |
99 | | - |
100 | | - values = [ |
101 | | - 'bar', |
102 | | - -5, |
103 | | - 3.14, |
104 | | - -1.0, |
105 | | - NaN, |
106 | | - null, |
107 | | - void 0, |
108 | | - [ 'beep', 'boop' ], |
109 | | - [ 1, 2, 3 ], |
110 | | - {}, |
111 | | - function noop() {} |
112 | | - ]; |
113 | | - for ( i = 0; i < values.length; i++ ) { |
114 | | - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); |
115 | | - } |
116 | | - t.end(); |
117 | | - |
118 | | - function badValue( value ) { |
119 | | - return function badValue() { |
120 | | - codePointAt( 'foo', 0, value ); |
121 | | - }; |
122 | | - } |
123 | | -}); |
124 | | - |
125 | | -tape( 'the function throws an error if a provided position is not a valid index in the provided string', function test( t ) { |
126 | | - var values; |
127 | | - var i; |
128 | | - |
129 | | - values = [ |
130 | | - [ 'bar', 3 ], |
131 | | - [ 'bar', -4 ], |
132 | | - [ 'string', 7 ], |
133 | | - [ 'string', -8 ], |
134 | | - [ '', 0 ] |
135 | | - ]; |
136 | | - for ( i = 0; i < values.length; i++ ) { |
137 | | - t.throws( badValue( values[i] ), RangeError, 'throws an error when provided '+values[i] ); |
138 | | - } |
139 | | - t.end(); |
140 | | - |
141 | | - function badValue( value ) { |
142 | | - return function badValue() { |
143 | | - codePointAt( value[ 0 ], value[ 1 ] ); |
144 | | - }; |
145 | | - } |
146 | | -}); |
147 | | - |
148 | | -tape( 'the arity of the function is 3', function test( t ) { |
149 | | - t.strictEqual( codePointAt.length, 3, 'has length 3' ); |
150 | | - t.end(); |
151 | | -}); |
152 | | - |
153 | | -tape( 'the function returns the code point at a specified string position', function test( t ) { |
154 | | - var out; |
155 | | - |
156 | | - out = codePointAt( 'last man standing', 4 ); |
157 | | - t.strictEqual( out, 0x20, 'returns expected value' ); |
158 | | - |
159 | | - out = codePointAt( 'last man standing', -13 ); |
160 | | - t.strictEqual( out, 0x20, 'returns expected value' ); |
161 | | - |
162 | | - out = codePointAt( 'presidential election', 8, true ); |
163 | | - t.strictEqual( out, 0x74, 'returns expected value' ); |
164 | | - |
165 | | - out = codePointAt( 'presidential election', -13, true ); |
166 | | - t.strictEqual( out, 0x74, 'returns expected value' ); |
167 | | - |
168 | | - out = codePointAt( 'अनुच्छेद', 2 ); |
169 | | - t.strictEqual( out, 0x941, 'returns expected value' ); |
170 | | - |
171 | | - out = codePointAt( 'अनुच्छेद', -6 ); |
172 | | - t.strictEqual( out, 0x941, 'returns expected value' ); |
173 | | - |
174 | | - out = codePointAt( '🌷', 0, true ); |
175 | | - t.strictEqual( out, 0x1F337, 'returns expected value' ); |
176 | | - |
177 | | - out = codePointAt( '🌷', -2, true ); |
178 | | - t.strictEqual( out, 0x1F337, 'returns expected value' ); |
179 | | - |
| 31 | + t.strictEqual( main !== void 0, true, 'main export is defined' ); |
180 | 32 | t.end(); |
181 | 33 | }); |
0 commit comments