This repository has been archived by the owner on Apr 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathscope.js
executable file
·108 lines (75 loc) · 2.79 KB
/
scope.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Load modules
var Chai = require('chai');
var Oz = require('../lib');
// Declare internals
var internals = {};
// Test shortcuts
var expect = Chai.expect;
describe('Scope', function () {
describe('#validate', function () {
it('should return true for valid scope', function (done) {
var scope = ['a', 'b', 'c'];
var err = Oz.scope.validate(scope);
expect(err).to.equal(true);
done();
});
it('should return error when scope is null', function (done) {
var err = Oz.scope.validate(null);
expect(err).to.exist;
done();
});
it('should return error when scope is not an array', function (done) {
var err = Oz.scope.validate({});
expect(err).to.exist;
done();
});
it('should return error when scope contains non-string values', function (done) {
var scope = ['a', 'b', 1];
var err = Oz.scope.validate(scope);
expect(err).to.exist;
done();
});
it('should return error when scope contains duplicates', function (done) {
var scope = ['a', 'b', 'b'];
var err = Oz.scope.validate(scope);
expect(err).to.exist;
done();
});
it('should return error when scope contains empty strings', function (done) {
var scope = ['a', 'b', ''];
var err = Oz.scope.validate(scope);
expect(err).to.exist;
done();
});
});
describe('#isSubset', function () {
it('should return true when scope is a subset', function (done) {
var scope = ['a', 'b', 'c'];
var subset = ['a', 'c'];
var isSubset = Oz.scope.isSubset(scope, subset);
expect(isSubset).to.equal(true);
done();
});
it('should return false when scope is not a subset', function (done) {
var scope = ['a'];
var subset = ['a', 'c'];
var isSubset = Oz.scope.isSubset(scope, subset);
expect(isSubset).to.equal(false);
done();
});
it('should return false when scope is not a subset but equal length', function (done) {
var scope = ['a', 'b'];
var subset = ['a', 'c'];
var isSubset = Oz.scope.isSubset(scope, subset);
expect(isSubset).to.equal(false);
done();
});
it('should return false when scope is not a subset due to duplicates', function (done) {
var scope = ['a', 'c', 'c', 'd'];
var subset = ['a', 'c', 'c'];
var isSubset = Oz.scope.isSubset(scope, subset);
expect(isSubset).to.equal(false);
done();
});
});
});