Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: node_js
node_js:
- '0.10'
- '0.11'
- 'iojs'
# - 'iojs' This isn't working on travis at the moment

before_install:
- npm i npm@latest -g
Expand Down
20 changes: 19 additions & 1 deletion src/annotation/annotations/access.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
export default function access() {
export default function access(env) {

const defaultPrivatePrefixTest = RegExp.prototype.test.bind(/^[_-]/);

return {
name: 'access',

parse(text) {
return text.trim();
},

autofill(item) {
if (env.privatePrefix === false) { return; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing linebreaks here.


let testFunc = defaultPrivatePrefixTest;

if (typeof env.privatePrefix !== 'undefined') {
testFunc = RegExp.prototype.test.bind(new RegExp(env.privatePrefix));
}

if (testFunc(item.context.name)) {
return 'private';
}

},

default() {
return 'public';
},
Expand Down
24 changes: 23 additions & 1 deletion test/annotations/access.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,33 @@
var assert = require('assert');

describe('#access', function () {
var access = (new (require('../../dist/annotation'))()).list.access;
var accessCtor = require('../../dist/annotation/annotations/access');
var access = accessCtor({});

it('should return the trimmed string', function () {
assert.equal(access.parse(' '), '');
assert.equal(access.parse(' '), '');
assert.equal(access.parse('\ntest\t'), 'test');
assert.equal(access.parse('\nte\nst\t'), 'te\nst');
});

it('should autofill based on default', function () {
assert.equal(access.autofill({ context: { name: 'non-private'}, access: 'public'}), undefined);
assert.equal(access.autofill({ context: { name: '_private-name'}, access: 'public'}), 'private');
assert.equal(access.autofill({ context: { name: '-private-name'}, access: 'public'}), 'private');
});

it('should ignore autofill if privatePrefix is false', function () {
var accessEnv = accessCtor({ privatePrefix: false });
assert.equal(accessEnv.autofill({ context: { name: 'non-private'}, access: 'public'}), undefined);
assert.equal(accessEnv.autofill({ context: { name: '_private-name'}, access: 'public'}), undefined);
assert.equal(accessEnv.autofill({ context: { name: '-private-name'}, access: 'public'}), undefined);
});

it('should autofill based on privatePrefix', function () {
var accessEnv = accessCtor({ privatePrefix: '^--' });
assert.equal(accessEnv.autofill({ context: { name: '-non-private'}, access: 'public'}), undefined);
assert.equal(accessEnv.autofill({ context: { name: '_non-private'}, access: 'public'}), undefined);
assert.equal(accessEnv.autofill({ context: { name: '--private-name'}, access: 'public'}), 'private');
});
});