Chromium Code Reviews| 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 nullField: null, | |
| 75 undefinedField: undefined | |
|
Jamie
2015/04/03 01:45:57
Add zero and '' fields to address my earlier comme
John Williams
2015/04/04 01:40:25
Done.
| |
| 76 }; | |
| 77 var copy = base.copyWithoutNullFields(obj); | |
| 78 assert.equal(copy['a'], obj['a']); | |
| 79 assert.equal(copy['b'], obj['b']); | |
| 80 assert.ok(!('nullField' in copy)); | |
| 81 assert.ok(!('undefinedField' in copy)); | |
| 82 }); | |
| 83 | |
| 84 QUnit.test('copyWithoutNullFields(null) returns a new empty bject', | |
| 85 function(assert) { | |
| 86 assert.deepEqual( | |
| 87 base.copyWithoutNullFields(null), | |
| 88 {}); | |
| 89 assert.notEqual( | |
| 90 base.copyWithoutNullFields(null), | |
| 91 base.copyWithoutNullFields(null)); | |
| 92 assert.deepEqual( | |
| 93 base.copyWithoutNullFields(undefined), | |
| 94 {}); | |
| 95 assert.notEqual( | |
| 96 base.copyWithoutNullFields(undefined), | |
| 97 base.copyWithoutNullFields(undefined)); | |
| 98 }); | |
| 99 | |
| 57 QUnit.test('modify the original after deepCopy(obj) should not affect the copy', | 100 QUnit.test('modify the original after deepCopy(obj) should not affect the copy', |
| 58 function(assert) { | 101 function(assert) { |
| 59 var original = [1, 2, 3, 4]; | 102 var original = [1, 2, 3, 4]; |
| 60 var copy = base.deepCopy(original); | 103 var copy = base.deepCopy(original); |
| 61 original[2] = 1000; | 104 original[2] = 1000; |
| 62 assert.deepEqual(copy, [1, 2, 3, 4]); | 105 assert.deepEqual(copy, [1, 2, 3, 4]); |
| 63 }); | 106 }); |
| 64 | 107 |
| 65 QUnit.test('dispose(obj) should invoke the dispose method on |obj|', | 108 QUnit.test('dispose(obj) should invoke the dispose method on |obj|', |
| 66 function(assert) { | 109 function(assert) { |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 /* Ѓ */ 0xD0, 0x83, | 355 /* Ѓ */ 0xD0, 0x83, |
| 313 /* ф */ 0xD1, 0x84]).buffer), | 356 /* ф */ 0xD1, 0x84]).buffer), |
| 314 "挂Ѓф"); | 357 "挂Ѓф"); |
| 315 | 358 |
| 316 // Unicode surrogate pair for U+1F603. | 359 // Unicode surrogate pair for U+1F603. |
| 317 assert.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer), | 360 assert.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer), |
| 318 "😃"); | 361 "😃"); |
| 319 }); | 362 }); |
| 320 | 363 |
| 321 })(); | 364 })(); |
| OLD | NEW |