summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 11:34:41 +0300
committerVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 15:33:51 +0300
commit2b2e3ed006671d17f6aae168e62eace66bed8481 (patch)
tree05cb46fea245f2079b6666ed687336ae653902af
parentc97c34f3b5ccc6540bb7433904cc9b3419f8623f (diff)
downloadawesomplete-2b2e3ed006671d17f6aae168e62eace66bed8481.zip
awesomplete-2b2e3ed006671d17f6aae168e62eace66bed8481.tar.gz
awesomplete-2b2e3ed006671d17f6aae168e62eace66bed8481.tar.bz2
Awesomplete.SORT_BYLENGTH tests
-rw-r--r--test/static/sortByLengthSpec.js51
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);
+ });
+ });
+});