Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Feb 16, 2017
1 parent a24357a commit ad9b2b7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 32 deletions.
5 changes: 2 additions & 3 deletions lib/bemhtml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ BEMHTML.prototype.render = function render(context,
if (cls)
classValue += ' ' + (typeof cls === 'string' ?
utils.attrEscape(cls).trim() : cls);
} else {
if (cls)
classValue += cls.trim ? utils.attrEscape(cls).trim() : cls;
} else if (cls) {
classValue += cls.trim ? utils.attrEscape(cls).trim() : cls;
}

if (addJSInitClass)
Expand Down
5 changes: 1 addition & 4 deletions lib/bemxjst/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ function BEMXJSTError(msg, func) {
this.name = 'BEMXJSTError';
this.message = msg;

if (Error.captureStackTrace)
Error.captureStackTrace(this, func || this.constructor);
else
this.stack = (new Error()).stack;
Error.captureStackTrace(this, func || this.constructor);
}

BEMXJSTError.prototype = Object.create(Error.prototype);
Expand Down
26 changes: 1 addition & 25 deletions lib/bemxjst/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ var WrapMatch = tree.WrapMatch;
var ExtendMatch = tree.ExtendMatch;
var CustomMatch = tree.CustomMatch;

function MatchProperty(template, pred) {
this.template = template;
this.key = pred.key;
this.value = pred.value;
}

MatchProperty.prototype.exec = function exec(context) {
return context[this.key] === this.value;
};

function MatchNested(template, pred) {
this.template = template;
this.keys = pred.key;
Expand Down Expand Up @@ -89,10 +79,7 @@ function MatchTemplate(mode, template) {
for (var i = 0, j = 0; i < this.predicates.length; i++, j++) {
var pred = template.predicates[i];
if (pred instanceof PropertyMatch) {
if (Array.isArray(pred.key))
this.predicates[j] = new MatchNested(this, pred);
else
this.predicates[j] = new MatchProperty(this, pred);
this.predicates[j] = new MatchNested(this, pred);
} else if (pred instanceof ExtendMatch) {
j--;
postpone.push(new MatchExtend(this));
Expand Down Expand Up @@ -141,17 +128,6 @@ function Match(entity, modeName) {
}
exports.Match = Match;

Match.prototype.clone = function clone(entity) {
var res = new Match(entity, this.modeName);

res.templates = this.templates.slice();
res.mask = this.mask.slice();
res.maskSize = this.maskSize;
res.count = this.count;

return res;
};

Match.prototype.prepend = function prepend(other) {
this.templates = other.templates.concat(this.templates);
this.count += other.count;
Expand Down
6 changes: 6 additions & 0 deletions test/api-generate-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ describe('API generate', function() {

assert.equal(typeof bundle, 'string');
});

it('should work with options', function() {
var bundle = bemxjst.generate('', { xhtml: true });

assert.equal(typeof bundle, 'string');
});
});
44 changes: 44 additions & 0 deletions test/flush-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var assert = require('assert');
var fixtures = require('./fixtures')('bemhtml');
var test = fixtures.test;
var bemtreeFixtures = require('./fixtures')('bemtree');
var bemtreeTest = bemtreeFixtures.test;

describe('Flush', function() {
it('should not flush custom def() bodies', function() {
Expand Down Expand Up @@ -77,4 +79,46 @@ describe('Flush', function() {
}
});
});

it('should use _flush function', function() {
test(function() {
block('b').tag()('span');
block('br').tag()('br');
},
{
block: 'b',
content: { block: 'br' }
},
'',
{
xhtml: true,
flush: true,
after: function after(template) {
assert.deepEqual(template._buf, [
'<span class="b">',
'<br class="br"/>',
'</span>'
]);
}
});
});

it('should use flush function in bemtree', function() {
bemtreeTest(function() {},
[
{ block: 'br' },
{ block: 'br' }
],
'',
{
engine: 'BEMTREE',
flush: true,
after: function after(template) {
assert.deepEqual(template._buf, [
{ block: 'br' },
{ block: 'br' }
]);
}
});
});
});
10 changes: 10 additions & 0 deletions test/templates-syntax-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ describe('Templates syntax', function() {
fixtures.compile(function() {
// No block() subpredicate
elem('e').tag()('b');
elemMod('m', 'v').tag()('b');
});
}, BEMXJSTError);
});

it('should throw error when no block custom subpredicate', function() {
assert.throws(function() {
fixtures.compile(function() {
// No block() subpredicate
match(function() { return 1; }).tag()('b');
});
}, BEMXJSTError);
});
Expand Down

0 comments on commit ad9b2b7

Please sign in to comment.