File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -814,4 +814,31 @@ test('allows to clone nodes', () => {
814814 is ( root2 . toString ( ) , 'a { color: black; z-index: 1 } b {}' )
815815} )
816816
817+ test ( 'container.nodes can be sorted' , ( ) => {
818+ let root = parse ( '@b; @c; @a;' )
819+ let b = root . nodes [ 0 ] ;
820+
821+ root . nodes . sort ( ( x , y ) => {
822+ return ( x as AtRule ) . name . localeCompare ( ( y as AtRule ) . name )
823+ } )
824+
825+ // Sorted nodes are reflected in "toString".
826+ is ( root . toString ( ) , ' @a;@b; @c;' )
827+
828+ // Sorted nodes are reflected in "walk".
829+ let result : string [ ] = [ ] ;
830+ root . walkAtRules ( ( atRule ) => {
831+ result . push ( atRule . name . trim ( ) )
832+ } ) ;
833+
834+ is ( result . join ( ' ' ) , 'a b c' )
835+
836+ // Sorted nodes have the corect "index".
837+ is ( root . index ( b ) , 1 )
838+
839+ // Inserting after a sorted node results in the correct order.
840+ b . after ( '@d;' ) ;
841+ is ( root . toString ( ) , ' @a;@b;@d; @c;' )
842+ } )
843+
817844test . run ( )
You can’t perform that action at this time.
0 commit comments