/
Matchers.scala
8427 lines (7991 loc) · 369 KB
/
Matchers.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2001-2013 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalatest.matchers.must
import org.scalatest.FailureMessages
import org.scalatest.Resources
import org.scalatest.Assertion
import org.scalatest.Assertions
import org.scalatest.Suite
import org.scalatest.UnquotedString
import org.scalatest.CompileMacro
import org.scalactic._
import org.scalatest.enablers._
import org.scalatest.matchers._
import org.scalatest.matchers.dsl._
import org.scalatest.verbs.CompileWord
import org.scalatest.verbs.TypeCheckWord
import org.scalatest.verbs.MustVerb
import org.scalatest.matchers.dsl.ResultOfNoElementsOfApplication
import org.scalatest.matchers.dsl.ResultOfOneElementOfApplication
import scala.collection.GenTraversable
import scala.reflect.{classTag, ClassTag}
import scala.util.matching.Regex
import DefaultEquality.areEqualComparingArraysStructurally
import org.scalatest.matchers.MatchersHelper
import MatchersHelper.transformOperatorChars
import TripleEqualsSupport.Spread
import TripleEqualsSupport.TripleEqualsInvocation
import TripleEqualsSupport.TripleEqualsInvocationOnSpread
import ArrayHelper.deep
// SKIP-SCALATESTJS,NATIVE-START
import MatchersHelper.accessProperty
import MatchersHelper.matchSymbolToPredicateMethod
// SKIP-SCALATESTJS,NATIVE-END
import scala.language.experimental.macros
import scala.language.higherKinds
import MatchersHelper.endWithRegexWithGroups
import MatchersHelper.fullyMatchRegexWithGroups
import MatchersHelper.includeRegexWithGroups
import MatchersHelper.indicateFailure
import MatchersHelper.indicateSuccess
import MatchersHelper.newTestFailedException
import MatchersHelper.startWithRegexWithGroups
import org.scalatest.exceptions._
// TODO: drop generic support for be as an equality comparison, in favor of specific ones.
// TODO: Put links from ShouldMatchers to wherever I reveal the matrix and algo of how properties are checked dynamically.
// TODO: double check that I wrote tests for (length (7)) and (size (8)) in parens
// TODO: document how to turn off the === implicit conversion
// TODO: Document you can use JMock, EasyMock, etc.
/**
* Trait that provides a domain specific language (DSL) for expressing assertions in tests
* using the word <code>must</code>.
*
* <p>
* For example, if you mix <code>Matchers</code> into
* a suite class, you can write an equality assertion in that suite like this:
* </p>
*
* <pre class="stHighlighted">
* result must equal (<span class="stLiteral">3</span>)
* </pre>
*
* <p>
* Here <code>result</code> is a variable, and can be of any type. If the object is an
* <code>Int</code> with the value 3, execution will continue (<em>i.e.</em>, the expression will result
* in the unit value, <code>()</code>). Otherwise, a <a href="../../exceptions/TestFailedException.html"><code>TestFailedException</code></a>
* will be thrown with a detail message that explains the problem, such as <code>"7 did not equal 3"</code>.
* This <code>TestFailedException</code> will cause the test to fail.
* </p>
*
* <p>
* Here is a table of contents for this documentation:
* </p>
*
* <ul>
* <li><a href="#matchersMigration">Matchers migration in ScalaTest 2.0</a></li>
* <li><a href="#checkingEqualityWithMatchers">Checking equality with matchers</a></li>
* <li><a href="#checkingSizeAndLength">Checking size and length</a></li>
* <li><a href="#checkingStrings">Checking strings</a></li>
* <li><a href="#greaterAndLessThan">Greater and less than</a></li>
* <li><a href="#checkingBooleanPropertiesWithBe">Checking <code>Boolean</code> properties with <code>be</code></a></li>
* <li><a href="#usingCustomBeMatchers">Using custom <code>BeMatchers</code></a></li>
* <li><a href="#checkingObjectIdentity">Checking object identity</a></li>
* <li><a href="#checkingAnObjectsClass">Checking an object's class</a></li>
* <li><a href="#checkingNumbersAgainstARange">Checking numbers against a range</a></li>
* <li><a href="#checkingForEmptiness">Checking for emptiness</a></li>
* <li><a href="#workingWithContainers">Working with "containers"</a></li>
* <li><a href="#workingWithAggregations">Working with "aggregations"</a></li>
* <li><a href="#workingWithSequences">Working with "sequences"</a></li>
* <li><a href="#workingWithSortables">Working with "sortables"</a></li>
* <li><a href="#workingWithIterators">Working with iterators</a></li>
* <li><a href="#inspectorShorthands">Inspector shorthands</a></li>
* <li><a href="#singleElementCollections">Single-element collections</a></li>
* <li><a href="#javaCollectionsAndMaps">Java collections and maps</a></li>
* <li><a href="#stringsAndArraysAsCollections"><code>String</code>s and <code>Array</code>s as collections</a></li>
* <li><a href="#beAsAnEqualityComparison">Be as an equality comparison</a></li>
* <li><a href="#beingNegative">Being negative</a></li>
* <li><a href="#checkingThatCodeDoesNotCompile">Checking that a snippet of code does not compile</a></li>
* <li><a href="#logicalExpressions">Logical expressions with <code>and</code> and <code>or</code></a></li>
* <li><a href="#workingWithOptions">Working with <code>Option</code>s</a></li>
* <li><a href="#checkingArbitraryProperties">Checking arbitrary properties with <code>have</code></a></li>
* <li><a href="#lengthSizeHavePropertyMatchers">Using <code>length</code> and <code>size</code> with <code>HavePropertyMatcher</code>s</a></li>
* <li><a href="#matchingAPattern">Checking that an expression matches a pattern</a></li>
* <li><a href="#usingCustomMatchers">Using custom matchers</a></li>
* <li><a href="#checkingForExpectedExceptions">Checking for expected exceptions</a></li>
* <li><a href="#thosePeskyParens">Those pesky parens</a></li>
* </ul>
*
* <p>
* Trait <code>must.Matchers</code> is an alternative to <a href="../should/Matchers.html"><code>should.Matchers</code></a> that provides the exact same
* meaning, syntax, and behavior as <code>should.Matchers</code>, but uses the verb <code>must</code> instead of <code>should</code>.
* The two traits differ only in the English semantics of the verb: <code>should</code>
* is informal, making the code feel like conversation between the writer and the reader; <code>must</code> is more formal, making the code feel more like
* a written specification.
* </p>
*
* <a name="checkingEqualityWithMatchers"></a>
* <h2>Checking equality with matchers</h2>
*
* <p>
* ScalaTest matchers provides five different ways to check equality, each designed to address a different need. They are:
* </p>
*
* <pre class="stHighlighted">
* result must equal (<span class="stLiteral">3</span>) <span class="stLineComment">// can customize equality</span>
* result must === (<span class="stLiteral">3</span>) <span class="stLineComment">// can customize equality and enforce type constraints</span>
* result must be (<span class="stLiteral">3</span>) <span class="stLineComment">// cannot customize equality, so fastest to compile</span>
* result mustEqual <span class="stLiteral">3</span> <span class="stLineComment">// can customize equality, no parentheses required</span>
* result mustBe <span class="stLiteral">3</span> <span class="stLineComment">// cannot customize equality, so fastest to compile, no parentheses required</span>
* </pre>
*
* <p>
* The “<code>left</code> <code>must</code> <code>equal</code> <code>(right)</code>” syntax requires an
* <code>org.scalactic.Equality[L]</code> to be provided (either implicitly or explicitly), where
* <code>L</code> is the left-hand type on which <code>must</code> is invoked. In the "<code>left</code> <code>must</code> <code>equal</code> <code>(right)</code>" case,
* for example, <code>L</code> is the type of <code>left</code>. Thus if <code>left</code> is type <code>Int</code>, the "<code>left</code> <code>must</code>
* <code>equal</code> <code>(right)</code>"
* statement would require an <code>Equality[Int]</code>.
* </p>
*
* <p>
* By default, an implicit <code>Equality[T]</code> instance is available for any type <code>T</code>, in which equality is implemented
* by simply invoking <code>==</code> on the <code>left</code>
* value, passing in the <code>right</code> value, with special treatment for arrays. If either <code>left</code> or <code>right</code> is an array, <code>deep</code>
* will be invoked on it before comparing with <em>==</em>. Thus, the following expression
* will yield false, because <code>Array</code>'s <code>equals</code> method compares object identity:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>) == <span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>) <span class="stLineComment">// yields false</span>
* </pre>
*
* <p>
* The next expression will by default <em>not</em> result in a <code>TestFailedException</code>, because default <code>Equality[Array[Int]]</code> compares
* the two arrays structurally, taking into consideration the equality of the array's contents:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>) must equal (<span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>)) <span class="stLineComment">// succeeds (i.e., does not throw TestFailedException)</span>
* </pre>
*
* <p>
* If you ever do want to verify that two arrays are actually the same object (have the same identity), you can use the
* <code>be theSameInstanceAs</code> syntax, <a href="#checkingObjectIdentity">described below</a>.
* </p>
*
* <p>
* You can customize the meaning of equality for a type when using "<code>must</code> <code>equal</code>," "<code>must</code> <code>===</code>,"
* or <code>mustEqual</code> syntax by defining implicit <code>Equality</code> instances that will be used instead of default <code>Equality</code>.
* You might do this to normalize types before comparing them with <code>==</code>, for instance, or to avoid calling the <code>==</code> method entirely,
* such as if you want to compare <code>Double</code>s with a tolerance.
* For an example, see the main documentation of trait <code>org.scalactic.Equality</code>.
* </p>
*
* <p>
* You can always supply implicit parameters explicitly, but in the case of implicit parameters of type <code>Equality[T]</code>, Scalactic provides a
* simple "explictly" DSL. For example, here's how you could explicitly supply an <code>Equality[String]</code> instance that normalizes both left and right
* sides (which must be strings), by transforming them to lowercase:
* </p>
*
* <pre class="stREPL">
* scala> import org.scalatest.matchers.must.Matchers._
* import org.scalatest.matchers.must.Matchers._
*
* scala> import org.scalactic.Explicitly._
* import org.scalactic.Explicitly._
*
* scala> import org.scalactic.StringNormalizations._
* import org.scalactic.StringNormalizations._
*
* scala> "Hi" must equal ("hi") (after being lowerCased)
* </pre>
*
* <p>
* The <code>after</code> <code>being</code> <code>lowerCased</code> expression results in an <code>Equality[String]</code>, which is then passed
* explicitly as the second curried parameter to <code>equal</code>. For more information on the explictly DSL, see the main documentation
* for trait <code>org.scalactic.Explicitly</code>.
* </p>
*
* <p>
* The "<code>must</code> <code>be</code>" and <code>mustBe</code> syntax do not take an <code>Equality[T]</code> and can therefore not be customized.
* They always use the default approach to equality described above. As a result, "<code>must</code> <code>be</code>" and <code>mustBe</code> will
* likely be the fastest-compiling matcher syntax for equality comparisons, since the compiler need not search for
* an implicit <code>Equality[T]</code> each time.
* </p>
*
* <p>
* The <code>must</code> <code>===</code> syntax (and its complement, <code>must</code> <code>!==</code>) can be used to enforce type
* constraints at compile-time between the left and right sides of the equality comparison. Here's an example:
* </p>
*
* <pre class="stREPL">
* scala> import org.scalatest.matchers.must.Matchers._
* import org.scalatest.matchers.must.Matchers._
*
* scala> import org.scalactic.TypeCheckedTripleEquals._
* import org.scalactic.TypeCheckedTripleEquals._
*
* scala> Some(2) must === (2)
* <console>:17: error: types Some[Int] and Int do not adhere to the equality constraint
* selected for the === and !== operators; the missing implicit parameter is of
* type org.scalactic.CanEqual[Some[Int],Int]
* Some(2) must === (2)
* ^
* </pre>
*
* <p>
* By default, the "<code>Some(2)</code> <code>must</code> <code>===</code> <code>(2)</code>" statement would fail at runtime. By mixing in
* the equality constraints provided by <code>TypeCheckedTripleEquals</code>, however, the statement fails to compile. For more information
* and examples, see the main documentation for trait <code>org.scalactic.TypeCheckedTripleEquals</code>.
* </p>
*
* <a name="checkingSizeAndLength"></a>
* <h2>Checking size and length</h2>
*
* <p>
* You can check the size or length of any type of object for which it
* makes sense. Here's how checking for length looks:
* </p>
* <pre class="stHighlighted">
* result must have length <span class="stLiteral">3</span>
* </pre>
*
* <p>
* Size is similar:
* </p>
*
* <pre class="stHighlighted">
* result must have size <span class="stLiteral">10</span>
* </pre>
*
* <p>
* The <code>length</code> syntax can be used with <code>String</code>, <code>Array</code>, any <code>scala.collection.GenSeq</code>,
* any <code>java.util.List</code>, and any type <code>T</code> for which an implicit <code>Length[T]</code> type class is
* available in scope.
* Similarly, the <code>size</code> syntax can be used with <code>Array</code>, any <code>scala.collection.GenTraversable</code>,
* any <code>java.util.Collection</code>, any <code>java.util.Map</code>, and any type <code>T</code> for which an implicit <code>Size[T]</code> type class is
* available in scope. You can enable the <code>length</code> or <code>size</code> syntax for your own arbitrary types, therefore,
* by defining <a href="../../enablers/Length.html"><code>Length</code></a> or <a href="../../enablers/Size.html"><code>Size</code></a> type
* classes for those types.
* </p>
*
* <p>
* In addition, the <code>length</code> syntax can be used with any object that has a field or method named <code>length</code>
* or a method named <code>getLength</code>. Similarly, the <code>size</code> syntax can be used with any
* object that has a field or method named <code>size</code> or a method named <code>getSize</code>.
* The type of a <code>length</code> or <code>size</code> field, or return type of a method, must be either <code>Int</code>
* or <code>Long</code>. Any such method must take no parameters. (The Scala compiler will ensure at compile time that
* the object on which <code>must</code> is being invoked has the appropriate structure.)
* </p>
*
* <a name="checkingStrings"></a>
* <h2>Checking strings</h2>
*
* <p>
* You can check for whether a string starts with, ends with, or includes a substring like this:
* </p>
*
* <pre class="stHighlighted">
* string must startWith (<span class="stQuotedString">"Hello"</span>)
* string must endWith (<span class="stQuotedString">"world"</span>)
* string must include (<span class="stQuotedString">"seven"</span>)
* </pre>
*
* <p>
* You can check for whether a string starts with, ends with, or includes a regular expression, like this:
* </p>
*
* <pre class="stHighlighted">
* string must startWith regex <span class="stQuotedString">"Hel*o"</span>
* string must endWith regex <span class="stQuotedString">"wo.ld"</span>
* string must include regex <span class="stQuotedString">"wo.ld"</span>
* </pre>
*
* <p>
* And you can check whether a string fully matches a regular expression, like this:
* </p>
*
* <pre class="stHighlighted">
* string must fullyMatch regex <span class="stQuotedString">"""(-)?(\d+)(\.\d*)?"""</span>
* </pre>
*
* <p>
* The regular expression passed following the <code>regex</code> token can be either a <code>String</code>
* or a <code>scala.util.matching.Regex</code>.
* </p>
*
* <p>
* With the <code>startWith</code>, <code>endWith</code>, <code>include</code>, and <code>fullyMatch</code>
* tokens can also be used with an optional specification of required groups, like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stQuotedString">"abbccxxx"</span> must startWith regex (<span class="stQuotedString">"a(b*)(c*)"</span> withGroups (<span class="stQuotedString">"bb"</span>, <span class="stQuotedString">"cc"</span>))
* <span class="stQuotedString">"xxxabbcc"</span> must endWith regex (<span class="stQuotedString">"a(b*)(c*)"</span> withGroups (<span class="stQuotedString">"bb"</span>, <span class="stQuotedString">"cc"</span>))
* <span class="stQuotedString">"xxxabbccxxx"</span> must include regex (<span class="stQuotedString">"a(b*)(c*)"</span> withGroups (<span class="stQuotedString">"bb"</span>, <span class="stQuotedString">"cc"</span>))
* <span class="stQuotedString">"abbcc"</span> must fullyMatch regex (<span class="stQuotedString">"a(b*)(c*)"</span> withGroups (<span class="stQuotedString">"bb"</span>, <span class="stQuotedString">"cc"</span>))
* </pre>
*
* <p>
* You can check whether a string is empty with <code>empty</code>:
* </p>
*
* <pre class="stHighlighted">
* s mustBe empty
* </pre>
*
* <p>
* You can also use most of ScalaTest's matcher syntax for collections on <code>String</code> by
* treating the <code>String</code>s as collections of characters. For examples, see the
* <a href="#stringsAndArraysAsCollections"><code>String</code>s and <code>Array</code>s as collections</a> section below.
* </p>
*
* <a name="greaterAndLessThan"></a>
* <h2>Greater and less than</h2>
*
* <p>
* You can check whether any type for which an implicit <code>Ordering[T]</code> is available
* is greater than, less than, greater than or equal, or less
* than or equal to a value of type <code>T</code>. The syntax is:
* </p>
* <pre class="stHighlighted">
* one must be < <span class="stLiteral">7</span>
* one must be > <span class="stLiteral">0</span>
* one must be <= <span class="stLiteral">7</span>
* one must be >= <span class="stLiteral">0</span>
* </pre>
*
* <a name="checkingBooleanPropertiesWithBe"></a>
* <h2>Checking <code>Boolean</code> properties with <code>be</code></h2>
*
* <p>
* If an object has a method that takes no parameters and returns boolean, you can check
* it by placing a <code>Symbol</code> (after <code>be</code>) that specifies the name
* of the method (excluding an optional prefix of "<code>is</code>"). A symbol literal
* in Scala begins with a tick mark and ends at the first non-identifier character. Thus,
* <code>'traversableAgain</code> results in a <code>Symbol</code> object at runtime, as does
* <code>'completed</code> and <code>'file</code>. Here's an example:
* </p>
*
* <pre class="stHighlighted">
* iter mustBe <span class="stQuotedString">'traversableAgain</span>
* </pre>
*
* Given this code, ScalaTest will use reflection to look on the object referenced from
* <code>emptySet</code> for a method that takes no parameters and results in <code>Boolean</code>,
* with either the name <code>empty</code> or <code>isEmpty</code>. If found, it will invoke
* that method. If the method returns <code>true</code>, execution will continue. But if it returns
* <code>false</code>, a <code>TestFailedException</code> will be thrown that will contain a detail message, such as:
*
* <pre class="stHighlighted">
* non-empty iterator was not traversableAgain
* </pre>
*
* <p>
* This <code>be</code> syntax can be used with any reference (<code>AnyRef</code>) type. If the object does
* not have an appropriately named predicate method, you'll get a <code>TestFailedException</code>
* at runtime with a detailed message that explains the problem.
* (For the details on how a field or method is selected during this
* process, see the documentation for <a href="matchers.dsl/BeWord.html"><code>BeWord</code></a>.)
* </p>
*
* <p>
* If you think it reads better, you can optionally put <code>a</code> or <code>an</code> after
* <code>be</code>. For example, <code>java.io.File</code> has two predicate methods,
* <code>isFile</code> and <code>isDirectory</code>. Thus with a <code>File</code> object
* named <code>temp</code>, you could write:
* </p>
*
* <pre class="stHighlighted">
* temp must be a <span class="stQuotedString">'file</span>
* </pre>
*
* <p>
* Or, given <code>java.awt.event.KeyEvent</code> has a method <code>isActionKey</code> that takes
* no arguments and returns <code>Boolean</code>, you could assert that a <code>KeyEvent</code> is
* an action key with:
*</p>
*
* <pre class="stHighlighted">
* keyEvent must be an <span class="stQuotedString">'actionKey</span>
* </pre>
*
* <p>
* If you prefer to check <code>Boolean</code> properties in a type-safe manner, you can use a <code>BePropertyMatcher</code>.
* This would allow you to write expressions such as:
* </p>
*
* <pre class="stHighlighted">
* xs mustBe traversableAgain
* temp must be a file
* keyEvent must be an actionKey
* </pre>
*
* <p>
* These expressions would fail to compile if <code>must</code> is used on an inappropriate type, as determined
* by the type parameter of the <code>BePropertyMatcher</code> being used. (For example, <code>file</code> in this example
* would likely be of type <code>BePropertyMatcher[java.io.File]</code>. If used with an appropriate type, such an expression will compile
* and at run time the <code>Boolean</code> property method or field will be accessed directly; <em>i.e.</em>, no reflection will be used.
* See the documentation for <a href="matchers/BePropertyMatcher.html"><code>BePropertyMatcher</code></a> for more information.
* </p>
*
* <a name="usingCustomBeMatchers"></a>
* <h2>Using custom <code>BeMatchers</code></h2>
*
* If you want to create a new way of using <code>be</code>, which doesn't map to an actual property on the
* type you care about, you can create a <code>BeMatcher</code>. You could use this, for example, to create <code>BeMatcher[Int]</code>
* called <code>odd</code>, which would match any odd <code>Int</code>, and <code>even</code>, which would match
* any even <code>Int</code>.
* Given this pair of <code>BeMatcher</code>s, you could check whether an <code>Int</code> was odd or even with expressions like:
* </p>
*
* <pre class="stHighlighted">
* num mustBe odd
* num must not be even
* </pre>
*
* For more information, see the documentation for <a href="matchers/BeMatcher.html"><code>BeMatcher</code></a>.
*
* <a name="checkingObjectIdentity"></a>
* <h2>Checking object identity</h2>
*
* <p>
* If you need to check that two references refer to the exact same object, you can write:
* </p>
*
* <pre class="stHighlighted">
* ref1 must be theSameInstanceAs ref2
* </pre>
*
* <a name="checkingAnObjectsClass"></a>
* <h2>Checking an object's class</h2>
*
* <p>
* If you need to check that an object is an instance of a particular class or trait, you can supply the type to
* “<code>be</code> <code>a</code>” or “<code>be</code> <code>an</code>”:
* </p>
*
* <pre class="stHighlighted">
* result1 mustBe a [<span class="stType">Tiger</span>]
* result1 must not be an [<span class="stType">Orangutan</span>]
* </pre>
*
* <p>
* Because type parameters are erased on the JVM, we recommend you insert an underscore for any type parameters
* when using this syntax. Both of the following test only that the result is an instance of <code>List[_]</code>, because at
* runtime the type parameter has been erased:
* </p>
*
* <pre class="stHighlighted">
* result mustBe a [<span class="stType">List[_]</span>] <span class="stLineComment">// recommended</span>
* result mustBe a [<span class="stType">List[Fruit]</span>] <span class="stLineComment">// discouraged</span>
* </pre>
*
* <a name="checkingNumbersAgainstARange"></a>
* <h2>Checking numbers against a range</h2>
*
* <p>
* Often you may want to check whether a number is within a
* range. You can do that using the <code>+-</code> operator, like this:
* </p>
*
* <pre class="stHighlighted">
* sevenDotOh must equal (<span class="stLiteral">6.9</span> +- <span class="stLiteral">0.2</span>)
* sevenDotOh must === (<span class="stLiteral">6.9</span> +- <span class="stLiteral">0.2</span>)
* sevenDotOh must be (<span class="stLiteral">6.9</span> +- <span class="stLiteral">0.2</span>)
* sevenDotOh mustEqual <span class="stLiteral">6.9</span> +- <span class="stLiteral">0.2</span>
* sevenDotOh mustBe <span class="stLiteral">6.9</span> +- <span class="stLiteral">0.2</span>
* </pre>
*
* <p>
* Any of these expressions will cause a <code>TestFailedException</code> to be thrown if the floating point
* value, <code>sevenDotOh</code> is outside the range <code>6.7</code> to <code>7.1</code>.
* You can use <code>+-</code> with any type <code>T</code> for which an implicit <code>Numeric[T]</code> exists, such as integral types:
* </p>
*
* <pre class="stHighlighted">
* seven must equal (<span class="stLiteral">6</span> +- <span class="stLiteral">2</span>)
* seven must === (<span class="stLiteral">6</span> +- <span class="stLiteral">2</span>)
* seven must be (<span class="stLiteral">6</span> +- <span class="stLiteral">2</span>)
* seven mustEqual <span class="stLiteral">6</span> +- <span class="stLiteral">2</span>
* seven mustBe <span class="stLiteral">6</span> +- <span class="stLiteral">2</span>
* </pre>
*
* <a name="checkingForEmptiness"></a>
* <h2>Checking for emptiness</h2>
*
* <p>
* You can check whether an object is "empty", like this:
* </p>
*
* <pre class="stHighlighted">
* traversable mustBe empty
* javaMap must not be empty
* </pre>
*
* <p>
* The <code>empty</code> token can be used with any type <code>L</code> for which an implicit <code>Emptiness[L]</code> exists.
* The <code>Emptiness</code> companion object provides implicits for <code>GenTraversable[E]</code>, <code>java.util.Collection[E]</code>,
* <code>java.util.Map[K, V]</code>, <code>String</code>, <code>Array[E]</code>, and <code>Option[E]</code>. In addition, the
* <code>Emptiness</code> companion object provides structural implicits for types that declare an <code>isEmpty</code> method that
* returns a <code>Boolean</code>. Here are some examples:
* </p>
*
* <pre class="stREPL">
* scala> import org.scalatest.matchers.must.Matchers._
* import org.scalatest.matchers.must.Matchers._
*
* scala> List.empty mustBe empty
*
* scala> None mustBe empty
*
* scala> Some(1) must not be empty
*
* scala> "" mustBe empty
*
* scala> new java.util.HashMap[Int, Int] mustBe empty
*
* scala> new { def isEmpty = true} mustBe empty
*
* scala> Array(1, 2, 3) must not be empty
* </pre>
*
* <a name="workingWithContainers"></a>
* <h2>Working with "containers"</h2>
*
* <p>
* You can check whether a collection contains a particular element like this:
* </p>
*
* <pre class="stHighlighted">
* traversable must contain (<span class="stQuotedString">"five"</span>)
* </pre>
*
* <p>
* The <code>contain</code> syntax shown above can be used with any type <code>C</code> that has a "containing" nature, evidenced by
* an implicit <code>org.scalatest.enablers.Containing[L]</code>, where <code>L</code> is left-hand type on
* which <code>must</code> is invoked. In the <code>Containing</code>
* companion object, implicits are provided for types <code>GenTraversable[E]</code>, <code>java.util.Collection[E]</code>,
* <code>java.util.Map[K, V]</code>, <code>String</code>, <code>Array[E]</code>, and <code>Option[E]</code>.
* Here are some examples:
* </p>
*
* <pre class="stREPL">
* scala> import org.scalatest.matchers.must.Matchers._
* import org.scalatest.matchers.must.Matchers._
*
* scala> List(1, 2, 3) must contain (2)
*
* scala> Map('a' -> 1, 'b' -> 2, 'c' -> 3) must contain ('b' -> 2)
*
* scala> Set(1, 2, 3) must contain (2)
*
* scala> Array(1, 2, 3) must contain (2)
*
* scala> "123" must contain ('2')
*
* scala> Some(2) must contain (2)
* </pre>
*
* <p>
* ScalaTest's implicit methods that provide the <code>Containing[L]</code> type classes require an <code>Equality[E]</code>, where
* <code>E</code> is an element type. For example, to obtain a <code>Containing[Array[Int]]</code> you must supply an <code>Equality[Int]</code>,
* either implicitly or explicitly. The <code>contain</code> syntax uses this <code>Equality[E]</code> to determine containership.
* Thus if you want to change how containership is determined for an element type <code>E</code>, place an implicit <code>Equality[E]</code>
* in scope or use the explicitly DSL. Although the implicit parameter required for the <code>contain</code> syntax is of type <code>Containing[L]</code>,
* implicit conversions are provided in the <code>Containing</code> companion object from <code>Equality[E]</code> to the various
* types of containers of <code>E</code>. Here's an example:
* </p>
*
* <pre class="stREPL">
* scala> import org.scalatest.matchers.must.Matchers._
* import org.scalatest.matchers.must.Matchers._
*
* scala> List("Hi", "Di", "Ho") must contain ("ho")
* org.scalatest.exceptions.TestFailedException: List(Hi, Di, Ho) did not contain element "ho"
* at ...
*
* scala> import org.scalactic.Explicitly._
* import org.scalactic.Explicitly._
*
* scala> import org.scalactic.StringNormalizations._
* import org.scalactic.StringNormalizations._
*
* scala> (List("Hi", "Di", "Ho") must contain ("ho")) (after being lowerCased)
* </pre>
*
* <p>
* Note that when you use the explicitly DSL with <code>contain</code> you need to wrap the entire
* <code>contain</code> expression in parentheses, as shown here.
* </p>
*
* <pre>
* (List("Hi", "Di", "Ho") must contain ("ho")) (after being lowerCased)
* ^ ^
* </pre>
*
* <p>
* In addition to determining whether an object contains another object, you can use <code>contain</code> to
* make other determinations.
* For example, the <code>contain</code> <code>oneOf</code> syntax ensures that one and only one of the specified elements are
* contained in the containing object:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>) must contain oneOf (<span class="stLiteral">5</span>, <span class="stLiteral">7</span>, <span class="stLiteral">9</span>)
* <span class="stType">Some</span>(<span class="stLiteral">7</span>) must contain oneOf (<span class="stLiteral">5</span>, <span class="stLiteral">7</span>, <span class="stLiteral">9</span>)
* <span class="stQuotedString">"howdy"</span> must contain oneOf (<span class="stQuotedString">'a'</span>, <span class="stQuotedString">'b'</span>, <span class="stQuotedString">'c'</span>, <span class="stQuotedString">'d'</span>)
* </pre>
*
* <p>
* Note that if multiple specified elements appear in the containing object, <code>oneOf</code> will fail:
* </p>
*
* <pre class="stREPL">
* scala> List(1, 2, 3) must contain oneOf (2, 3, 4)
* org.scalatest.exceptions.TestFailedException: List(1, 2, 3) did not contain one (and only one) of (2, 3, 4)
* at ...
* </pre>
*
* <p>
* If you really want to ensure one or more of the specified elements are contained in the containing object,
* use <code>atLeastOneOf</code>, described below, instead of <code>oneOf</code>. Keep in mind, <code>oneOf</code>
* means "<em>exactly</em> one of."
* </p>
*
* <p>
* Note also that with any <code>contain</code> syntax, you can place custom implicit <code>Equality[E]</code> instances in scope
* to customize how containership is determined, or use the explicitly DSL. Here's an example:
* </p>
*
* <pre class="stHighlighted">
* (<span class="stType">Array</span>(<span class="stQuotedString">"Doe"</span>, <span class="stQuotedString">"Ray"</span>, <span class="stQuotedString">"Me"</span>) must contain oneOf (<span class="stQuotedString">"X"</span>, <span class="stQuotedString">"RAY"</span>, <span class="stQuotedString">"BEAM"</span>)) (after being lowerCased)
* </pre>
*
* <p>
* If you have a collection of elements that you'd like to use in a "one of" comparison, you can use "oneElementOf," like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>) must contain oneElementOf <span class="stType">List</span>(<span class="stLiteral">5</span>, <span class="stLiteral">7</span>, <span class="stLiteral">9</span>)
* <span class="stType">Some</span>(<span class="stLiteral">7</span>) must contain oneElementOf <span class="stType">Vector</span>(<span class="stLiteral">5</span>, <span class="stLiteral">7</span>, <span class="stLiteral">9</span>)
* <span class="stQuotedString">"howdy"</span> must contain oneElementOf <span class="stType">Set</span>(<span class="stQuotedString">'a'</span>, <span class="stQuotedString">'b'</span>, <span class="stQuotedString">'c'</span>, <span class="stQuotedString">'d'</span>)
* (<span class="stType">Array</span>(<span class="stQuotedString">"Doe"</span>, <span class="stQuotedString">"Ray"</span>, <span class="stQuotedString">"Me"</span>) must contain oneElementOf <span class="stType">List</span>(<span class="stQuotedString">"X"</span>, <span class="stQuotedString">"RAY"</span>, <span class="stQuotedString">"BEAM"</span>)) (after being lowerCased)
* </pre>
*
* <p>
* The <code>contain</code> <code>noneOf</code> syntax does the opposite of <code>oneOf</code>: it ensures none of the specified elements
* are contained in the containing object:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>) must contain noneOf (<span class="stLiteral">7</span>, <span class="stLiteral">8</span>, <span class="stLiteral">9</span>)
* <span class="stType">Some</span>(<span class="stLiteral">0</span>) must contain noneOf (<span class="stLiteral">7</span>, <span class="stLiteral">8</span>, <span class="stLiteral">9</span>)
* <span class="stQuotedString">"12345"</span> must contain noneOf (<span class="stQuotedString">'7'</span>, <span class="stQuotedString">'8'</span>, <span class="stQuotedString">'9'</span>)
* </pre>
*
* <p>
* If you have a collection of elements that you'd like to use in a "none of" comparison, you can use "noElementsOf," like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>) must contain noElementsOf <span class="stType">List</span>(<span class="stLiteral">7</span>, <span class="stLiteral">8</span>, <span class="stLiteral">9</span>)
* <span class="stType">Some</span>(<span class="stLiteral">0</span>) must contain noElementsOf <span class="stType">Vector</span>(<span class="stLiteral">7</span>, <span class="stLiteral">8</span>, <span class="stLiteral">9</span>)
* <span class="stQuotedString">"12345"</span> must contain noElementsOf <span class="stType">Set</span>(<span class="stQuotedString">'7'</span>, <span class="stQuotedString">'8'</span>, <span class="stQuotedString">'9'</span>)
* </pre>
*
* <a name="workingWithAggregations"></a>
* <h2>Working with "aggregations"</h2>
*
* <p>
* As mentioned, the "<code>contain</code>," "<code>contain</code> <code>oneOf</code>," and "<code>contain</code> <code>noneOf</code>" syntax requires a
* <code>Containing[L]</code> be provided, where <code>L</code> is the left-hand type. Other <code>contain</code> syntax, which
* will be described in this section, requires an <code>Aggregating[L]</code> be provided, where again <code>L</code> is the left-hand type.
* (An <code>Aggregating[L]</code> instance defines the "aggregating nature" of a type <code>L</code>.)
* The reason, essentially, is that <code>contain</code> syntax that makes sense for <code>Option</code> is enabled by
* <code>Containing[L]</code>, whereas syntax that does <em>not</em> make sense for <code>Option</code> is enabled
* by <code>Aggregating[L]</code>. For example, it doesn't make sense to assert that an <code>Option[Int]</code> contains all of a set of integers, as it
* could only ever contain one of them. But this does make sense for a type such as <code>List[Int]</code> that can aggregate zero to many integers.
* </p>
*
* <p>
* The <code>Aggregating</code> companion object provides implicit instances of <code>Aggregating[L]</code>
* for types <code>GenTraversable[E]</code>, <code>java.util.Collection[E]</code>,
* <code>java.util.Map[K, V]</code>, <code>String</code>, <code>Array[E]</code>. Note that these are the same types as are supported with
* <code>Containing</code>, but with <code>Option[E]</code> missing.
* Here are some examples:
* </p>
*
* <p>
* The <code>contain</code> <code>atLeastOneOf</code> syntax, for example, works for any type <code>L</code> for which an <code>Aggregating[L]</code> exists. It ensures
* that at least one of (<em>i.e.</em>, one or more of) the specified objects are contained in the containing object:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>) must contain atLeastOneOf (<span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>)
* <span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>) must contain atLeastOneOf (<span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>)
* <span class="stQuotedString">"abc"</span> must contain atLeastOneOf (<span class="stQuotedString">'c'</span>, <span class="stQuotedString">'a'</span>, <span class="stQuotedString">'t'</span>)
* </pre>
*
* <p>
* Similar to <code>Containing[L]</code>, the implicit methods that provide the <code>Aggregating[L]</code> instances require an <code>Equality[E]</code>, where
* <code>E</code> is an element type. For example, to obtain a <code>Aggregating[Vector[String]]</code> you must supply an <code>Equality[String]</code>,
* either implicitly or explicitly. The <code>contain</code> syntax uses this <code>Equality[E]</code> to determine containership.
* Thus if you want to change how containership is determined for an element type <code>E</code>, place an implicit <code>Equality[E]</code>
* in scope or use the explicitly DSL. Although the implicit parameter required for the <code>contain</code> syntax is of type <code>Aggregating[L]</code>,
* implicit conversions are provided in the <code>Aggregating</code> companion object from <code>Equality[E]</code> to the various
* types of aggregations of <code>E</code>. Here's an example:
* </p>
*
* <pre class="stHighlighted">
* (<span class="stType">Vector</span>(<span class="stQuotedString">" A"</span>, <span class="stQuotedString">"B "</span>) must contain atLeastOneOf (<span class="stQuotedString">"a "</span>, <span class="stQuotedString">"b"</span>, <span class="stQuotedString">"c"</span>)) (after being lowerCased and trimmed)
* </pre>
*
* <p>
* If you have a collection of elements that you'd like to use in an "at least one of" comparison, you can use "atLeastOneElementOf," like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>) must contain atLeastOneElementOf <span class="stType">List</span>(<span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>)
* <span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>) must contain atLeastOneElementOf <span class="stType">Vector</span>(<span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>)
* <span class="stQuotedString">"abc"</span> must contain atLeastOneElementOf <span class="stType">Set</span>(<span class="stQuotedString">'c'</span>, <span class="stQuotedString">'a'</span>, <span class="stQuotedString">'t'</span>)
* (<span class="stType">Vector</span>(<span class="stQuotedString">" A"</span>, <span class="stQuotedString">"B "</span>) must contain atLeastOneElementOf <span class="stType">List</span>(<span class="stQuotedString">"a "</span>, <span class="stQuotedString">"b"</span>, <span class="stQuotedString">"c"</span>)) (after being lowerCased and trimmed)
* </pre>
*
* <p>
* The "<code>contain</code> <code>atMostOneOf</code>" syntax lets you specify a set of objects at most one of which must be contained in the containing object:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>) must contain atMostOneOf (<span class="stLiteral">5</span>, <span class="stLiteral">6</span>, <span class="stLiteral">7</span>)
* </pre>
*
* <p>
* If you have a collection of elements that you'd like to use in a "at most one of" comparison, you can use "atMostOneElementOf," like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>) must contain atMostOneElementOf <span class="stType">Vector</span>(<span class="stLiteral">5</span>, <span class="stLiteral">6</span>, <span class="stLiteral">7</span>)
* </pre>
*
* <p>
* The "<code>contain</code> <code>allOf</code>" syntax lets you specify a set of objects that must all be contained in the containing object:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>) must contain allOf (<span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">5</span>)
* </pre>
*
* <p>
* If you have a collection of elements that you'd like to use in a "all of" comparison, you can use "allElementsOf," like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">4</span>, <span class="stLiteral">5</span>) must contain allElementsOf <span class="stType">Array</span>(<span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">5</span>)
* </pre>
*
* <p>
* The "<code>contain</code> <code>only</code>" syntax lets you assert that the containing object contains <em>only</em> the specified objects, though it may
* contain more than one of each:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">2</span>, <span class="stLiteral">1</span>) must contain only (<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* </pre>
*
* <p>
* The "<code>contain</code> <code>theSameElementsAs</code>" and "<code>contain</code> <code>theSameElementsInOrderAs</code> syntax differ from the others
* in that the right hand side is a <code>GenTraversable[_]</code> rather than a varargs of <code>Any</code>. (Note: in a future 2.0 milestone release, possibly
* 2.0.M6, these will likely be widened to accept any type <code>R</code> for which an <code>Aggregating[R]</code> exists.)
* </p>
*
* <p>
* The "<code>contain</code> <code>theSameElementsAs</code>" syntax lets you assert that two aggregations contain the same objects:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">3</span>, <span class="stLiteral">3</span>) must contain theSameElementsAs <span class="stType">Vector</span>(<span class="stLiteral">3</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* </pre>
*
* <p>
* The number of times any family of equal objects appears must also be the same in both the left and right aggregations.
* The specified objects may appear multiple times, but must appear in the order they appear in the right-hand list. For example, if
* the last 3 element is left out of the right-hand list in the previous example, the expression would fail because the left side
* has three 3's and the right hand side has only two:
* </p>
*
* <pre class="stREPL">
* List(1, 2, 2, 3, 3, 3) must contain theSameElementsAs Vector(3, 2, 3, 1, 2)
* org.scalatest.exceptions.TestFailedException: List(1, 2, 2, 3, 3, 3) did not contain the same elements as Vector(3, 2, 3, 1, 2)
* at ...
* </pre>
*
* <p>
* Note that no <code>onlyElementsOf</code> matcher is provided, because it would have the same
* behavior as <code>theSameElementsAs</code>. (<em>I.e.</em>, if you were looking for <code>onlyElementsOf</code>, please use <code>theSameElementsAs</code>
* instead.)
* </p>
*
* </p>
* <a name="workingWithSequences"></a>
* <h2>Working with "sequences"</h2>
*
* <p>
* The rest of the <code>contain</code> syntax, which
* will be described in this section, requires a <code>Sequencing[L]</code> be provided, where again <code>L</code> is the left-hand type.
* (A <code>Sequencing[L]</code> instance defines the "sequencing nature" of a type <code>L</code>.)
* The reason, essentially, is that <code>contain</code> syntax that implies an "order" of elements makes sense only for types that place elements in a sequence.
* For example, it doesn't make sense to assert that a <code>Map[String, Int]</code> or <code>Set[Int]</code> contains all of a set of integers in a particular
* order, as these types don't necessarily define an order for their elements. But this does make sense for a type such as <code>Seq[Int]</code> that does define
* an order for its elements.
* </p>
*
* <p>
* The <code>Sequencing</code> companion object provides implicit instances of <code>Sequencing[L]</code>
* for types <code>GenSeq[E]</code>, <code>java.util.List[E]</code>,
* <code>String</code>, and <code>Array[E]</code>.
* Here are some examples:
* </p>
*
* <p>
* Similar to <code>Containing[L]</code>, the implicit methods that provide the <code>Aggregating[L]</code> instances require an <code>Equality[E]</code>, where
* <code>E</code> is an element type. For example, to obtain a <code>Aggregating[Vector[String]]</code> you must supply an <code>Equality[String]</code>,
* either implicitly or explicitly. The <code>contain</code> syntax uses this <code>Equality[E]</code> to determine containership.
* Thus if you want to change how containership is determined for an element type <code>E</code>, place an implicit <code>Equality[E]</code>
* in scope or use the explicitly DSL. Although the implicit parameter required for the <code>contain</code> syntax is of type <code>Aggregating[L]</code>,
* implicit conversions are provided in the <code>Aggregating</code> companion object from <code>Equality[E]</code> to the various
* types of aggregations of <code>E</code>. Here's an example:
* </p>
*
* <p>
* The "<code>contain</code> <code>inOrderOnly</code>" syntax lets you assert that the containing object contains <em>only</em> the specified objects, in order.
* The specified objects may appear multiple times, but must appear in the order they appear in the right-hand list. Here's an example:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>, <span class="stLiteral">3</span>, <span class="stLiteral">3</span>) must contain inOrderOnly (<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* </pre>
*
* <p>
* The "<code>contain</code> <code>inOrder</code>" syntax lets you assert that the containing object contains <em>only</em> the specified objects in order, like
* <code>inOrderOnly</code>, but allows other objects to appear in the left-hand aggregation as well:
* contain more than one of each:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">0</span>, <span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">2</span>, <span class="stLiteral">99</span>, <span class="stLiteral">3</span>, <span class="stLiteral">3</span>, <span class="stLiteral">3</span>, <span class="stLiteral">5</span>) must contain inOrder (<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* </pre>
*
* <p>
* If you have a collection of elements that you'd like to use in a "in order" comparison, you can use "inOrderElementsOf," like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">0</span>, <span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">2</span>, <span class="stLiteral">99</span>, <span class="stLiteral">3</span>, <span class="stLiteral">3</span>, <span class="stLiteral">3</span>, <span class="stLiteral">5</span>) must contain inOrderElementsOf <span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* </pre>
*
* <p>
* Note that "order" in <code>inOrder</code>, <code>inOrderOnly</code>, and <code>theSameElementsInOrderAs</code> (described below)
* in the <code>Aggregation[L]</code> instances built-in to ScalaTest is defined as "iteration order".
* </p>
*
* <p>
* Lastly, the "<code>contain</code> <code>theSameElementsInOrderAs</code>" syntax lets you assert that two aggregations contain
* the same exact elements in the same (iteration) order:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>) must contain theSameElementsInOrderAs <span class="stType">collection.mutable.TreeSet</span>(<span class="stLiteral">3</span>, <span class="stLiteral">2</span>, <span class="stLiteral">1</span>)
* </pre>
*
* <p>
* The previous assertion succeeds because the iteration order of a<code>TreeSet</code> is the natural
* ordering of its elements, which in this case is 1, 2, 3. An iterator obtained from the left-hand <code>List</code> will produce the same elements
* in the same order.
* </p>
*
* <p>
* Note that no <code>inOrderOnlyElementsOf</code> matcher is provided, because it would have the same
* behavior as <code>theSameElementsInOrderAs</code>. (<em>I.e.</em>, if you were looking for <code>inOrderOnlyElementsOf</code>, please use <code>theSameElementsInOrderAs</code>
* instead.)
* </p>
*
* <a name="workingWithSortables"></a>
* <h2>Working with "sortables"</h2>
*
* <p>
* You can also ask whether the elements of "sortable" objects (such as <code>Array</code>s, Java <code>List</code>s, and <code>GenSeq</code>s)
* are in sorted order, like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>) mustBe sorted
* </pre>
*
* <a name="workingWithIterators"></a>
* <h2>Working with iterators</h2>
*
* <p>
* Although it seems desireable to provide similar matcher syntax for Scala and Java iterators to that provided for sequences like
* <code>Seq</code>s, <code>Array</code>, and <code>java.util.List</code>, the
* ephemeral nature of iterators makes this problematic. Some syntax (such as <code>must</code> <code>contain</code>) is relatively straightforward to
* support on iterators, but other syntax (such
* as, for example, <code>Inspector</code> expressions on nested iterators) is not. Rather
* than allowing inconsistencies between sequences and iterators in the API, we chose to not support any such syntax directly on iterators:
*
* <pre class="stHighlighted">
* scala> <span class="stReserved">val</span> it = <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>).iterator
* it: <span class="stType">Iterator[Int]</span> = non-empty iterator
* <br/>scala> it must contain (<span class="stLiteral">2</span>)
* <console>:<span class="stLiteral">15</span>: error: could not find <span class="stReserved">implicit</span> value <span class="stReserved">for</span> parameter typeClass1: <span class="stType">org.scalatest.enablers.Containing[Iterator[Int]]</span>
* it must contain (<span class="stLiteral">2</span>)
* ^
* </pre>
*
* <p>
* Instead, you will need to convert your iterators to a sequence explicitly before using them in matcher expressions:
* </p>
*
* <pre class="stHighlighted">
* scala> it.toStream must contain (<span class="stLiteral">2</span>)
* </pre>
*
* <p>
* We recommend you convert (Scala or Java) iterators to <code>Stream</code>s, as shown in the previous example, so that you can
* continue to reap any potential benefits provided by the laziness of the underlying iterator.
* </p>
*
* <a name="inspectorShorthands"></a>
* <h2>Inspector shorthands</h2>
*
* <p>
* You can use the <a href="../../Inspectors.html"><code>Inspectors</code></a> syntax with matchers as well as assertions. If you have a multi-dimensional collection, such as a
* list of lists, using <code>Inspectors</code> is your best option:
* </p>
*
* <pre class="stHighlighted">
* <span class="stReserved">val</span> yss =
* <span class="stType">List</span>(
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>),
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>),
* <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* )
* <br/>forAll (yss) { ys =>
* forAll (ys) { y => y must be > <span class="stLiteral">0</span> }
* }
* </pre>
*
* <p>
* For assertions on one-dimensional collections, however, matchers provides "inspector shorthands." Instead of writing:
* </p>
*
* <pre class="stHighlighted">
* <span class="stReserved">val</span> xs = <span class="stType">List</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>, <span class="stLiteral">3</span>)
* forAll (xs) { x => x must be < <span class="stLiteral">10</span> }
* </pre>
*
* <p>
* You can write:
* </p>
*
* <pre class="stHighlighted">
* all (xs) must be < <span class="stLiteral">10</span>