Skip to content

Commit db9ab2b

Browse files
common下测试代码升级ES6
1 parent 73ccd81 commit db9ab2b

File tree

84 files changed

+2054
-2002
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2054
-2002
lines changed

test/common/commontypes/BaseTypesSpec.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
1-
require('../../../src/common/commontypes/BaseTypes');
1+
import {StringExt, NumberExt, ArrayExt} from '../../../src/common/commontypes/BaseTypes';
22

3-
describe('BaseTypes', function () {
4-
it('startsWith, contains', function () {
3+
describe('BaseTypes', () => {
4+
it('startsWith, contains', () => {
55
var str = "BaseTypesTest";
6-
var isStartWith = SuperMap.String.startsWith(str, 'Base');
7-
var isContains = SuperMap.String.contains(str, 'contain');
6+
var isStartWith = StringExt.startsWith(str, 'Base');
7+
var isContains = StringExt.contains(str, 'contain');
88
expect(isStartWith).toBeTruthy();
99
expect(isContains).toBeFalsy();
1010
});
1111

12-
it('trim', function () {
12+
it('trim', () => {
1313
var str = "this is a BaseTypesTest ";
14-
var newStr = SuperMap.String.trim(str);
14+
var newStr = StringExt.trim(str);
1515
expect(newStr).toEqual("this is a BaseTypesTest");
1616
});
1717

18-
it('camelize', function () {
19-
var str = SuperMap.String.camelize('chicken-head');
18+
it('camelize', () => {
19+
var str = StringExt.camelize('chicken-head');
2020
expect(str).toEqual('chickenHead');
2121
});
2222

23-
it('format_String', function () {
23+
it('format_String', () => {
2424
var template1 = "${a,b}";
25-
var result1 = SuperMap.String.format(template1, null, null);
25+
var result1 = StringExt.format(template1, null, null);
2626
expect(result1).toEqual("${a,b}");
2727
var template = "${a.b}";
2828
var context = {a: {b: "format"}};
2929
var args = null;
30-
var result = SuperMap.String.format(template, context, args);
30+
var result = StringExt.format(template, context, args);
3131
expect(result).toEqual("format");
3232
});
3333

34-
it('isNumeric, numericIf', function () {
35-
var result1 = SuperMap.String.isNumeric("6.02e23");
36-
var result2 = SuperMap.String.isNumeric(" 4 ");
37-
var result3 = SuperMap.String.numericIf("4");
34+
it('isNumeric, numericIf', () => {
35+
var result1 = StringExt.isNumeric("6.02e23");
36+
var result2 = StringExt.isNumeric(" 4 ");
37+
var result3 = StringExt.numericIf("4");
3838
expect(result1).toBeTruthy();
3939
expect(result2).toBeFalsy();
4040
expect(result3).toEqual(4);
4141
});
4242

4343
//数值操作的一系列常用扩展函数
44-
it('limitSigDigs', function () {
45-
var number = SuperMap.Number.limitSigDigs(123.123456789, 6);
44+
it('limitSigDigs', () => {
45+
var number = NumberExt.limitSigDigs(123.123456789, 6);
4646
expect(number).toEqual(123.123);
4747
});
4848

4949
//数字格式化输出.
50-
it('format_Number', function () {
51-
var number1 = SuperMap.Number.format(123456789, null, ',', '.');
52-
var number2 = SuperMap.Number.format(123.123456789, 0, ',', '.');
53-
var number3 = SuperMap.Number.format(123.123456789, 5, ',', '.');
50+
it('format_Number', () => {
51+
var number1 = NumberExt.format(123456789, null, ',', '.');
52+
var number2 = NumberExt.format(123.123456789, 0, ',', '.');
53+
var number3 = NumberExt.format(123.123456789, 5, ',', '.');
5454
expect(number1).toEqual("123,456,789");
5555
expect(number2).toEqual("123");
5656
expect(number3).toEqual("123.12346");
5757
});
5858

59-
it('Number.limitSigDigs', function () {
59+
it('Number.limitSigDigs', () => {
6060
var number = 123.123456789;
6161
var newNm = number.limitSigDigs(8);
6262
expect(newNm).toEqual(123.12346);
6363
});
6464

6565
//数组操作的一系列常用扩展函数
6666
//过滤数组
67-
it('filter', function () {
67+
it('filter', () => {
6868
var array = [10, 9, 53, 7, 25, 45];
69-
var newArray = SuperMap.Array.filter(array, function (val, i, array) {
69+
var newArray = ArrayExt.filter(array, (val, i, array) => {
7070
if (val > 20) {
7171
return true;
7272
}

test/common/commontypes/BoundsSpec.js

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
require('../../../src/common/commontypes/Bounds');
2-
require('../../../src/common/commontypes/LonLat');
1+
import {Bounds} from '../../../src/common/commontypes/Bounds';
2+
import {Pixel} from '../../../src/common/commontypes/Pixel';
3+
import {LonLat} from '../../../src/common/commontypes/LonLat';
4+
import {Size} from '../../../src/common/commontypes/Size';
5+
import {Point} from '../../../src/common/commontypes/geometry/Point';
36

4-
describe('Bounds', function () {
5-
it('constructor, clone, equals, toString, toArray', function () {
6-
var bounds = new SuperMap.Bounds([-180, -90, 180, 90]);
7+
describe('Bounds', () => {
8+
it('constructor, clone, equals, toString, toArray', () => {
9+
var bounds = new Bounds([-180, -90, 180, 90]);
710
var bounds1 = bounds.clone();
811
expect(bounds).not.toBeNull();
912
expect(bounds.CLASS_NAME).toEqual("SuperMap.Bounds");
@@ -32,8 +35,8 @@ describe('Bounds', function () {
3235
});
3336

3437
//取小数点后decimal位数字进行四舍五入再转换为BBOX字符串
35-
it('toBBOX', function () {
36-
var bounds = new SuperMap.Bounds(-1.1234567, -1.7654321, 1.4444444, 1.5555555);
38+
it('toBBOX', () => {
39+
var bounds = new Bounds(-1.1234567, -1.7654321, 1.4444444, 1.5555555);
3740
var str1 = bounds.toBBOX();
3841
expect(str1).toEqual("-1.123457,-1.765432,1.444444,1.555556");
3942
var str2 = bounds.toBBOX(1);
@@ -43,8 +46,8 @@ describe('Bounds', function () {
4346
bounds.destroy();
4447
});
4548

46-
it('getSize, getCenterPixel', function () {
47-
var bounds = new SuperMap.Bounds(-180, -90, 100, 80);
49+
it('getSize, getCenterPixel', () => {
50+
var bounds = new Bounds(-180, -90, 100, 80);
4851
var size = bounds.getSize();
4952
var pixel = bounds.getCenterPixel();
5053
expect(size.w).toEqual(280);
@@ -54,15 +57,15 @@ describe('Bounds', function () {
5457
bounds.destroy();
5558
});
5659

57-
it('scale', function () {
58-
var bounds = new SuperMap.Bounds(-50, -50, 40, 40);
60+
it('scale', () => {
61+
var bounds = new Bounds(-50, -50, 40, 40);
5962
var bounds1 = bounds.scale(2);
6063
expect(bounds1).not.toBeNull();
6164
expect(bounds1.bottom).toEqual(-95);
6265
expect(bounds1.left).toEqual(-95);
6366
expect(bounds1.right).toEqual(85);
6467
expect(bounds1.top).toEqual(85);
65-
var origin = new SuperMap.Pixel(40, 50);
68+
var origin = new Pixel(40, 50);
6669
var bounds2 = bounds.scale(2, origin);
6770
expect(bounds2).not.toBeNull();
6871
expect(bounds2.bottom).toEqual(-150);
@@ -72,8 +75,8 @@ describe('Bounds', function () {
7275
bounds.destroy();
7376
});
7477

75-
it('add', function () {
76-
var bounds = new SuperMap.Bounds(-50, -50, 40, 40);
78+
it('add', () => {
79+
var bounds = new Bounds(-50, -50, 40, 40);
7780
var newBounds = bounds.add(20, 10);
7881
expect(newBounds).not.toBeNull();
7982
expect(newBounds.bottom).toEqual(-40);
@@ -84,14 +87,14 @@ describe('Bounds', function () {
8487
});
8588

8689
//在当前bounds上扩展bounds
87-
it('extend', function () {
88-
var bounds = new SuperMap.Bounds(-50, -50, 40, 40);
90+
it('extend', () => {
91+
var bounds = new Bounds(-50, -50, 40, 40);
8992
spyOn(bounds, 'extend').and.callThrough();
90-
bounds.extend(new SuperMap.LonLat(50, 60));
93+
bounds.extend(new LonLat(50, 60));
9194
expect(bounds).not.toBeNull();
92-
bounds.extend(new SuperMap.Geometry.Point(50, 60));
95+
bounds.extend(new Point(50, 60));
9396
expect(bounds).not.toBeNull();
94-
bounds.extend(new SuperMap.Bounds(50, 60));
97+
bounds.extend(new Bounds(50, 60));
9598
expect(bounds).not.toBeNull();
9699
expect(bounds.bottom).toEqual(-50);
97100
expect(bounds.left).toEqual(-50);
@@ -101,30 +104,30 @@ describe('Bounds', function () {
101104
});
102105

103106
//判断传入的坐标是否在范围内
104-
it('containsLonLat', function () {
105-
var bounds = new SuperMap.Bounds(-50, -50, 40, 40);
106-
var isContains1 = bounds.containsLonLat(new SuperMap.LonLat(40, 40), true);
107+
it('containsLonLat', () => {
108+
var bounds = new Bounds(-50, -50, 40, 40);
109+
var isContains1 = bounds.containsLonLat(new LonLat(40, 40), true);
107110
expect(isContains1).toBeTruthy();
108111
var isContains2 = bounds.containsLonLat(
109-
new SuperMap.LonLat(400, 40),
112+
new LonLat(400, 40),
110113
{
111114
inclusive: true,
112-
worldBounds: new SuperMap.Bounds(-180, -90, 180, 90)
115+
worldBounds: new Bounds(-180, -90, 180, 90)
113116
}
114117
);
115118
expect(isContains2).toBeTruthy();
116119
bounds.destroy();
117120
});
118121

119-
it('containsPixel', function () {
120-
var bounds = new SuperMap.Bounds(-50, -50, 40, 40);
121-
var isContains = bounds.containsPixel(new SuperMap.Pixel(40, 40), true);
122+
it('containsPixel', () => {
123+
var bounds = new Bounds(-50, -50, 40, 40);
124+
var isContains = bounds.containsPixel(new Pixel(40, 40), true);
122125
expect(isContains).toBeTruthy();
123126
bounds.destroy();
124127
});
125128

126-
it('contains', function () {
127-
var bounds = new SuperMap.Bounds(-50, -50, 40, 40);
129+
it('contains', () => {
130+
var bounds = new Bounds(-50, -50, 40, 40);
128131
var isContains1 = bounds.contains(40, 40);
129132
var isContains2 = bounds.contains();
130133
var isContains3 = bounds.contains(40, 40, false);
@@ -135,38 +138,38 @@ describe('Bounds', function () {
135138
});
136139

137140
//判断目标边界范围是否与当前边界范围相交
138-
it('intersectsBounds', function () {
139-
var bounds = new SuperMap.Bounds(-180, -90, 100, 80);
141+
it('intersectsBounds', () => {
142+
var bounds = new Bounds(-180, -90, 100, 80);
140143
var options1 = {
141144
inclusive: false,
142-
worldBounds: new SuperMap.Bounds(-170, -90, 120, 80)
145+
worldBounds: new Bounds(-170, -90, 120, 80)
143146
};
144147
var options2 = {
145148
inclusive: false,
146-
worldBounds: new SuperMap.Bounds(-180, -90, 100, 80)
149+
worldBounds: new Bounds(-180, -90, 100, 80)
147150
};
148151
var isIntersects1 = bounds.intersectsBounds(
149-
new SuperMap.Bounds(100, -90, 120, 80),
152+
new Bounds(100, -90, 120, 80),
150153
options1
151154
);
152155
var isIntersects2 = bounds.intersectsBounds(
153-
new SuperMap.Bounds(100, -90, 100, 80),
156+
new Bounds(100, -90, 100, 80),
154157
options2
155158
);
156159
expect(isIntersects1).toBeTruthy();
157160
expect(isIntersects2).toBeFalsy();
158161
bounds.destroy();
159162
});
160163

161-
it('determineQuadrant', function () {
162-
var bounds = new SuperMap.Bounds(-180, -90, 100, 80);
163-
var str = bounds.determineQuadrant(new SuperMap.LonLat(20, 20));
164+
it('determineQuadrant', () => {
165+
var bounds = new Bounds(-180, -90, 100, 80);
166+
var str = bounds.determineQuadrant(new LonLat(20, 20));
164167
expect(str).toEqual("tr");
165168
bounds.destroy();
166169
});
167170

168-
it('toServerJSONObject', function () {
169-
var bounds = new SuperMap.Bounds(-180, -90, 100, 80);
171+
it('toServerJSONObject', () => {
172+
var bounds = new Bounds(-180, -90, 100, 80);
170173
var obj = bounds.toServerJSONObject();
171174
expect(obj).not.toBeNull();
172175
expect(obj.bottom).toEqual(-90);
@@ -178,26 +181,26 @@ describe('Bounds', function () {
178181
bounds.destroy();
179182
});
180183

181-
it('fromString', function () {
182-
var bounds = SuperMap.Bounds.fromString("-180,-90,100,80", false);
184+
it('fromString', () => {
185+
var bounds = Bounds.fromString("-180,-90,100,80", false);
183186
expect(bounds).not.toBeNull();
184187
expect(bounds.bottom).toEqual(-90);
185188
expect(bounds.left).toEqual(-180);
186189
expect(bounds.right).toEqual(100);
187190
expect(bounds.top).toEqual(80);
188191
});
189192

190-
it('fromSize', function () {
191-
var bounds = SuperMap.Bounds.fromSize(new SuperMap.Size(20, 10));
193+
it('fromSize', () => {
194+
var bounds = Bounds.fromSize(new Size(20, 10));
192195
expect(bounds).not.toBeNull();
193196
expect(bounds.bottom).toEqual(10);
194197
expect(bounds.left).toEqual(0);
195198
expect(bounds.right).toEqual(20);
196199
expect(bounds.top).toEqual(0);
197200
});
198201

199-
it('oppositeQuadrant', function () {
200-
var oppositeQuadrant = SuperMap.Bounds.oppositeQuadrant("tl");
202+
it('oppositeQuadrant', () => {
203+
var oppositeQuadrant = Bounds.oppositeQuadrant("tl");
201204
expect(oppositeQuadrant).toEqual("br");
202205
});
203206
});

test/common/commontypes/DateSpec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
require('../../../src/common/commontypes/Date');
1+
import {DateExt} from '../../../src/common/commontypes/Date';
22

3-
describe('Date', function () {
4-
it('toISOString', function () {
5-
var dateString = SuperMap.Date.toISOString(new Date());
3+
describe('Date', () => {
4+
it('toISOString', () => {
5+
var dateString = DateExt.toISOString(new Date());
66
expect(dateString).not.toBeNaN();
77
});
88

9-
it('parse', function () {
10-
var date1 = SuperMap.Date.parse("2010-08-07T11:58:23.123-06");
11-
var date2 = SuperMap.Date.parse("sca123");
12-
var date1String = SuperMap.Date.toISOString(date1);
9+
it('parse', () => {
10+
var date1 = DateExt.parse("2010-08-07T11:58:23.123-06");
11+
var date2 = DateExt.parse("sca123");
12+
var date1String = DateExt.toISOString(date1);
1313
expect(date1String).toEqual("2010-08-07T17:58:23.123Z");
1414
expect(date2).not.toBeNull();
1515
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy