-
Notifications
You must be signed in to change notification settings - Fork 0
/
path_test.js
74 lines (60 loc) · 2.28 KB
/
path_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const unitJS = require('unit.js')
const { ErrArguments } = require('./errors')
const { Separator, Path, FileInfo } = require('./path')
describe('Seperator', () => {
it('valid', () => {
unitJS.assert.equal('/', Separator)
})
})
describe('Path Tests', () => {
it('all', () => {
const p = new Path()
unitJS.assert.equal(false, p.IsVirtual())
unitJS.assert.equal(false, p.IsDir())
unitJS.assert.equal(false, p.Exists())
unitJS.assert.equal('', p.Name())
unitJS.assert.equal('', p.String())
unitJS.value(p.ParentPath()).is(new Path())
unitJS.value(p.ExcludePath(new Path())).is(new Path())
unitJS.value(p.Info()).is(new FileInfo())
})
})
describe('FileInfo Tests', () => {
it('with valid params', () => {
const fileInfo = new FileInfo(true, 2, 3, 'permission')
unitJS.assert.equal(true, fileInfo.IsDir)
unitJS.assert.equal(2, fileInfo.Size)
unitJS.assert.equal(3, fileInfo.CreatedAt)
unitJS.assert.equal('permission', fileInfo.Permission)
})
it('Should be throw ErrArguments with invalid size ', () => {
unitJS.error(() => {
new FileInfo(true, -1, 0, 'perm')
}).is(ErrArguments)
})
it('.ToJSON()', () => {
const jsonValue = `{"IsDir":true,"Size":3,"CreatedAt":4,"Permission":"perm1"}`,
fileInfo = new FileInfo(true, 3, 4, 'perm1')
unitJS.assert.equal(jsonValue, fileInfo.ToJSON())
})
it('.FromJSON()', () => {
const jsonValue = `{"IsDir":true,"Size":3,"CreatedAt":4,"Permission":"perm1"}`,
{ fileInfo, error } = new FileInfo().FromJSON(jsonValue)
unitJS.value(error).isNull()
unitJS.assert.equal(true, fileInfo.IsDir)
unitJS.assert.equal(3, fileInfo.Size)
unitJS.assert.equal(4, fileInfo.CreatedAt)
unitJS.assert.equal('perm1', fileInfo.Permission)
})
it('Should be SyntaxError .FromJSON() is invalid json string', () => {
const { fileInfo, error } = new FileInfo().FromJSON('invalid')
unitJS.value(error).isInstanceOf(Error)
unitJS.value(fileInfo).isNull()
})
it('Should be SyntaxError .FromJSON() is invalid CreatedAt', () => {
const jsonValue = `{"IsDir":true,"Size":3,"CreatedAt":-1,"Permission":"perm1"}`,
{ fileInfo, error } = new FileInfo().FromJSON(jsonValue)
unitJS.value(error).is(ErrArguments)
unitJS.value(fileInfo).isNull()
})
})