1- import test from 'tape'
1+ import assert from 'node:assert/strict'
2+ import test from 'node:test'
23import { franc , francAll } from '../packages/franc/index.js'
34import { fixtures } from './fixtures.js'
45
@@ -11,16 +12,24 @@ if (languageA === franc(fixtureB)) {
1112 throw new Error ( 'a and b should not be equal...' )
1213}
1314
14- test ( 'franc()' , ( t ) => {
15- t . equal ( typeof franc , 'function' , 'should be of type `function`' )
16- t . equal ( typeof franc ( 'XYZ' ) , 'string' , 'should return a string' )
17- t . equal ( franc ( 'XYZ' ) , 'und' , 'should return "und" on an undetermined value' )
18- t . equal ( franc ( ) , 'und' , 'should return "und" on a missing value' )
19- t . equal ( franc ( 'the the the the the ' ) , 'sco' , 'should work on weird values' )
15+ test ( 'franc()' , ( ) => {
16+ assert . equal ( typeof franc , 'function' , 'should be of type `function`' )
17+ assert . equal ( typeof franc ( 'XYZ' ) , 'string' , 'should return a string' )
18+ assert . equal (
19+ franc ( 'XYZ' ) ,
20+ 'und' ,
21+ 'should return "und" on an undetermined value'
22+ )
23+ assert . equal ( franc ( ) , 'und' , 'should return "und" on a missing value' )
24+ assert . equal (
25+ franc ( 'the the the the the ' ) ,
26+ 'sco' ,
27+ 'should work on weird values'
28+ )
2029
2130 /* Inspired by lifthrasiir on hackernews:
2231 * https://news.ycombinator.com/item?id=8405672 */
23- t . equal (
32+ assert . equal (
2433 franc (
2534 [
2635 '한국어 문서가 전 세계 웹에서 차지하는 비중은 2004년에 4.1%로, 이는 영어(35.8%), ' ,
@@ -33,7 +42,7 @@ test('franc()', (t) => {
3342 'should work on unique-scripts with many latin characters (1)'
3443 )
3544
36- t . equal (
45+ assert . equal (
3746 franc (
3847 [
3948 '現行の学校文法では、英語にあるような「目的語」「補語」などの成分はないとする。' ,
@@ -46,13 +55,13 @@ test('franc()', (t) => {
4655 'should work on unique-scripts with many latin characters (2)'
4756 )
4857
49- t . equal (
58+ assert . equal (
5059 franc ( 'すべての人は、生命、自由及び身体の安全に対する権利を有する。' ) ,
5160 'jpn' ,
5261 'should detect Japanese even when Han ratio > 0.5 (udhr_jpn art 3) (1)'
5362 )
5463
55- t . equal (
64+ assert . equal (
5665 franc (
5766 [
5867 'すべての人は、憲法又は法律によって与えられた基本的権利を侵害する行為に対し、' ,
@@ -63,7 +72,7 @@ test('franc()', (t) => {
6372 'should detect Japanese even when Han ratio > 0.5 (udhr_jpn art 8) (2)'
6473 )
6574
66- t . equal (
75+ assert . equal (
6776 franc (
6877 [
6978 '成年の男女は、人種、国籍又は宗教によるいかなる制限をも受けることなく、婚姻し、' ,
@@ -76,58 +85,64 @@ test('franc()', (t) => {
7685 'should detect Japanese even when Han ratio > 0.5 (udhr_jpn art 16) (3)'
7786 )
7887
79- t . notEqual (
88+ assert . notEqual (
8089 franc ( fixtureB , { ignore : [ franc ( fixtureB ) ] } ) ,
8190 franc ( fixtureB ) ,
8291 'should accept `ignore`'
8392 )
8493
85- t . deepEqual (
94+ assert . deepEqual (
8695 franc ( fixtures . aii . fixture , { ignore : [ 'aii' ] } ) ,
8796 'und' ,
8897 'should support `ignore` if the script can only be in that language'
8998 )
9099
91- t . equal (
100+ assert . equal (
92101 franc ( fixtureB , { only : [ languageA ] } ) ,
93102 languageA ,
94103 'should accept `only`'
95104 )
96105
97- t . equal (
106+ assert . equal (
98107 franc ( hebrew , { only : [ 'eng' ] } ) ,
99108 'und' ,
100109 'should accept `only` for different scripts'
101110 )
102111
103- t . equal ( franc ( 'the' , { minLength : 3 } ) , 'sco' , 'should accept `minLength` (1)' )
104- t . equal ( franc ( 'the' , { minLength : 4 } ) , 'und' , 'should accept `minLength` (2)' )
112+ assert . equal (
113+ franc ( 'the' , { minLength : 3 } ) ,
114+ 'sco' ,
115+ 'should accept `minLength` (1)'
116+ )
117+ assert . equal (
118+ franc ( 'the' , { minLength : 4 } ) ,
119+ 'und' ,
120+ 'should accept `minLength` (2)'
121+ )
105122
106- t . equal (
123+ assert . equal (
107124 franc ( '987 654 321' ) ,
108125 'und' ,
109126 'should return `und` for generic characters'
110127 )
111-
112- t . end ( )
113128} )
114129
115- test ( 'francAll()' , ( t ) => {
116- t . equal ( typeof francAll , 'function' , 'should be of type `function`' )
130+ test ( 'francAll()' , ( ) => {
131+ assert . equal ( typeof francAll , 'function' , 'should be of type `function`' )
117132
118- t . deepEqual (
133+ assert . deepEqual (
119134 francAll ( 'XYZ' ) ,
120135 [ [ 'und' , 1 ] ] ,
121136 'should return an array containing language--probability tuples'
122137 )
123138
124- t . deepEqual (
139+ assert . deepEqual (
125140 francAll ( 'פאר טסי' ) ,
126141 [ [ 'und' , 1 ] ] ,
127142 'should return `[["und", 1]]` without matches (1)'
128143 )
129144
130- t . deepEqual (
145+ assert . deepEqual (
131146 francAll ( 'פאר טסי' , { minLength : 3 } ) ,
132147 [
133148 [ 'heb' , 0 ] ,
@@ -136,25 +151,25 @@ test('francAll()', (t) => {
136151 'should return `[["und", 1]]` without matches (2)'
137152 )
138153
139- t . deepEqual (
154+ assert . deepEqual (
140155 francAll ( 'xyz' ) ,
141156 [ [ 'und' , 1 ] ] ,
142157 'should return `[["und", 1]]` without matches (3)'
143158 )
144159
145- t . deepEqual (
160+ assert . deepEqual (
146161 francAll ( ) ,
147162 [ [ 'und' , 1 ] ] ,
148163 'should return `[["und", 1]]` for a missing value'
149164 )
150165
151- t . deepEqual (
166+ assert . deepEqual (
152167 francAll ( '987 654 321' ) ,
153168 [ [ 'und' , 1 ] ] ,
154169 'should return `[["und", 1]]` for generic characters'
155170 )
156171
157- t . deepEqual (
172+ assert . deepEqual (
158173 francAll ( 'the the the the the ' ) . slice ( 0 , 2 ) ,
159174 [
160175 [ 'sco' , 1 ] ,
@@ -163,7 +178,7 @@ test('francAll()', (t) => {
163178 'should work on weird values'
164179 )
165180
166- t . deepEqual (
181+ assert . deepEqual (
167182 francAll ( fixtureB , { ignore : [ franc ( fixtureB ) ] } )
168183 . map ( ( tuple ) => {
169184 return tuple [ 0 ]
@@ -173,19 +188,19 @@ test('francAll()', (t) => {
173188 'should accept `ignore`'
174189 )
175190
176- t . deepEqual (
191+ assert . deepEqual (
177192 francAll ( fixtureB , { only : [ languageA ] } ) ,
178193 [ [ languageA , 1 ] ] ,
179194 'should accept `only`'
180195 )
181196
182- t . deepEqual (
197+ assert . deepEqual (
183198 francAll ( hebrew , { only : [ 'eng' ] } ) ,
184199 [ [ 'und' , 1 ] ] ,
185200 'should accept `only` for different scripts'
186201 )
187202
188- t . deepEqual (
203+ assert . deepEqual (
189204 francAll ( 'the' , { minLength : 3 } ) . slice ( 0 , 2 ) ,
190205 [
191206 [ 'sco' , 1 ] ,
@@ -194,16 +209,14 @@ test('francAll()', (t) => {
194209 'should accept `minLength` (1)'
195210 )
196211
197- t . deepEqual (
212+ assert . deepEqual (
198213 francAll ( 'the' , { minLength : 4 } ) ,
199214 [ [ 'und' , 1 ] ] ,
200215 'should accept `minLength` (2)'
201216 )
202-
203- t . end ( )
204217} )
205218
206- test ( 'algorithm' , ( t ) => {
219+ test ( 'algorithm' , ( ) => {
207220 const keys = Object . keys ( fixtures )
208221
209222 // Failing for some reason.
@@ -215,7 +228,7 @@ test('algorithm', (t) => {
215228
216229 if ( ignore . has ( info . iso6393 ) ) continue
217230
218- t . equal (
231+ assert . equal (
219232 francAll ( info . fixture ) [ 0 ] [ 0 ] ,
220233 info . iso6393 ,
221234 info . fixture . replace ( / \n / g, '\\n' ) . slice ( 0 , 20 ) +
@@ -224,6 +237,4 @@ test('algorithm', (t) => {
224237 ')'
225238 )
226239 }
227-
228- t . end ( )
229240} )
0 commit comments