@@ -469,7 +469,6 @@ function map(obj, iterator, context) {
469
469
470
470
471
471
/**
472
- * @workInProgress
473
472
* @ngdoc function
474
473
* @name angular.Object.size
475
474
* @function
@@ -481,14 +480,20 @@ function map(obj, iterator, context) {
481
480
* {@link angular.Object} for more info.
482
481
*
483
482
* @param {Object|Array } obj Object or array to inspect.
484
- * @returns {number } The size of `obj` or `0` if `obj` is not an object or array.
483
+ * @returns {number } The size of `obj` or `0` if `obj` is neither an object or an array.
485
484
*
486
485
* @example
487
486
* Number of items in array: {{ [1,2].$size() }}<br/>
488
487
* Number of items in object: {{ {a:1, b:2, c:3}.$size() }}<br/>
488
+ *
489
+ * @scenario
490
+ it('should print correct sizes for an array and an object', function() {
491
+ expect(binding('[1,2].$size()')).toBe('2');
492
+ expect(binding('{a:1, b:2, c:3}.$size()')).toBe('3');
493
+ });
489
494
*/
490
495
function size ( obj ) {
491
- var size = 0 ;
496
+ var size = 0 , key ;
492
497
if ( obj ) {
493
498
if ( isNumber ( obj . length ) ) {
494
499
return obj . length ;
@@ -526,22 +531,21 @@ function isLeafNode (node) {
526
531
}
527
532
528
533
/**
529
- * @workInProgress
530
534
* @ngdoc function
531
535
* @name angular.Object.copy
532
536
* @function
533
537
*
534
538
* @description
535
539
* Creates a deep copy of `source`.
536
540
*
541
+ * If `source` is an object or an array, all of its members will be copied into the `destination`
542
+ * object.
543
+ *
537
544
* If `destination` is not provided and `source` is an object or an array, a copy is created &
538
545
* returned, otherwise the `source` is returned.
539
546
*
540
547
* If `destination` is provided, all of its properties will be deleted.
541
548
*
542
- * If `source` is an object or an array, all of its members will be copied into the `destination`
543
- * object.
544
- *
545
549
* Note: this function is used to augment the Object type in angular expressions. See
546
550
* {@link angular.Object} for more info.
547
551
*
@@ -556,10 +560,22 @@ function isLeafNode (node) {
556
560
<button ng:click="form = master.$copy()">copy</button>
557
561
<hr/>
558
562
559
- Master is <span ng:hide="master.$equals(form)">NOT</span> same as form.
563
+ The master object is <span ng:hide="master.$equals(form)">NOT</span> equal to the form object .
560
564
561
565
<pre>master={{master}}</pre>
562
566
<pre>form={{form}}</pre>
567
+
568
+ * @scenario
569
+ it('should print that initialy the form object is NOT equal to master', function() {
570
+ expect(element('.doc-example input[name=master.salutation]').val()).toBe('Hello');
571
+ expect(element('.doc-example input[name=master.name]').val()).toBe('world');
572
+ expect(element('.doc-example span').css('display')).toBe('inline');
573
+ });
574
+
575
+ it('should make form and master equal when the copy button is clicked', function() {
576
+ element('.doc-example button').click();
577
+ expect(element('.doc-example span').css('display')).toBe('none');
578
+ });
563
579
*/
564
580
function copy ( source , destination ) {
565
581
if ( ! destination ) {
@@ -595,7 +611,6 @@ function copy(source, destination){
595
611
596
612
597
613
/**
598
- * @workInProgress
599
614
* @ngdoc function
600
615
* @name angular.Object.equals
601
616
* @function
@@ -604,13 +619,11 @@ function copy(source, destination){
604
619
* Determines if two objects or value are equivalent.
605
620
*
606
621
* To be equivalent, they must pass `==` comparison or be of the same type and have all their
607
- * properties pass `==` comparison.
622
+ * properties pass `==` comparison. During property comparision properties of `function` type and
623
+ * properties with name starting with `$` are ignored.
608
624
*
609
625
* Supports values types, arrays and objects.
610
626
*
611
- * For objects `function` properties and properties that start with `$` are not considered during
612
- * comparisons.
613
- *
614
627
* Note: this function is used to augment the Object type in angular expressions. See
615
628
* {@link angular.Object} for more info.
616
629
*
@@ -619,15 +632,27 @@ function copy(source, destination){
619
632
* @returns {boolean } True if arguments are equal.
620
633
*
621
634
* @example
622
- Salutation: <input type="text" name="master.salutation" value="Hello" /><br/>
623
- Name: <input type="text" name="master.name" value="world"/><br/>
624
- <button ng:click="form = master.$copy()">copy</button>
635
+ Salutation: <input type="text" name="greeting.salutation" value="Hello" /><br/>
636
+ Name: <input type="text" name="greeting.name" value="world"/><br/>
625
637
<hr/>
626
638
627
- Master is <span ng:hide="master.$equals(form)">NOT</span> same as form.
639
+ The <code>greeting</code> object is
640
+ <span ng:hide="greeting.$equals({salutation:'Hello', name:'world'})">NOT</span> equal to
641
+ <code>{salutation:'Hello', name:'world'}</code>.
628
642
629
- <pre>master={{master}}</pre>
630
- <pre>form={{form}}</pre>
643
+ <pre>greeting={{greeting}}</pre>
644
+
645
+ @scenario
646
+ it('should print that initialy greeting is equal to the hardcoded value object', function() {
647
+ expect(element('.doc-example input[name=greeting.salutation]').val()).toBe('Hello');
648
+ expect(element('.doc-example input[name=greeting.name]').val()).toBe('world');
649
+ expect(element('.doc-example span').css('display')).toBe('none');
650
+ });
651
+
652
+ it('should say that the objects are not equal when the form is modified', function() {
653
+ input('greeting.name').enter('kitty');
654
+ expect(element('.doc-example span').css('display')).toBe('inline');
655
+ });
631
656
*/
632
657
function equals ( o1 , o2 ) {
633
658
if ( o1 == o2 ) return true ;
0 commit comments