OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function() { | 5 (function() { |
6 | 6 |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 QUnit.module('base'); | 9 QUnit.module('base'); |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 assert.equal(base.deepCopy(null), null); | 47 assert.equal(base.deepCopy(null), null); |
48 assert.deepEqual(base.deepCopy([1, 2]), [1, 2]); | 48 assert.deepEqual(base.deepCopy([1, 2]), [1, 2]); |
49 assert.deepEqual(base.deepCopy({'key': 'value'}), {'key': 'value'}); | 49 assert.deepEqual(base.deepCopy({'key': 'value'}), {'key': 'value'}); |
50 assert.deepEqual(base.deepCopy( | 50 assert.deepEqual(base.deepCopy( |
51 {'key': {'key_nested': 'value_nested'}}), | 51 {'key': {'key_nested': 'value_nested'}}), |
52 {'key': {'key_nested': 'value_nested'}} | 52 {'key': {'key_nested': 'value_nested'}} |
53 ); | 53 ); |
54 assert.deepEqual(base.deepCopy([1, [2, [3]]]), [1, [2, [3]]]); | 54 assert.deepEqual(base.deepCopy([1, [2, [3]]]), [1, [2, [3]]]); |
55 }); | 55 }); |
56 | 56 |
| 57 QUnit.test('copyWithoutNullFields returns a new object', |
| 58 function(assert) { |
| 59 var obj = { |
| 60 a: 'foo', |
| 61 b: 42 |
| 62 }; |
| 63 var copy = base.copyWithoutNullFields(obj); |
| 64 assert.notEqual(obj, copy); |
| 65 assert.deepEqual(obj, copy); |
| 66 }); |
| 67 |
| 68 QUnit.test('copyWithoutNullFields removes null and undefined fields', |
| 69 function(assert) { |
| 70 /** @const */ |
| 71 var obj = { |
| 72 a: 'foo', |
| 73 b: 42, |
| 74 zero: 0, |
| 75 emptyString: '', |
| 76 nullField: null, |
| 77 undefinedField: undefined |
| 78 }; |
| 79 var copy = base.copyWithoutNullFields(obj); |
| 80 assert.equal(copy['a'], obj['a']); |
| 81 assert.equal(copy['b'], obj['b']); |
| 82 assert.equal(copy['zero'], 0); |
| 83 assert.equal(copy['emptyString'], ''); |
| 84 assert.ok(!('nullField' in copy)); |
| 85 assert.ok(!('undefinedField' in copy)); |
| 86 }); |
| 87 |
| 88 QUnit.test('copyWithoutNullFields(null) returns a new empty bject', |
| 89 function(assert) { |
| 90 assert.deepEqual( |
| 91 base.copyWithoutNullFields(null), |
| 92 {}); |
| 93 assert.notEqual( |
| 94 base.copyWithoutNullFields(null), |
| 95 base.copyWithoutNullFields(null)); |
| 96 assert.deepEqual( |
| 97 base.copyWithoutNullFields(undefined), |
| 98 {}); |
| 99 assert.notEqual( |
| 100 base.copyWithoutNullFields(undefined), |
| 101 base.copyWithoutNullFields(undefined)); |
| 102 }); |
| 103 |
57 QUnit.test('modify the original after deepCopy(obj) should not affect the copy', | 104 QUnit.test('modify the original after deepCopy(obj) should not affect the copy', |
58 function(assert) { | 105 function(assert) { |
59 var original = [1, 2, 3, 4]; | 106 var original = [1, 2, 3, 4]; |
60 var copy = base.deepCopy(original); | 107 var copy = base.deepCopy(original); |
61 original[2] = 1000; | 108 original[2] = 1000; |
62 assert.deepEqual(copy, [1, 2, 3, 4]); | 109 assert.deepEqual(copy, [1, 2, 3, 4]); |
63 }); | 110 }); |
64 | 111 |
65 QUnit.test('dispose(obj) should invoke the dispose method on |obj|', | 112 QUnit.test('dispose(obj) should invoke the dispose method on |obj|', |
66 function(assert) { | 113 function(assert) { |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 /* Ѓ */ 0xD0, 0x83, | 359 /* Ѓ */ 0xD0, 0x83, |
313 /* ф */ 0xD1, 0x84]).buffer), | 360 /* ф */ 0xD1, 0x84]).buffer), |
314 "挂Ѓф"); | 361 "挂Ѓф"); |
315 | 362 |
316 // Unicode surrogate pair for U+1F603. | 363 // Unicode surrogate pair for U+1F603. |
317 assert.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer), | 364 assert.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer), |
318 "😃"); | 365 "😃"); |
319 }); | 366 }); |
320 | 367 |
321 })(); | 368 })(); |
OLD | NEW |