Added uniqueness check

This commit is contained in:
Unmesh Gundecha
2021-02-21 21:08:36 +08:00
parent 0caed6e38e
commit 6e0a747058
2 changed files with 29 additions and 11 deletions

View File

@@ -38,4 +38,29 @@ describe('Checklist', function () {
expect(orgList).to.be.sorted(Intl.Collator().compare);
});
});
});
describe('Uniqueness', function() {
it('has unique items', function () {
var items = srcMd.match(/(?<=\* )(.*?)(?=\))/g);
var hasDuplicate = items.some((val, i) => items.indexOf(val) !== i);
expect(hasDuplicate).to.equal(false, 'List has duplicate items');
});
it('has unique link text', function () {
var items = srcMd.match(/(?<=\* \[)(.*?)(?=\])/g);
var hasDuplicate = items.some((val, i) => items.indexOf(val) !== i);
expect(hasDuplicate).to.equal(false, 'List has duplicate text');
});
it('has unique urls', function () {
var items = srcMd.match(/(?<=\* \[*.*\]\()(.*?)(?=\))/g);
var items = arrayRemove(items, 'https://github.com/abhivaikar/howtheytest');
var hasDuplicate = items.some((val, i) => items.indexOf(val) !== i);
expect(hasDuplicate).to.equal(false, 'List has duplicate link');
});
})
});
function arrayRemove(arr, value) {
return arr.filter(function(ele){
return ele != value;
});
}