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; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
48 | bool = cmsData.regex.isSingleAbe(this.fixture.articleEach) |
||
49 | chai.expect(bool).to.be.false; |
||
0 ignored issues
–
show
|
|||
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; |
||
0 ignored issues
–
show
|
|||
58 | bool = cmsData.regex.isBlockAbe(this.fixture.articleEach) |
||
59 | chai.expect(bool).to.be.true; |
||
0 ignored issues
–
show
|
|||
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; |
||
0 ignored issues
–
show
|
|||
68 | bool = cmsData.regex.isEachStatement(this.fixture.articleEach) |
||
69 | chai.expect(bool).to.be.true; |
||
0 ignored issues
–
show
|
|||
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; |
||
0 ignored issues
–
show
|
|||
78 | var arr = cmsData.regex.getTagAbeTypeRequest(this.fixture.articleRequest) |
||
0 ignored issues
–
show
Comprehensibility
Naming
Best Practice
introduced
by
The variable
arr already seems to be declared on line 76 . Consider using another variable name or omitting the var keyword.
This check looks for variables that are declared in multiple lines. There may be several reasons for this. In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs. If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared. ![]() |
|||
79 | chai.expect(arr[0]).to.not.be.null; |
||
0 ignored issues
–
show
|
|||
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 | }); |