| 
1 | 1 | /**  | 
2 | 2 | * @license Apache-2.0  | 
3 | 3 | *  | 
4 |  | -* Copyright (c) 2021 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 substringAfter = 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 substringAfter, 'function', 'main export is a function' );  | 
32 |  | -	t.end();  | 
33 |  | -});  | 
34 |  | - | 
35 |  | -tape( 'the function throws an error if not provided a string as its first argument', function test( t ) {  | 
36 |  | -	var values;  | 
37 |  | -	var i;  | 
38 |  | - | 
39 |  | -	values = [  | 
40 |  | -		5,  | 
41 |  | -		NaN,  | 
42 |  | -		true,  | 
43 |  | -		false,  | 
44 |  | -		null,  | 
45 |  | -		void 0,  | 
46 |  | -		[],  | 
47 |  | -		{},  | 
48 |  | -		function noop() {}  | 
49 |  | -	];  | 
50 |  | - | 
51 |  | -	for ( i = 0; i < values.length; i++ ) {  | 
52 |  | -		t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );  | 
53 |  | -	}  | 
54 |  | -	t.end();  | 
55 |  | - | 
56 |  | -	function badValue( value ) {  | 
57 |  | -		return function badValue() {  | 
58 |  | -			substringAfter( value, 'beep' );  | 
59 |  | -		};  | 
60 |  | -	}  | 
61 |  | -});  | 
62 |  | - | 
63 |  | -tape( 'the function throws an error if not provided a string as its second argument', function test( t ) {  | 
64 |  | -	var values;  | 
65 |  | -	var i;  | 
66 |  | - | 
67 |  | -	values = [  | 
68 |  | -		5,  | 
69 |  | -		NaN,  | 
70 |  | -		true,  | 
71 |  | -		false,  | 
72 |  | -		null,  | 
73 |  | -		void 0,  | 
74 |  | -		[],  | 
75 |  | -		{},  | 
76 |  | -		function noop() {}  | 
77 |  | -	];  | 
78 |  | - | 
79 |  | -	for ( i = 0; i < values.length; i++ ) {  | 
80 |  | -		t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );  | 
81 |  | -	}  | 
82 |  | -	t.end();  | 
83 |  | - | 
84 |  | -	function badValue( value ) {  | 
85 |  | -		return function badValue() {  | 
86 |  | -			substringAfter( 'beep', value );  | 
87 |  | -		};  | 
88 |  | -	}  | 
89 |  | -});  | 
90 |  | - | 
91 |  | -tape( 'the function throws an error if provided a non-integer value as its third argument', function test( t ) {  | 
92 |  | -	var values;  | 
93 |  | -	var i;  | 
94 |  | - | 
95 |  | -	values = [  | 
96 |  | -		'5',  | 
97 |  | -		3.14,  | 
98 |  | -		NaN,  | 
99 |  | -		true,  | 
100 |  | -		false,  | 
101 |  | -		null,  | 
102 |  | -		void 0,  | 
103 |  | -		[],  | 
104 |  | -		{},  | 
105 |  | -		function noop() {}  | 
106 |  | -	];  | 
107 |  | - | 
108 |  | -	for ( i = 0; i < values.length; i++ ) {  | 
109 |  | -		t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );  | 
110 |  | -	}  | 
111 |  | -	t.end();  | 
112 |  | - | 
113 |  | -	function badValue( value ) {  | 
114 |  | -		return function badValue() {  | 
115 |  | -			substringAfter( 'beep', 'e', value );  | 
116 |  | -		};  | 
117 |  | -	}  | 
118 |  | -});  | 
119 |  | - | 
120 |  | -tape( 'the function returns the substring after a provided search string', function test( t ) {  | 
121 |  | -	var expected;  | 
122 |  | -	var actual;  | 
123 |  | -	var str;  | 
124 |  | - | 
125 |  | -	str = 'beep boop';  | 
126 |  | -	actual = substringAfter( str, ' ' );  | 
127 |  | -	expected = 'boop';  | 
128 |  | -	t.strictEqual( actual, expected, 'returns expected value' );  | 
129 |  | - | 
130 |  | -	str = 'beep boop';  | 
131 |  | -	actual = substringAfter( str, 'p' );  | 
132 |  | -	expected = ' boop';  | 
133 |  | -	t.strictEqual( actual, expected, 'returns expected value' );  | 
134 |  | - | 
135 |  | -	str = 'Hello, World!';  | 
136 |  | -	actual = substringAfter( str, 'o' );  | 
137 |  | -	expected = ', World!';  | 
138 |  | -	t.strictEqual( actual, expected, 'returns expected value' );  | 
139 |  | - | 
140 |  | -	t.end();  | 
141 |  | -});  | 
142 |  | - | 
143 |  | -tape( 'the function returns the substring after a provided search string (Unicode characters)', function test( t ) {  | 
144 |  | -	var expected;  | 
145 |  | -	var actual;  | 
146 |  | -	var str;  | 
147 |  | - | 
148 |  | -	str = 'beep 😀 boop 😀 baz';  | 
149 |  | -	actual = substringAfter( str, '😀' );  | 
150 |  | -	expected = ' boop 😀 baz';  | 
151 |  | -	t.strictEqual( actual, expected, 'returns expected value' );  | 
152 |  | - | 
153 |  | -	str = '🤖 Robot army 🤖!';  | 
154 |  | -	actual = substringAfter( str, '🤖' );  | 
155 |  | -	expected = ' Robot army 🤖!';  | 
156 |  | - | 
157 |  | -	str = '🐺 Wolf brothers 🐺';  | 
158 |  | -	actual = substringAfter( str, 'o' );  | 
159 |  | -	expected = 'lf brothers 🐺';  | 
160 |  | - | 
161 |  | -	t.end();  | 
162 |  | -});  | 
163 |  | - | 
164 |  | -tape( 'the function returns the substring after a provided search string (custom start index)', function test( t ) {  | 
165 |  | -	var expected;  | 
166 |  | -	var actual;  | 
167 |  | -	var str;  | 
168 |  | - | 
169 |  | -	str = 'beep boop baz';  | 
170 |  | -	actual = substringAfter( str, ' ', 6 );  | 
171 |  | -	expected = 'baz';  | 
172 |  | -	t.strictEqual( actual, expected, 'returns expected value' );  | 
173 |  | - | 
174 |  | -	str = 'beep boop baz';  | 
175 |  | -	actual = substringAfter( str, 'p', 6 );  | 
176 |  | -	expected = ' baz';  | 
177 |  | - | 
178 |  | -	str = 'beep boop baz';  | 
179 |  | -	actual = substringAfter( str, 'beep', -2 );  | 
180 |  | -	expected = ' boop baz';  | 
181 |  | - | 
182 |  | -	str = 'beep boop baz';  | 
183 |  | -	actual = substringAfter( str, 'beep', 20 );  | 
184 |  | -	expected = '';  | 
185 |  | - | 
186 |  | -	t.end();  | 
187 |  | -});  | 
188 |  | - | 
189 |  | -tape( 'the function returns the empty string if the search string is not found', function test( t ) {  | 
190 |  | -	var expected;  | 
191 |  | -	var actual;  | 
192 |  | -	var str;  | 
193 |  | - | 
194 |  | -	str = 'beep boop';  | 
195 |  | -	actual = substringAfter( str, 'z' );  | 
196 |  | -	expected = '';  | 
197 |  | -	t.strictEqual( actual, expected, 'returns expected value' );  | 
198 |  | - | 
199 |  | -	str = 'beep boop';  | 
200 |  | -	actual = substringAfter( str, 'baz' );  | 
201 |  | -	expected = '';  | 
202 |  | -	t.strictEqual( actual, expected, 'returns expected value' );  | 
203 |  | - | 
204 |  | -	t.end();  | 
205 |  | -});  | 
206 |  | - | 
207 |  | -tape( 'the function returns the original string if the search string is the empty string', function test( t ) {  | 
208 |  | -	var expected;  | 
209 |  | -	var actual;  | 
210 |  | -	var str;  | 
211 |  | - | 
212 |  | -	str = 'beep boop';  | 
213 |  | -	actual = substringAfter( str, '' );  | 
214 |  | -	expected = 'beep boop';  | 
215 |  | -	t.strictEqual( actual, expected, 'returns expected value' );  | 
216 |  | - | 
 | 31 | +	t.strictEqual( main !== void 0, true, 'main export is defined' );  | 
217 | 32 | 	t.end();  | 
218 | 33 | });  | 
0 commit comments