Skip to content

Commit

Permalink
Added a test suite with chai and mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
martianboy committed Sep 29, 2016
1 parent 4d48873 commit b655871
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
typings
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A comparator function for comparing two persian strings with correct alphabetic order.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "BABEL_ENV=commonjs mocha --compilers js:babel-core/register --reporter spec test/*.js"
},
"repository": {
"type": "git",
Expand All @@ -19,5 +19,11 @@
"bugs": {
"url": "https://github.com/martianboy/persian-alphabetic-compare/issues"
},
"homepage": "https://github.com/martianboy/persian-alphabetic-compare#readme"
"homepage": "https://github.com/martianboy/persian-alphabetic-compare#readme",
"devDependencies": {
"babel-core": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"chai": "^3.5.0",
"mocha": "^3.1.0"
}
}
57 changes: 57 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import chai from 'chai';
import compare from '..';

describe('persianStringCompare', () => {
function expect_letter_compare(letters) {
return chai.expect(compare.apply(null, letters.split('|')));
}

it("must place Persian letter Peh after Beh and before Teh", () => {
expect_letter_compare('ب|پ').to.be.lessThan(0);
expect_letter_compare('پ|ت').to.be.lessThan(0);
});
it("must place Persian letter Cheh after Jim and before Heh", () => {
expect_letter_compare('ج|چ').to.be.lessThan(0);
expect_letter_compare('چ|ح').to.be.lessThan(0);
});
it("must place Persian letter Jeh after Zeh and before Sin", () => {
expect_letter_compare('ز|ژ').to.be.lessThan(0);
expect_letter_compare('ژ|س').to.be.lessThan(0);
});
it("must place Persian letter Kaf at the same place as Arabic Keh", () => {
expect_letter_compare('ك|ک').to.be.eq(0);
});
it("must place Persian letter Gaf after Kaf", () => {
expect_letter_compare('ک|گ').to.be.lessThan(0);
expect_letter_compare('گ|ل').to.be.lessThan(0);
});
it("must place Arabic letter Teh marbuta after Persian Heh.", () => {
expect_letter_compare('ه|ة').to.be.lessThan(0);
expect_letter_compare('ة|و').to.be.lessThan(0);
});
it("must place Persian letter Heh with Yeh above at the same place as Arabic Teh marbuta", () => {
expect_letter_compare('ۀ|ة').to.be.eq(0);
});
it("must place Arabic letter Waw with Hamza above after Persian Heh.", () => {
expect_letter_compare('و|ؤ').to.be.lessThan(0);
expect_letter_compare('ؤ|ی').to.be.lessThan(0);
});
it("must place Persian letter Yeh at the same place as Arabic Yeh with two dots below", () => {
expect_letter_compare('ي|ی').to.be.eq(0);
});
it('must place Arabic letter Yeh with Hamza above after Persian Yeh', () => {
expect_letter_compare('ی|ئ').to.be.lessThan(0);
});

it('must handle words with same first letters', () => {
chai.expect(compare('کردکوی', 'کرمانشاه')).to.be.lessThan(0);
});

it('must ignore Arabic diacritics', () => {
chai.expect(compare('امّا', 'اما')).to.be.eq(0);
});

it('must ignore Arabic diacritics at the end of the strings', () => {
chai.expect(compare('مثلاٌ', 'مثلا')).to.be.eq(0);
});
});
18 changes: 18 additions & 0 deletions tsd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"chai/chai.d.ts": {
"commit": "f470e7569e7046c62866f57bc4fea56ba79975d5"
},
"assertion-error/assertion-error.d.ts": {
"commit": "f470e7569e7046c62866f57bc4fea56ba79975d5"
},
"mocha/mocha.d.ts": {
"commit": "f470e7569e7046c62866f57bc4fea56ba79975d5"
}
}
}

0 comments on commit b655871

Please sign in to comment.