summaryrefslogtreecommitdiffstats
path: root/test/static/sortByLengthSpec.js
blob: 982ae40988e543c5e7c839ef1ea624c48d99f048 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
describe("Awesomplete.SORT_BYLENGTH", function () {

	subject(function () { return Awesomplete.SORT_BYLENGTH });

	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);
		});
	});
});