diff options
author | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-12-28 09:31:07 +0300 |
---|---|---|
committer | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-12-28 09:31:07 +0300 |
commit | 0b38bb595b9a4b8a6353fd4748dfb3c6530b57ac (patch) | |
tree | eaea8096b6ffa7f04fb218f5e9fea7942edfb668 /test/static/sortByLengthSpec.js | |
parent | 730f82a2bbe7aa3ac65f574e3ce1c481fd953f66 (diff) | |
parent | 5dbfd450fb5d5ce0c1b8886baed047f91d926691 (diff) | |
download | awesomplete-0b38bb595b9a4b8a6353fd4748dfb3c6530b57ac.zip awesomplete-0b38bb595b9a4b8a6353fd4748dfb3c6530b57ac.tar.gz awesomplete-0b38bb595b9a4b8a6353fd4748dfb3c6530b57ac.tar.bz2 |
Merge remote-tracking branch 'upstream/gh-pages' into features/code-climate
Diffstat (limited to 'test/static/sortByLengthSpec.js')
-rw-r--r-- | test/static/sortByLengthSpec.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/static/sortByLengthSpec.js b/test/static/sortByLengthSpec.js new file mode 100644 index 0000000..e11d9db --- /dev/null +++ b/test/static/sortByLengthSpec.js @@ -0,0 +1,51 @@ +describe("Awesomplete.SORT_BYLENGTH", function () { + + subject(function () { return Awesomplete.SORT_BYLENGTH }); + + it("is a function", function () { + expect(this.subject).toEqual(jasmine.any(Function)); + }); + + describe("with strings of different length", function () { + it("returns negative number if the first string is shorter", function () { + expect(this.subject("a", "aa")).toBe(-1); + expect(this.subject("a", "bb")).toBe(-1); + expect(this.subject("b", "aa")).toBe(-1); + + expect(this.subject("a", "aaa")).toBe(-2); + expect(this.subject("a", "bbb")).toBe(-2); + expect(this.subject("b", "aaa")).toBe(-2); + }); + + it("returns positive number if the first string is longer", function () { + expect(this.subject("aa", "a")).toBe(1); + expect(this.subject("bb", "a")).toBe(1); + expect(this.subject("aa", "b")).toBe(1); + + expect(this.subject("aaa", "a")).toBe(2); + expect(this.subject("bbb", "a")).toBe(2); + expect(this.subject("aaa", "b")).toBe(2); + }); + }); + + describe("with strings of the same length", function () { + it("returns -1 if the first string < second string", function () { + expect(this.subject("a", "b")).toBe(-1); + expect(this.subject("aa", "bb")).toBe(-1); + expect(this.subject("aaa", "bbb")).toBe(-1); + }); + + it("returns 1 if the first string > second string", function () { + expect(this.subject("b", "a")).toBe(1); + expect(this.subject("bb", "aa")).toBe(1); + expect(this.subject("bbb", "aaa")).toBe(1); + }); + + // FIXME SORT_BYLENGTH should probably return 0 like classic string comparison + it("returns 1 if the first string == second string", function () { + expect(this.subject("a", "a")).toBe(1); + expect(this.subject("aa", "aa")).toBe(1); + expect(this.subject("aaa", "aaa")).toBe(1); + }); + }); +}); |