@@ -2,86 +2,74 @@ import assert from 'node:assert/strict'
2
2
import test from 'node:test'
3
3
import { h } from 'hastscript'
4
4
import { shiftHeading } from './index.js'
5
- import * as mod from './index.js'
6
5
7
- test ( 'shiftHeading' , ( ) => {
8
- assert . deepEqual (
9
- Object . keys ( mod ) . sort ( ) ,
10
- [ 'shiftHeading' ] ,
11
- 'should expose the public api'
12
- )
6
+ test ( 'shiftHeading' , async function ( t ) {
7
+ await t . test ( 'should expose the public api' , async function ( ) {
8
+ assert . deepEqual ( Object . keys ( await import ( './index.js' ) ) . sort ( ) , [
9
+ 'shiftHeading'
10
+ ] )
11
+ } )
13
12
14
- assert . throws (
15
- ( ) => {
16
- // @ts -ignore runtime .
13
+ await t . test ( 'should throw when not given a number' , async function ( ) {
14
+ assert . throws ( function ( ) {
15
+ // @ts -ignore: check how a missing `shift` is handled .
17
16
shiftHeading ( h ( '' ) )
18
- } ,
19
- / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` u n d e f i n e d ` $ / ,
20
- 'should throw when not given a number'
21
- )
17
+ } , / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` u n d e f i n e d ` $ / )
18
+ } )
22
19
23
- assert . throws (
24
- ( ) => {
20
+ await t . test ( 'should throw when given not a number' , async function ( ) {
21
+ assert . throws ( function ( ) {
25
22
shiftHeading ( h ( '' ) , Number . NaN )
26
- } ,
27
- / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` N a N ` $ / ,
28
- 'should throw when given not a number'
29
- )
23
+ } , / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` N a N ` $ / )
24
+ } )
30
25
31
- assert . throws (
32
- ( ) => {
26
+ await t . test ( 'should throw when not given an integer' , async function ( ) {
27
+ assert . throws ( function ( ) {
33
28
shiftHeading ( h ( '' ) , 0.1 )
34
- } ,
35
- / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` 0 .1 ` $ / ,
36
- 'should throw when not given an integer'
37
- )
29
+ } , / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` 0 .1 ` $ / )
30
+ } )
38
31
39
- assert . throws (
40
- ( ) => {
41
- shiftHeading ( h ( '' ) , Number . POSITIVE_INFINITY )
42
- } ,
43
- / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` I n f i n i t y ` $ / ,
44
- 'should throw when not given a finite number'
32
+ await t . test (
33
+ 'should throw when not given a finite number' ,
34
+ async function ( ) {
35
+ assert . throws ( function ( ) {
36
+ shiftHeading ( h ( '' ) , Number . POSITIVE_INFINITY )
37
+ } , / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` I n f i n i t y ` $ / )
38
+ }
45
39
)
46
40
47
- assert . throws (
48
- ( ) => {
49
- shiftHeading ( h ( '' ) , 0 )
50
- } ,
51
- / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` 0 ` $ / ,
52
- 'should throw when not given a non-null number'
41
+ await t . test (
42
+ 'should throw when not given a non-null number' ,
43
+ async function ( ) {
44
+ assert . throws ( function ( ) {
45
+ shiftHeading ( h ( '' ) , 0 )
46
+ } , / ^ E r r o r : E x p e c t e d a n o n - n u l l f i n i t e i n t e g e r , n o t ` 0 ` $ / )
47
+ }
53
48
)
54
49
55
- assert . deepEqual (
56
- shiftHeading ( h ( 'h1' , 'Alpha' ) , 1 ) ,
57
- h ( 'h2' , 'Alpha' ) ,
58
- 'should shift nodes upwards'
59
- )
50
+ await t . test ( 'should shift nodes upwards' , async function ( ) {
51
+ assert . deepEqual ( shiftHeading ( h ( 'h1' , 'Alpha' ) , 1 ) , h ( 'h2' , 'Alpha' ) )
52
+ } )
60
53
61
- assert . deepEqual (
62
- shiftHeading ( h ( 'h2' , 'Bravo' ) , - 1 ) ,
63
- h ( 'h1' , 'Bravo' ) ,
64
- 'should shift nodes downwards'
65
- )
54
+ await t . test ( 'should shift nodes downwards' , async function ( ) {
55
+ assert . deepEqual ( shiftHeading ( h ( 'h2' , 'Bravo' ) , - 1 ) , h ( 'h1' , 'Bravo' ) )
56
+ } )
66
57
67
- assert . deepEqual (
68
- shiftHeading ( h ( 'h2' , 'Charlie' ) , - 2 ) ,
69
- h ( 'h1' , 'Charlie' ) ,
70
- 'should not shift upwards past h1'
71
- )
58
+ await t . test ( 'should not shift upwards past h1' , async function ( ) {
59
+ assert . deepEqual ( shiftHeading ( h ( 'h2' , 'Charlie' ) , - 2 ) , h ( 'h1' , 'Charlie' ) )
60
+ } )
72
61
73
- assert . deepEqual (
74
- shiftHeading ( h ( 'h5' , 'Delta' ) , 2 ) ,
75
- h ( 'h6' , 'Delta' ) ,
76
- 'should not shift downwards past h6'
77
- )
62
+ await t . test ( 'should not shift downwards past h6' , async function ( ) {
63
+ assert . deepEqual ( shiftHeading ( h ( 'h5' , 'Delta' ) , 2 ) , h ( 'h6' , 'Delta' ) )
64
+ } )
78
65
79
- assert . deepEqual (
80
- shiftHeading (
81
- h ( 'main' , [ h ( 'h1' , 'Echo' ) , h ( 'p' , 'Foxtrot' ) , h ( 'h5' , 'Golf' ) ] ) ,
82
- 2
83
- ) ,
84
- h ( 'main' , [ h ( 'h3' , 'Echo' ) , h ( 'p' , 'Foxtrot' ) , h ( 'h6' , 'Golf' ) ] ) ,
85
- 'should change a tree'
86
- )
66
+ await t . test ( 'should change a tree' , async function ( ) {
67
+ assert . deepEqual (
68
+ shiftHeading (
69
+ h ( 'main' , [ h ( 'h1' , 'Echo' ) , h ( 'p' , 'Foxtrot' ) , h ( 'h5' , 'Golf' ) ] ) ,
70
+ 2
71
+ ) ,
72
+ h ( 'main' , [ h ( 'h3' , 'Echo' ) , h ( 'p' , 'Foxtrot' ) , h ( 'h6' , 'Golf' ) ] )
73
+ )
74
+ } )
87
75
} )
0 commit comments