Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
another test for custom reference, error handling for unrecognized rule
Browse files Browse the repository at this point in the history
  • Loading branch information
nebulon42 committed Jul 10, 2017
1 parent abd3d94 commit 81c56a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/carto/tree/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ tree.Rule.prototype.validate = function (env) {

if (!env.ref.validSelector(this.name)) {
var mean = getMean(this.name, env.ref);
var mean_message = '';
if (mean[0][1] < 3) {
mean_message = '. Did you mean ' + mean[0][0] + '?';
var mean_message = '.';
if (!_.isNil(mean) && !_.isEmpty(mean)) {
if (mean[0][1] < 3) {
mean_message = '. Did you mean ' + mean[0][0] + '?';
}
}
valid = false;
util.error(env, {
Expand Down
31 changes: 30 additions & 1 deletion test/reference.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var assert = require('assert');
var assert = require('assert'),
_ = require('lodash');

var carto = require('../lib/carto');

Expand Down Expand Up @@ -52,7 +53,35 @@ describe('Reference', function() {
reference: customRef
}),
output = renderer.renderMSS('#test { marker-color: #fff; }');
assert.ok(!_.isNil(output.msg) && output.msg.length > 0);
assert.equal(output.msg[0].message, 'Could not use the given reference, because it does not adhere to the specification. See the documentation for details.');
done();
});

it('should error on no rules', function(done) {
var customRef = {
load: function (wanted) {
return {
version: wanted,
style: {},
layer: {},
symbolizers: {},
colors: {},
datasources: {}
};
},
latest: '1.5.0',
versions: [
'1.0.0',
'1.5.0'
]
};
var renderer = new carto.Renderer({
reference: customRef
}),
output = renderer.renderMSS('#test { marker-width: 1; }');
assert.ok(!_.isNil(output.msg) && output.msg.length > 0);
assert.equal(output.msg[0].message, 'Unrecognized rule: marker-width.');
done();
});
});

0 comments on commit 81c56a7

Please sign in to comment.