11import { strict as assert } from 'node:assert'
22import { suite , test } from 'node:test'
33
4- import { validatedTld } from './utils.ts'
4+ import { isDomain , validatedTld } from './utils.ts'
5+
6+ suite ( 'isDomain()' , ( ) => {
7+ test ( 'invalid domains' , function ( ) {
8+ assert . equal ( false , isDomain ( '' ) , 'empty' )
9+ assert . equal ( false , isDomain ( 'c' ) , 'too short' )
10+ assert . equal ( false , isDomain ( 'c om' ) , 'contains space' )
11+ assert . equal ( false , isDomain ( 'domain' ) , 'no tld' )
12+ assert . equal ( false , isDomain ( '-example.com' ) , 'starts with hyphen' )
13+ assert . equal ( false , isDomain ( 'example.com1' ) , 'tld contains number' )
14+ assert . throws ( ( ) => validatedTld ( 'clearlyinvalidtldbecasuethisistoooooooooooooloooooooooooooooooong.com' ) , 'too long' )
15+ } )
16+
17+ test ( 'valid domain string' , function ( ) {
18+ assert . ok ( isDomain ( 'example.com' ) )
19+ assert . ok ( isDomain ( '.example.com.' ) )
20+ assert . ok ( isDomain ( 'youtu.be' ) )
21+ assert . ok ( isDomain ( 'blog.google' ) )
22+ } )
23+ } )
524
625suite ( 'validatedTld()' , ( ) => {
7- test ( 'invalid TLDs' , function ( ) {
26+ test ( 'invalid TLDs' , function ( ) {
827 assert . throws ( ( ) => validatedTld ( '' ) , 'empty' )
928 assert . throws ( ( ) => validatedTld ( 'c' ) , 'too short' )
1029 assert . throws ( ( ) => validatedTld ( 'c om' ) , 'contains space' )
@@ -15,18 +34,18 @@ suite('validatedTld()', () => {
1534 assert . throws ( ( ) => validatedTld ( 'clearlyinvalidtldbecasuethisistoooooooooooooloooooooooooooooooong' ) , 'too long' )
1635 } )
1736
18- test ( 'valid - TLDs' , function ( ) {
37+ test ( 'valid - TLDs' , function ( ) {
1938 assert . equal ( validatedTld ( '.com' ) , 'com' )
2039 assert . equal ( validatedTld ( 'org.' ) , 'org' )
2140 assert . equal ( validatedTld ( 'AI' ) , 'ai' )
2241 assert . equal ( validatedTld ( '.nyc' ) , 'nyc' )
2342 } )
2443
25- test ( 'valid - SLDs' , function ( ) {
44+ test ( 'valid - SLDs' , function ( ) {
2645 assert . equal ( validatedTld ( '.co.uk' ) , 'co.uk' )
2746 } )
2847
29- test ( 'valid - IDN' , function ( ) {
48+ test ( 'valid - IDN' , function ( ) {
3049 assert . equal ( validatedTld ( 'xn--zckzah' ) , 'xn--zckzah' )
3150 assert . equal ( validatedTld ( 'テスト' ) , 'テスト' )
3251 assert . equal ( validatedTld ( '.香港' ) , '香港' )
0 commit comments