Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / core / test / unit / spec / version / Version.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 describe("Ext.Version", function() {
16                 var version = new Ext.Version("1.2.3beta");
17
18                 describe("toString", function() {
19                         it("should cast to string", function() {
20                                 expect(version+"").toBe("1.2.3beta");
21                         });
22                 });
23
24                 describe("getMajor", function() {
25                         it("should return 1", function() {
26                                 expect(version.getMajor()).toBe(1);
27                         });
28                 });
29
30                 describe("getMinor", function() {
31                         it("should return 2", function() {
32                                 expect(version.getMinor()).toBe(2);
33                         });
34                 });
35
36                 describe("getPatch", function() {
37                         it("should return 3", function() {
38                                 expect(version.getPatch()).toBe(3);
39                         });
40                 });
41
42                 describe("getBuild", function() {
43                         it("should return 0", function() {
44                                 expect(version.getBuild()).toBe(0);
45                         });
46                 });
47
48                 describe("getRelease", function() {
49                         it("should return beta", function() {
50                                 expect(version.getRelease()).toBe("beta");
51                         });
52                 });
53
54                 describe("getShortVersion", function() {
55                         it("should return 123", function() {
56                                 expect(version.getShortVersion()).toBe("123");
57                         });
58                 });
59
60                 describe("toArray", function() {
61                         it("should return [1, 2, 3, 0, 'beta']", function() {
62                                 expect(version.toArray()).toEqual([1, 2, 3, 0, 'beta']);
63                         });
64                 });
65
66                 describe("isGreaterThan", function() {
67                         it("should be greater than 1.2.3alpha", function() {
68                                 expect(version.isGreaterThan("1.2.3alpha")).toBeTruthy();
69                         });
70                         it("should not be greater than 1.2.3RC", function() {
71                                 expect(version.isGreaterThan("1.2.3RC")).toBeFalsy();
72                         });
73                 });
74
75                 describe("isLessThan", function() {
76                         it("should not be smaller than 1.2.3alpha", function() {
77                                 expect(version.isLessThan("1.2.3alpha")).toBeFalsy();
78                         });
79                         it("should be smaller than 1.2.3RC", function() {
80                                 expect(version.isLessThan("1.2.3RC")).toBeTruthy();
81                         });
82                 });
83
84                 describe("equals", function() {
85                         it("should equals 1.2.3beta", function() {
86                                 expect(version.equals("1.2.3beta")).toBeTruthy();
87                         });
88                 });
89
90                 describe("match", function() {
91                         it("should match integer 1", function() {
92                                 expect(version.match(1)).toBeTruthy();
93                         });
94                         it("should match float 1.2", function() {
95                                 expect(version.match(1.2)).toBeTruthy();
96                         });
97                         it("should match string 1.2.3", function() {
98                                 expect(version.match("1.2.3")).toBeTruthy();
99                         });
100                         it("should not match string 1.2.3alpha", function() {
101                                 expect(version.match("1.2.3alpha")).toBeFalsy();
102                         });
103                 });
104         });
105
106         describe("Ext.Version Statics", function() {
107
108                 describe("getComponentValue", function() {
109                         it("should return 0", function() {
110                                 expect(Ext.Version.getComponentValue(undefined)).toBe(0);
111                         });
112
113                         it("should return -2", function() {
114                                 expect(Ext.Version.getComponentValue(-2)).toBe(-2);
115                         });
116
117                         it("should return 2", function() {
118                                 expect(Ext.Version.getComponentValue("2")).toBe(2);
119                         });
120
121                         it("should return -5", function() {
122                                 expect(Ext.Version.getComponentValue("alpha")).toBe(-5);
123                         });
124
125                         it("should return unknown", function() {
126                                 expect(Ext.Version.getComponentValue("unknown")).toBe("unknown");
127                         });
128                 });
129
130                 describe("compare", function() {
131                         it("should return 1", function() {
132                                 expect(Ext.Version.compare("1.2.3beta", "1.2.2")).toBe(1);
133                         });
134
135                         it("should return 1", function() {
136                                 expect(Ext.Version.compare("1.2.3beta", 1)).toBe(1);
137                         });
138
139                         it("should return -1", function() {
140                                 expect(Ext.Version.compare("1.2.3beta", 2)).toBe(-1);
141                         });
142
143                         it("should return -1", function() {
144                                 expect(Ext.Version.compare("1.2.3beta", "1.2.4")).toBe(-1);
145                         });
146
147                         it("should return 1", function() {
148                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3dev")).toBe(1);
149                         });
150
151                         it("should return 1", function() {
152                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3alpha")).toBe(1);
153                         });
154
155                         it("should return 1", function() {
156                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3a")).toBe(1);
157                         });
158
159                         it("should return 0", function() {
160                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3b")).toBe(0);
161                         });
162
163                         it("should return 0", function() {
164                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3beta")).toBe(0);
165                         });
166
167                         it("should return 1", function() {
168                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3alpha")).toBe(1);
169                         });
170
171                         it("should return -1", function() {
172                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3RC")).toBe(-1);
173                         });
174
175                         it("should return -1", function() {
176                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3rc")).toBe(-1);
177                         });
178
179                         it("should return -1", function() {
180                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3#")).toBe(-1);
181                         });
182
183                         it("should return -1", function() {
184                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3pl")).toBe(-1);
185                         });
186
187                         it("should return -1", function() {
188                                 expect(Ext.Version.compare("1.2.3beta", "1.2.3p")).toBe(-1);
189                         });
190                 });
191         });
192
193
194         describe("Versioning", function() {
195                 describe("Ext.setVersion", function() {
196                         it("should return an instance of Ext.Version", function() {
197                                 Ext.setVersion("test", "1.0.1");
198
199                                 expect(Ext.getVersion("test") instanceof Ext.Version).toBe(true);
200                         });
201                 });
202
203                 describe("deprecated Ext.version", function() {
204                         it("should be undefined", function() {
205                                 expect(Ext.version).toBe(undefined);
206                         });
207                 });
208 });
209