|
1
|
|
|
var chai = require('chai'); |
|
2
|
|
|
var path = require('path'); |
|
3
|
|
|
|
|
4
|
|
|
var config = require('../../../src/cli').config |
|
5
|
|
|
config.set({root: path.join(process.cwd(), 'test', 'fixtures')}) |
|
6
|
|
|
|
|
7
|
|
|
var cmsData = require('../../../src/cli').cmsData |
|
8
|
|
|
var Manager = require('../../../src/cli').Manager; |
|
9
|
|
|
var fse = require('fs-extra'); |
|
10
|
|
|
|
|
11
|
|
|
describe('regex', function() { |
|
12
|
|
|
before( function(done) { |
|
13
|
|
|
Manager.instance.init() |
|
14
|
|
|
.then(function () { |
|
15
|
|
|
|
|
16
|
|
|
this.fixture = { |
|
17
|
|
|
articleSingle: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article-single-abe.html'), 'utf8'), |
|
18
|
|
|
articleEach: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article-each-abe.html'), 'utf8'), |
|
19
|
|
|
articleRequest: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'article-request.html'), 'utf8') |
|
20
|
|
|
} |
|
21
|
|
|
done() |
|
22
|
|
|
|
|
23
|
|
|
}.bind(this)) |
|
24
|
|
|
}); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* cmsData.regex.getAttr |
|
28
|
|
|
*/ |
|
29
|
|
|
it('cmsData.regex.getAttr()', function() { |
|
30
|
|
|
var attribute = cmsData.regex.getAttr(this.fixture.articleSingle, 'key') |
|
31
|
|
|
chai.assert.equal(attribute, 'title'); |
|
32
|
|
|
}); |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* cmsData.regex.escapeTextToRegex |
|
36
|
|
|
*/ |
|
37
|
|
|
it('cmsData.regex.escapeTextToRegex()', function() { |
|
38
|
|
|
var attribute = cmsData.regex.escapeTextToRegex(this.fixture.articleSingle, 'g') |
|
39
|
|
|
chai.expect(typeof attribute).to.contain('object'); |
|
40
|
|
|
}); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* cmsData.regex.isSingleAbe |
|
44
|
|
|
*/ |
|
45
|
|
|
it('cmsData.regex.isSingleAbe()', function() { |
|
46
|
|
|
var bool = cmsData.regex.isSingleAbe(this.fixture.articleSingle) |
|
47
|
|
|
chai.expect(bool).to.be.true; |
|
|
|
|
|
|
48
|
|
|
bool = cmsData.regex.isSingleAbe(this.fixture.articleEach) |
|
49
|
|
|
chai.expect(bool).to.be.false; |
|
|
|
|
|
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* cmsData.regex.isBlockAbe |
|
54
|
|
|
*/ |
|
55
|
|
|
it('cmsData.regex.isBlockAbe()', function() { |
|
56
|
|
|
var bool = cmsData.regex.isBlockAbe(this.fixture.articleSingle) |
|
57
|
|
|
chai.expect(bool).to.be.false; |
|
|
|
|
|
|
58
|
|
|
bool = cmsData.regex.isBlockAbe(this.fixture.articleEach) |
|
59
|
|
|
chai.expect(bool).to.be.true; |
|
|
|
|
|
|
60
|
|
|
}); |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* cmsData.regex.isEachStatement |
|
64
|
|
|
*/ |
|
65
|
|
|
it('cmsData.regex.isEachStatement()', function() { |
|
66
|
|
|
var bool = cmsData.regex.isEachStatement(this.fixture.articleSingle) |
|
67
|
|
|
chai.expect(bool).to.be.false; |
|
|
|
|
|
|
68
|
|
|
bool = cmsData.regex.isEachStatement(this.fixture.articleEach) |
|
69
|
|
|
chai.expect(bool).to.be.true; |
|
|
|
|
|
|
70
|
|
|
}); |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* cmsData.regex.getTagAbeTypeRequest |
|
74
|
|
|
*/ |
|
75
|
|
|
it('cmsData.regex.getTagAbeTypeRequest()', function() { |
|
76
|
|
|
var arr = cmsData.regex.getTagAbeTypeRequest(this.fixture.articleSingle) |
|
77
|
|
|
chai.expect(arr[0]).to.be.undefined; |
|
|
|
|
|
|
78
|
|
|
var arr = cmsData.regex.getTagAbeTypeRequest(this.fixture.articleRequest) |
|
|
|
|
|
|
79
|
|
|
chai.expect(arr[0]).to.not.be.null; |
|
|
|
|
|
|
80
|
|
|
}); |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* cmsData.regex.validDataAbe |
|
84
|
|
|
*/ |
|
85
|
|
|
it('cmsData.regex.validDataAbe()', function() { |
|
86
|
|
|
// doesn't tested because not sure what it does |
|
87
|
|
|
}); |
|
88
|
|
|
}); |