@@ -609,3 +609,267 @@ tape( 'the function supports disabling permissions without specifying a user cla
609609 restore ( ) ;
610610 t . end ( ) ;
611611} ) ;
612+
613+ tape ( 'the function supports enabling permissions for the "user" user class' , function test ( t ) {
614+ var expected ;
615+ var values ;
616+ var opts ;
617+ var i ;
618+
619+ values = [
620+ 'u+' , // no effect
621+ 'u+r' ,
622+ 'u+w' ,
623+ 'u+x' ,
624+ 'u+rw' ,
625+ 'u+rx' ,
626+ 'u+wx' ,
627+ 'u+rwx'
628+ ] ;
629+ expected = [
630+ 'u=,g=,o=' , // no effect
631+ 'u=r,g=,o=' ,
632+ 'u=w,g=,o=' ,
633+ 'u=x,g=,o=' ,
634+ 'u=rw,g=,o=' ,
635+ 'u=rx,g=,o=' ,
636+ 'u=wx,g=,o=' ,
637+ 'u=rwx,g=,o='
638+ ] ;
639+
640+ opts = {
641+ 'symbolic' : true
642+ } ;
643+
644+ for ( i = 0 ; i < values . length ; i ++ ) {
645+ // Clear all bits:
646+ umask ( 'u=,g=,o=' ) ;
647+ t . equal ( umask ( ) , 511 , 'returns expected value' ) ; // 511 == 0o0777
648+
649+ // Enable permissions:
650+ umask ( values [ i ] ) ;
651+ t . equal ( umask ( opts ) , expected [ i ] , 'returns expected value' ) ;
652+ }
653+ restore ( ) ;
654+ t . end ( ) ;
655+ } ) ;
656+
657+ tape ( 'the function supports enabling permissions for the "group" user class' , function test ( t ) {
658+ var expected ;
659+ var values ;
660+ var opts ;
661+ var i ;
662+
663+ values = [
664+ 'g+' , // no effect
665+ 'g+r' ,
666+ 'g+w' ,
667+ 'g+x' ,
668+ 'g+rw' ,
669+ 'g+rx' ,
670+ 'g+wx' ,
671+ 'g+rwx'
672+ ] ;
673+ expected = [
674+ 'u=,g=,o=' , // no effect
675+ 'u=,g=r,o=' ,
676+ 'u=,g=w,o=' ,
677+ 'u=,g=x,o=' ,
678+ 'u=,g=rw,o=' ,
679+ 'u=,g=rx,o=' ,
680+ 'u=,g=wx,o=' ,
681+ 'u=,g=rwx,o='
682+ ] ;
683+
684+ opts = {
685+ 'symbolic' : true
686+ } ;
687+
688+ for ( i = 0 ; i < values . length ; i ++ ) {
689+ // Clear all bits:
690+ umask ( 'u=,g=,o=' ) ;
691+ t . equal ( umask ( ) , 511 , 'returns expected value' ) ; // 511 == 0o0777
692+
693+ // Enable permissions:
694+ umask ( values [ i ] ) ;
695+ t . equal ( umask ( opts ) , expected [ i ] , 'returns expected value' ) ;
696+ }
697+ restore ( ) ;
698+ t . end ( ) ;
699+ } ) ;
700+
701+ tape ( 'the function supports enabling permissions for the "non-group" user class' , function test ( t ) {
702+ var expected ;
703+ var values ;
704+ var opts ;
705+ var i ;
706+
707+ values = [
708+ 'o+' , // no effect
709+ 'o+r' ,
710+ 'o+w' ,
711+ 'o+x' ,
712+ 'o+rw' ,
713+ 'o+rx' ,
714+ 'o+wx' ,
715+ 'o+rwx'
716+ ] ;
717+ expected = [
718+ 'u=,g=,o=' , // no effect
719+ 'u=,g=,o=r' ,
720+ 'u=,g=,o=w' ,
721+ 'u=,g=,o=x' ,
722+ 'u=,g=,o=rw' ,
723+ 'u=,g=,o=rx' ,
724+ 'u=,g=,o=wx' ,
725+ 'u=,g=,o=rwx'
726+ ] ;
727+
728+ opts = {
729+ 'symbolic' : true
730+ } ;
731+
732+ for ( i = 0 ; i < values . length ; i ++ ) {
733+ // Clear all bits:
734+ umask ( 'u=,g=,o=' ) ;
735+ t . equal ( umask ( ) , 511 , 'returns expected value' ) ; // 511 == 0o0777
736+
737+ // Enable permissions:
738+ umask ( values [ i ] ) ;
739+ t . equal ( umask ( opts ) , expected [ i ] , 'returns expected value' ) ;
740+ }
741+ restore ( ) ;
742+ t . end ( ) ;
743+ } ) ;
744+
745+ tape ( 'the function supports disabling permissions for the "user" user class' , function test ( t ) {
746+ var expected ;
747+ var values ;
748+ var opts ;
749+ var i ;
750+
751+ values = [
752+ 'u-' , // no effect
753+ 'u-r' ,
754+ 'u-w' ,
755+ 'u-x' ,
756+ 'u-rw' ,
757+ 'u-rx' ,
758+ 'u-wx' ,
759+ 'u-rwx'
760+ ] ;
761+ expected = [
762+ 'u=rwx,g=rwx,o=rwx' , // no effect
763+ 'u=wx,g=rwx,o=rwx' ,
764+ 'u=rx,g=rwx,o=rwx' ,
765+ 'u=rw,g=rwx,o=rwx' ,
766+ 'u=x,g=rwx,o=rwx' ,
767+ 'u=w,g=rwx,o=rwx' ,
768+ 'u=r,g=rwx,o=rwx' ,
769+ 'u=,g=rwx,o=rwx'
770+ ] ;
771+
772+ opts = {
773+ 'symbolic' : true
774+ } ;
775+
776+ for ( i = 0 ; i < values . length ; i ++ ) {
777+ // Set all bits:
778+ umask ( 'u=rwx,g=rwx,o=rwx' ) ;
779+ t . equal ( umask ( ) , 0 , 'returns expected value' ) ; // 0 == 0o0000
780+
781+ // Disable permissions:
782+ umask ( values [ i ] ) ;
783+ t . equal ( umask ( opts ) , expected [ i ] , 'returns expected value' ) ;
784+ }
785+ restore ( ) ;
786+ t . end ( ) ;
787+ } ) ;
788+
789+ tape ( 'the function supports disabling permissions for the "group" user class' , function test ( t ) {
790+ var expected ;
791+ var values ;
792+ var opts ;
793+ var i ;
794+
795+ values = [
796+ 'g-' , // no effect
797+ 'g-r' ,
798+ 'g-w' ,
799+ 'g-x' ,
800+ 'g-rw' ,
801+ 'g-rx' ,
802+ 'g-wx' ,
803+ 'g-rwx'
804+ ] ;
805+ expected = [
806+ 'u=rwx,g=rwx,o=rwx' , // no effect
807+ 'u=rwx,g=wx,o=rwx' ,
808+ 'u=rwx,g=rx,o=rwx' ,
809+ 'u=rwx,g=rw,o=rwx' ,
810+ 'u=rwx,g=x,o=rwx' ,
811+ 'u=rwx,g=w,o=rwx' ,
812+ 'u=rwx,g=r,o=rwx' ,
813+ 'u=rwx,g=,o=rwx'
814+ ] ;
815+
816+ opts = {
817+ 'symbolic' : true
818+ } ;
819+
820+ for ( i = 0 ; i < values . length ; i ++ ) {
821+ // Set all bits:
822+ umask ( 'u=rwx,g=rwx,o=rwx' ) ;
823+ t . equal ( umask ( ) , 0 , 'returns expected value' ) ; // 0 == 0o0000
824+
825+ // Disable permissions:
826+ umask ( values [ i ] ) ;
827+ t . equal ( umask ( opts ) , expected [ i ] , 'returns expected value' ) ;
828+ }
829+ restore ( ) ;
830+ t . end ( ) ;
831+ } ) ;
832+
833+ tape ( 'the function supports disabling permissions for the "non-group" user class' , function test ( t ) {
834+ var expected ;
835+ var values ;
836+ var opts ;
837+ var i ;
838+
839+ values = [
840+ 'o-' , // no effect
841+ 'o-r' ,
842+ 'o-w' ,
843+ 'o-x' ,
844+ 'o-rw' ,
845+ 'o-rx' ,
846+ 'o-wx' ,
847+ 'o-rwx'
848+ ] ;
849+ expected = [
850+ 'u=rwx,g=rwx,o=rwx' , // no effect
851+ 'u=rwx,g=rwx,o=wx' ,
852+ 'u=rwx,g=rwx,o=rx' ,
853+ 'u=rwx,g=rwx,o=rw' ,
854+ 'u=rwx,g=rwx,o=x' ,
855+ 'u=rwx,g=rwx,o=w' ,
856+ 'u=rwx,g=rwx,o=r' ,
857+ 'u=rwx,g=rwx,o='
858+ ] ;
859+
860+ opts = {
861+ 'symbolic' : true
862+ } ;
863+
864+ for ( i = 0 ; i < values . length ; i ++ ) {
865+ // Set all bits:
866+ umask ( 'u=rwx,g=rwx,o=rwx' ) ;
867+ t . equal ( umask ( ) , 0 , 'returns expected value' ) ; // 0 == 0o0000
868+
869+ // Disable permissions:
870+ umask ( values [ i ] ) ;
871+ t . equal ( umask ( opts ) , expected [ i ] , 'returns expected value' ) ;
872+ }
873+ restore ( ) ;
874+ t . end ( ) ;
875+ } ) ;
0 commit comments