|
| 1 | +'use strict' |
| 2 | + |
| 3 | +/* eslint-env mocha */ |
| 4 | +const chai = require('chai') |
| 5 | +const dirtyChai = require('dirty-chai') |
| 6 | +const formatMode = require('../../src/files/format-mode') |
| 7 | + |
| 8 | +chai.use(dirtyChai) |
| 9 | +const expect = chai.expect |
| 10 | + |
| 11 | +describe('format-mode', function () { |
| 12 | + it('formats mode for directories', function () { |
| 13 | + expect(formatMode(parseInt('0777', 8), true)).to.equal('drwxrwxrwx') |
| 14 | + }) |
| 15 | + |
| 16 | + it('formats mode for files', function () { |
| 17 | + expect(formatMode(parseInt('0777', 8), false)).to.equal('-rwxrwxrwx') |
| 18 | + }) |
| 19 | + |
| 20 | + it('setgid, setuid and stick bit', function () { |
| 21 | + expect(formatMode(parseInt('1777', 8), false)).to.equal('-rwxrwxrwt') |
| 22 | + expect(formatMode(parseInt('2777', 8), false)).to.equal('-rwxrwsrwx') |
| 23 | + expect(formatMode(parseInt('4777', 8), false)).to.equal('-rwsrwxrwx') |
| 24 | + expect(formatMode(parseInt('5777', 8), false)).to.equal('-rwsrwxrwt') |
| 25 | + expect(formatMode(parseInt('6777', 8), false)).to.equal('-rwsrwsrwx') |
| 26 | + expect(formatMode(parseInt('7777', 8), false)).to.equal('-rwsrwsrwt') |
| 27 | + }) |
| 28 | + |
| 29 | + it('formats user', function () { |
| 30 | + expect(formatMode(parseInt('0100', 8), false)).to.equal('---x------') |
| 31 | + expect(formatMode(parseInt('0200', 8), false)).to.equal('--w-------') |
| 32 | + expect(formatMode(parseInt('0300', 8), false)).to.equal('--wx------') |
| 33 | + expect(formatMode(parseInt('0400', 8), false)).to.equal('-r--------') |
| 34 | + expect(formatMode(parseInt('0500', 8), false)).to.equal('-r-x------') |
| 35 | + expect(formatMode(parseInt('0600', 8), false)).to.equal('-rw-------') |
| 36 | + expect(formatMode(parseInt('0700', 8), false)).to.equal('-rwx------') |
| 37 | + }) |
| 38 | + |
| 39 | + it('formats group', function () { |
| 40 | + expect(formatMode(parseInt('0010', 8), false)).to.equal('------x---') |
| 41 | + expect(formatMode(parseInt('0020', 8), false)).to.equal('-----w----') |
| 42 | + expect(formatMode(parseInt('0030', 8), false)).to.equal('-----wx---') |
| 43 | + expect(formatMode(parseInt('0040', 8), false)).to.equal('----r-----') |
| 44 | + expect(formatMode(parseInt('0050', 8), false)).to.equal('----r-x---') |
| 45 | + expect(formatMode(parseInt('0060', 8), false)).to.equal('----rw----') |
| 46 | + expect(formatMode(parseInt('0070', 8), false)).to.equal('----rwx---') |
| 47 | + }) |
| 48 | + |
| 49 | + it('formats other', function () { |
| 50 | + expect(formatMode(parseInt('0001', 8), false)).to.equal('---------x') |
| 51 | + expect(formatMode(parseInt('0002', 8), false)).to.equal('--------w-') |
| 52 | + expect(formatMode(parseInt('0003', 8), false)).to.equal('--------wx') |
| 53 | + expect(formatMode(parseInt('0004', 8), false)).to.equal('-------r--') |
| 54 | + expect(formatMode(parseInt('0005', 8), false)).to.equal('-------r-x') |
| 55 | + expect(formatMode(parseInt('0006', 8), false)).to.equal('-------rw-') |
| 56 | + expect(formatMode(parseInt('0007', 8), false)).to.equal('-------rwx') |
| 57 | + }) |
| 58 | +}) |
0 commit comments