/
Inspectors.scala
654 lines (617 loc) · 36.9 KB
/
Inspectors.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
/*
* 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
import scala.collection.GenTraversable
import scala.collection.GenSeq
import Suite.indentLines
import enablers.Collecting
import scala.language.higherKinds
import enablers.InspectorAsserting
import org.scalactic._
import org.scalatest.exceptions._
/**
* Provides nestable <em>inspector methods</em> (or just <em>inspectors</em>) that enable assertions to be made about collections.
*
* <p>
* For example, the <code>forAll</code> method enables you to state that something should be true about all elements of a collection, such
* as that all elements should be positive:
* </p>
*
* <pre class="stREPL">
* scala> import org.scalatest._
* import org.scalatest._
*
* scala> import Assertions._
* import Assertions._
*
* scala> import Inspectors._
* import Inspectors._
*
* scala> val xs = List(1, 2, 3, 4, 5)
* xs: List[Int] = List(1, 2, 3, 4, 5)
*
* scala> forAll (xs) { x => assert(x > 0) }
* </pre>
*
* <p>
* Or, with matchers:
* </p>
*
* <pre class="stREPL">
* scala> import Matchers._
* import Matchers._
*
* scala> forAll (xs) { x => x should be > 0 }
* </pre>
*
* <p>
* To make assertions about nested collections, you can nest the inspector method invocations.
* For example, given the following list of lists of <code>Int</code>:
* </p>
*
* <pre class="stREPL">
* scala> val yss =
* | List(
* | List(1, 2, 3),
* | List(1, 2, 3),
* | List(1, 2, 3)
* | )
* yss: List[List[Int]] = List(List(1, 2, 3), List(1, 2, 3), List(1, 2, 3))
* </pre>
*
* <p>
* You can assert that all <code>Int</code> elements in all nested lists are positive by nesting two <code>forAll</code> method invocations, like this:
* </p>
*
* <pre class="stREPL">
* scala> forAll (yss) { ys =>
* | forAll (ys) { y => y should be > 0 }
* | }
* </pre>
*
* <p>
* The full list of inspector methods are:
* </p>
*
* <ul>
* <li><code>forAll</code> - succeeds if the assertion holds true for every element</li>
* <li><code>forAtLeast</code> - succeeds if the assertion holds true for at least the specified number of elements</li>
* <li><code>forAtMost</code> - succeeds if the assertion holds true for at most the specified number of elements</li>
* <li><code>forBetween</code> - succeeds if the assertion holds true for between the specified minimum and maximum number of elements, inclusive</li>
* <li><code>forEvery</code> - same as <code>forAll</code>, but lists all failing elements if it fails (whereas <code>forAll</code> just reports the first failing element)</li>
* <li><code>forExactly</code> - succeeds if the assertion holds true for exactly the specified number of elements</li>
* </ul>
*
* <p>
* The error messages produced by inspector methods are designed to make sense no matter how deeply you nest the method invocations.
* Here's an example of a nested inspection that fails and the resulting error message:
* </p>
*
* <pre class="stREPL">
* scala> forAll (yss) { ys =>
* | forAll (ys) { y => y should be < 2 }
* | }
* org.scalatest.exceptions.TestFailedException: forAll failed, because:
* at index 0, forAll failed, because:
* at index 1, 2 was not less than 2 (<console>:20)
* in List(1, 2, 3) (<console>:20)
* in List(List(1, 2, 3), List(1, 2, 3), List(1, 2, 3))
* at org.scalatest.InspectorsHelper$.forAll(Inspectors.scala:146)
* ...
* </pre>
*
* <p>
* One way the error message is designed to help you understand the error is by using indentation that mimics the indentation of the
* source code (optimistically assuming the source will be nicely indented). The error message above indicates the outer <code>forAll</code> failed
* because its initial <code>List</code> (<em>i.e.</em>, at index 0) failed
* the assertion, which was that all elements of that initial <code>List[Int]</code> at index 0 should be less than 2. This assertion failed because index 1 of
* that inner list contained the value 2, which was indeed “not less than 2.” The error message for the inner list is an indented line inside the error message
* for the outer list. The actual contents of each list are displayed at the end in inspector error messages, also indented appropriately. The actual contents
* are placed at the end so that for very large collections, the contents will not drown out and make it difficult to find the messages that describe
* actual causes of the failure.
* </p>
*
* <p>
* The <code>forAll</code> and <code>forEvery</code> methods are similar in that both succeed only if the assertion holds for all elements of the collection.
* They differ in that <code>forAll</code> will only report the first element encountered that failed the assertion, but <code>forEvery</code> will report <em>all</em>
* elements that fail the assertion. The tradeoff is that while <code>forEvery</code> gives more information, it may take longer to run because it must inspect every element
* of the collection. The <code>forAll</code> method can simply stop inspecting once it encounters the first failing element. Here's an example that
* shows the difference in the <code>forAll</code> and <code>forEvery</code> error messages:
* </p>
*
* <pre class="stREPL">
* scala> forAll (xs) { x => x should be < 3 }
* org.scalatest.exceptions.TestFailedException: forAll failed, because:
* at index 2, 3 was not less than 3 (<console>:18)
* in List(1, 2, 3, 4, 5)
* at org.scalatest.InspectorsHelper$.forAll(Inspectors.scala:146)
* ...
*
* scala> forEvery (xs) { x => x should be < 3 }
* org.scalatest.exceptions.TestFailedException: forEvery failed, because:
* at index 2, 3 was not less than 3 (<console>:18),
* at index 3, 4 was not less than 3 (<console>:18),
* at index 4, 5 was not less than 3 (<console>:18)
* in List(1, 2, 3, 4, 5)
* at org.scalatest.InspectorsHelper$.forEvery(Inspectors.scala:226)
* ...
* </pre>
*
* <p>
* Note that if you're using matchers, you can alternatively use <em>inspector shorthands</em> for writing non-nested
* inspections. Here's an example:
* </p>
*
* <pre>
* scala> all (xs) should be > 3
* org.scalatest.exceptions.TestFailedException: 'all' inspection failed, because:
* at index 0, 1 was not greater than 3
* in List(1, 2, 3, 4, 5)
* at org.scalatest.InspectorsHelper$.forAll(Inspectors.scala:146)
* </pre>
*
* <p>
* You can use <code>Inspectors</code> on any <code>scala.collection.GenTraversable</code>, <code>java.util.Collection</code>,
* <code>java.util.Map</code> (with <a href="Entry.html"><code>Entry</code></a>), <code>Array</code>, or <code>String</code>.
* Here are some examples:
* </p>
*
* <pre class="stREPL">
* scala> import org.scalatest._
* import org.scalatest._
*
* scala> import Inspectors._
* import Inspectors._
*
* scala> import Matchers._
* import Matchers._
*
* scala> forAll (Array(1, 2, 3)) { e => e should be < 5 }
*
* scala> import collection.JavaConverters._
* import collection.JavaConverters._
*
* scala> val js = List(1, 2, 3).asJava
* js: java.util.List[Int] = [1, 2, 3]
*
* scala> forAll (js) { j => j should be < 5 }
*
* scala> val jmap = Map("a" -> 1, "b" -> 2).asJava
* jmap: java.util.Map[String,Int] = {a=1, b=2}
*
* scala> forAtLeast(1, jmap) { e => e shouldBe Entry("b", 2) }
*
* scala> forAtLeast(2, "hello, world!") { c => c shouldBe 'o' }
* </pre>
*/
trait Inspectors {
/**
* Ensure that all elements in a given collection pass the given inspection function, where "pass" means returning normally from the function (<em>i.e.</em>,
* without throwing an exception).
*
* <p>
* The difference between <code>forAll</code> and <code>forEvery</code> is that
* <code>forAll</code> will stop on the first failure, while <code>forEvery</code> will continue to inspect all elements after the
* first failure (and report all failures).
* </p>
*
* @param xs the collection of elements
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam E the type of element in the collection
* @tparam C the type of collection
*
*/
def forAll[E, C[_], ASSERTION](xs: C[E])(fun: E => ASSERTION)(implicit collecting: Collecting[E, C[E]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAll(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure that all elements in a given <code>scala.collection.GenMap</code> pass the given inspection function, where "pass" means returning normally from the function (<em>i.e.</em>,
* without throwing an exception).
*
* <p>
* The difference between <code>forAll</code> and <code>forEvery</code> is that
* <code>forAll</code> will stop on the first failure, while <code>forEvery</code> will continue to inspect all <code>scala.collection.GenMap</code> entries after the
* first failure (and report all failures).
* </p>
*
* @param xs the <code>java.util.Map</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the Map
* @tparam V the type of value in the Map
* @tparam MAP subtype of <code>java.util.Map</code>
*
*/
def forAll[K, V, MAP[k, v] <: scala.collection.GenMap[k, v], ASSERTION](xs: MAP[K, V])(fun: ((K, V)) => ASSERTION)(implicit collecting: Collecting[(K, V), scala.collection.GenTraversable[(K, V)]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAll(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* Ensure that all elements in a given <code>java.util.Map</code> pass the given inspection function, where "pass" means returning normally from the function (<em>i.e.</em>,
* without throwing an exception).
*
* <p>
* The difference between <code>forAll</code> and <code>forEvery</code> is that
* <code>forAll</code> will stop on the first failure, while <code>forEvery</code> will continue to inspect all <code>java.util.Map</code> elements after the
* first failure (and report all failures).
* </p>
*
* @param xs the <code>java.util.Map</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the Java Map
* @tparam V the type of value in the Java Map
* @tparam JMAP subtype of <code>java.util.Map</code>
*
*/
def forAll[K, V, JMAP[k, v] <: java.util.Map[k, v], ASSERTION](xs: JMAP[K, V])(fun: org.scalatest.Entry[K, V] => ASSERTION)(implicit collecting: Collecting[org.scalatest.Entry[K, V], JMAP[K, V]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAll(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* Ensure that all characters in a given <code>String</code> pass the given inspection function, where "pass" means returning normally from the function (<em>i.e.</em>,
* without throwing an exception).
*
* <p>
* The difference between <code>forAll</code> and <code>forEvery</code> is that
* <code>forAll</code> will stop on the first failure, while <code>forEvery</code> will continue to inspect all characters in the <code>String</code> after the
* first failure (and report all failures).
* </p>
*
* @param xs the <code>String</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
*
*/
def forAll[ASSERTION](xs: String)(fun: Char => ASSERTION)(implicit collecting: Collecting[Char, String], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAll(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure that at least <code>min</code> number of elements of a given collection pass the given inspection function.
*
* @param min the minimum number of elements that must pass the inspection function
* @param xs the collection of elements
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam E the type of element in the collection
* @tparam C the type of collection
*
*/
def forAtLeast[E, C[_], ASSERTION](min: Int, xs: C[E])(fun: E => ASSERTION)(implicit collecting: Collecting[E, C[E]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAtLeast(min, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure that at least <code>min</code> number of elements in a given <code>scala.collection.GenMap</code> pass the given inspection function.
*
* @param min the minimum number of elements that must pass the inspection function
* @param xs the <code>scala.collection.GenMap</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>scala.collection.GenMap</code>
* @tparam V the type of value in the <code>scala.collection.GenMap</code>
* @tparam MAP subtype of <code>scala.collection.GenMap</code>
*
*/
def forAtLeast[K, V, MAP[k, v] <: scala.collection.GenMap[k, v], ASSERTION](min: Int, xs: MAP[K, V])(fun: ((K, V)) => ASSERTION)(implicit collecting: Collecting[(K, V), scala.collection.GenTraversable[(K, V)]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAtLeast(min, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* Ensure that at least <code>min</code> number of elements in a given <code>java.util.Map</code> pass the given inspection function.
*
* @param min the minimum number of elements that must pass the inspection function
* @param xs the <code>java.util.Map</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>java.util.Map</code>
* @tparam V the type of value in the <code>java.util.Map</code>
* @tparam JMAP subtype of <code>java.util.Map</code>
*
*/
def forAtLeast[K, V, JMAP[k, v] <: java.util.Map[k, v], ASSERTION](min: Int, xs: JMAP[K, V])(fun: org.scalatest.Entry[K, V] => ASSERTION)(implicit collecting: Collecting[org.scalatest.Entry[K, V],JMAP[K, V]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAtLeast(min, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* Ensure that at least <code>min</code> number of characters in a given <code>String</code> pass the given inspection function.
*
* @param min the minimum number of characters in <code>String</code> that must pass the inspection function
* @param xs the <code>String</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
*
*/
def forAtLeast[ASSERTION](min: Int, xs: String)(fun: Char => ASSERTION)(implicit collecting: Collecting[Char, String], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAtLeast(min, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
private def shouldIncludeIndex[T, R](xs: GenTraversable[T]) = xs.isInstanceOf[GenSeq[T]]
/**
* Ensure that at most <code>max</code> number of elements of a given collection pass the given inspection function.
*
* @param max the maximum number of elements that must pass the inspection function
* @param xs the collection of elements
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam E the type of element in the collection
* @tparam C the type of collection
*/
def forAtMost[E, C[_], ASSERTION](max: Int, xs: C[E])(fun: E => ASSERTION)(implicit collecting: Collecting[E, C[E]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAtMost(max, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure that at most <code>max</code> number of elements in a given <code>scala.collection.GenMap</code> pass the given inspection function.
*
* @param max the maximum number of elements in the <code>scala.collection.GenMap</code> that must pass the inspection function
* @param xs the <code>scala.collection.GenMap</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>scala.collection.GenMap</code>
* @tparam V the type of value in the <code>scala.collection.GenMap</code>
* @tparam MAP subtype of <code>scala.collection.GenMap</code>
*/
def forAtMost[K, V, MAP[k, v] <: scala.collection.GenMap[k, v], ASSERTION](max: Int, xs: MAP[K, V])(fun: ((K, V)) => ASSERTION)(implicit collecting: Collecting[(K, V), scala.collection.GenTraversable[(K, V)]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAtMost(max, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* Ensure that at most <code>max</code> number of elements in a given <code>java.util.Map</code> pass the given inspection function.
*
* @param max the maximum number of elements in the <code>java.util.Map</code> that must pass the inspection function
* @param xs the <code>java.util.Map</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>java.util.Map</code>
* @tparam V the type of value in the <code>java.util.Map</code>
* @tparam JMAP subtype of <code>java.util.Map</code>
*/
def forAtMost[K, V, JMAP[k, v] <: java.util.Map[k, v], ASSERTION](max: Int, xs: JMAP[K, V])(fun: org.scalatest.Entry[K, V] => ASSERTION)(implicit collecting: Collecting[org.scalatest.Entry[K, V], JMAP[K, V]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAtMost(max, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* Ensure that at most <code>max</code> number of characters in a given <code>String</code> pass the given inspection function.
*
* @param max the maximum number of characters in <code>String</code> that must pass the inspection function
* @param xs the <code>String</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
*/
def forAtMost[ASSERTION](max: Int, xs: String)(fun: Char => ASSERTION)(implicit collecting: Collecting[Char, String], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forAtMost(max, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure that exactly <code>succeededCount</code> number of elements of a given collection pass the given inspection function.
*
* @param succeededCount the number of elements that must pass the inspection function
* @param xs the collection of elements
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam E the type of element in the collection
* @tparam C the type of collection
*/
def forExactly[E, C[_], ASSERTION](succeededCount: Int, xs: C[E])(fun: E => ASSERTION)(implicit collecting: Collecting[E, C[E]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forExactly(succeededCount, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure that exactly <code>succeededCount</code> number of elements in a given <code>scala.collection.GenMap</code> pass the given inspection function.
*
* @param succeededCount the number of entries in the <code>scala.collection.GenMap</code> that must pass the inspection function
* @param xs the <code>scala.collection.GenMap</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>scala.collection.GenMap</code>
* @tparam V the type of value in the <code>scala.collection.GenMap</code>
* @tparam MAP subtype of <code>scala.collection.GenMap</code>
*/
def forExactly[K, V, MAP[k, v] <: scala.collection.GenMap[k, v], ASSERTION](succeededCount: Int, xs: MAP[K, V])(fun: ((K, V)) => ASSERTION)(implicit collecting: Collecting[(K, V), scala.collection.GenTraversable[(K, V)]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forExactly(succeededCount, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* Ensure that exactly <code>succeededCount</code> number of elements in a given <code>java.util.Map</code> pass the given inspection function.
*
* @param succeededCount the number of elements in the <code>java.util.Map</code> that must pass the inspection function
* @param xs the <code>java.util.Map</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>java.util.Map</code>
* @tparam V the type of value in the <code>java.util.Map</code>
* @tparam JMAP subtype of <code>java.util.Map</code>
*/
def forExactly[K, V, JMAP[k, v] <: java.util.Map[k, v], ASSERTION](succeededCount: Int, xs: JMAP[K, V])(fun: org.scalatest.Entry[K, V] => ASSERTION)(implicit collecting: Collecting[org.scalatest.Entry[K, V], JMAP[K, V]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forExactly(succeededCount, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* Ensure that exactly <code>succeededCount</code> number of characters in a given <code>String</code> pass the given inspection function.
*
* @param succeededCount the number of characters in the <code>String</code> that must pass the inspection function
* @param xs the <code>String</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
*/
def forExactly[ASSERTION](succeededCount: Int, xs: String)(fun: Char => ASSERTION)(implicit collecting: Collecting[Char, String], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forExactly(succeededCount, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
private[scalatest] def forNo[E, C[_], ASSERTION](xs: C[E])(fun: E => ASSERTION)(implicit collecting: Collecting[E, C[E]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forNo(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
private[scalatest] def forNo[K, V, MAP[k, v] <: scala.collection.GenMap[k, v], ASSERTION](xs: MAP[K, V])(fun: ((K, V)) => ASSERTION)(implicit collecting: Collecting[(K, V), scala.collection.GenTraversable[(K, V)]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forNo(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-START
private[scalatest] def forNo[K, V, JMAP[k, v] <: java.util.Map[k, v], ASSERTION](xs: JMAP[K, V])(fun: org.scalatest.Entry[K, V] => ASSERTION)(implicit collecting: Collecting[org.scalatest.Entry[K, V], JMAP[K, V]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forNo(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-END
private[scalatest] def forNo[ASSERTION](xs: String)(fun: Char => ASSERTION)(implicit collecting: Collecting[Char, String], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forNo(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure the number of elements of a given collection that pass the given inspection function is between <code>from</code> and <code>upTo</code>.
*
* @param from the minimum number of elements that must pass the inspection number
* @param upTo the maximum number of elements that must pass the inspection number
* @param xs the collection of elements
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam E the type of element in the collection
* @tparam C the type of collection
*/
def forBetween[E, C[_], ASSERTION](from: Int, upTo: Int, xs: C[E])(fun: E => ASSERTION)(implicit collecting: Collecting[E, C[E]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forBetween(from, upTo, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure the number of elements in a given <code>scala.collection.GenMap</code> that pass the given inspection function is between <code>from</code> and <code>upTo</code>.
*
* @param from the minimum number of elements in the <code>scala.collection.GenMap</code> that must pass the inspection number
* @param upTo the maximum number of elements in the <code>scala.collection.GenMap</code> that must pass the inspection number
* @param xs the <code>scala.collection.GenMap</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>scala.collection.GenMap</code>
* @tparam V the type of value in the <code>scala.collection.GenMap</code>
* @tparam MAP subtype of <code>scala.collection.GenMap</code>
*/
def forBetween[K, V, MAP[k, v] <: scala.collection.GenMap[k, v], ASSERTION](from: Int, upTo: Int, xs: MAP[K, V])(fun: ((K, V)) => ASSERTION)(implicit collecting: Collecting[(K, V), scala.collection.GenTraversable[(K, V)]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forBetween(from, upTo, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* Ensure the number of elements in a given <code>java.util.Map</code> that pass the given inspection function is between <code>from</code> and <code>upTo</code>.
*
* @param from the minimum number of elements in the <code>java.util.Map</code> that must pass the inspection number
* @param upTo the maximum number of elements in the <code>java.util.Map</code> that must pass the inspection number
* @param xs the <code>java.util.Map</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>java.util.Map</code>
* @tparam V the type of value in the <code>java.util.Map</code>
* @tparam JMAP subtype of <code>java.util.Map</code>
*/
def forBetween[K, V, JMAP[k, v] <: java.util.Map[k, v], ASSERTION](from: Int, upTo: Int, xs: JMAP[K, V])(fun: org.scalatest.Entry[K, V] => ASSERTION)(implicit collecting: Collecting[org.scalatest.Entry[K, V], JMAP[K, V]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forBetween(from, upTo, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* Ensure the number of characters of a given <code>String</code> that pass the given inspection function is between <code>from</code> and <code>upTo</code>.
*
* @param from the minimum number of characters in the <code>String</code> that must pass the inspection number
* @param upTo the maximum number of characters in the <code>String</code> that must pass the inspection number
* @param xs the <code>String</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
*/
def forBetween[ASSERTION](from: Int, upTo: Int, xs: String)(fun: Char => ASSERTION)(implicit collecting: Collecting[Char, String], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forBetween(from, upTo, collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure that every element in a given collection passes the given inspection function, where "pass" means returning normally from the function (<em>i.e.</em>,
* without throwing an exception).
*
* <p>
* The difference between <code>forEvery</code> and <code>forAll</code> is that
* <code>forEvery</code> will continue to inspect all elements after first failure, and report all failures,
* whereas <code>forAll</code> will stop on (and only report) the first failure.
* </p>
*
* @param xs the collection of elements
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam E the type of element in the collection
* @tparam C the type of collection
*/
def forEvery[E, C[_], ASSERTION](xs: C[E])(fun: E => ASSERTION)(implicit collecting: Collecting[E, C[E]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forEvery(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
/**
* Ensure that every element in a given <code>scala.collection.GenMap</code> passes the given inspection function, where "pass" means returning normally
* from the function (<em>i.e.</em>, without throwing an exception).
*
* <p>
* The difference between <code>forEvery</code> and <code>forAll</code> is that
* <code>forEvery</code> will continue to inspect all entries in the <code>scala.collection.GenMap</code> after first failure, and report all failures,
* whereas <code>forAll</code> will stop on (and only report) the first failure.
* </p>
*
* @param xs the <code>scala.collection.GenMap</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>scala.collection.GenMap</code>
* @tparam V the type of value in the <code>scala.collection.GenMap</code>
* @tparam MAP subtype of <code>scala.collection.GenMap</code>
*/
def forEvery[K, V, MAP[k, v] <: scala.collection.GenMap[k, v], ASSERTION](xs: MAP[K, V])(fun: ((K, V)) => ASSERTION)(implicit collecting: Collecting[(K, V), scala.collection.GenTraversable[(K, V)]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forEvery(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* Ensure that every element in a given <code>java.util.Map</code> passes the given inspection function, where "pass" means returning normally
* from the function (<em>i.e.</em>, without throwing an exception).
*
* <p>
* The difference between <code>forEvery</code> and <code>forAll</code> is that
* <code>forEvery</code> will continue to inspect all elements in the <code>java.util.Map</code> after first failure, and report all failures,
* whereas <code>forAll</code> will stop on (and only report) the first failure.
* </p>
*
* @param xs the <code>java.util.Map</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
* @tparam K the type of key in the <code>java.util.Map</code>
* @tparam V the type of value in the <code>java.util.Map</code>
* @tparam JMAP subtype of <code>java.util.Map</code>
*/
def forEvery[K, V, JMAP[k, v] <: java.util.Map[k, v], ASSERTION](xs: JMAP[K, V])(fun: org.scalatest.Entry[K, V] => ASSERTION)(implicit collecting: Collecting[org.scalatest.Entry[K, V], JMAP[K, V]], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forEvery(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* Ensure that every character in a given <code>String</code> passes the given inspection function, where "pass" means returning normally from the function (<em>i.e.</em>,
* without throwing an exception).
*
* <p>
* The difference between <code>forEvery</code> and <code>forAll</code> is that
* <code>forEvery</code> will continue to inspect all characters in the <code>String</code> after first failure, and report all failures,
* whereas <code>forAll</code> will stop on (and only report) the first failure.
* </p>
*
* @param xs the <code>String</code>
* @param fun the inspection function
* @param collecting the implicit <code>Collecting</code> that can transform <code>xs</code> into a <code>scala.collection.GenTraversable</code>
*/
def forEvery[ASSERTION](xs: String)(fun: Char => ASSERTION)(implicit collecting: Collecting[Char, String], asserting: InspectorAsserting[ASSERTION], prettifier: Prettifier, pos: source.Position): asserting.Result = {
asserting.forEvery(collecting.genTraversableFrom(xs), xs, false, prettifier, pos)(fun)
}
}
/**
* Companion object that facilitates the importing of <code>Inspectors</code> members as
* an alternative to mixing it in. One use case is to import <code>Inspectors</code>'s members so you can use
* them in the Scala interpreter.
*/
object Inspectors extends Inspectors
private[scalatest] object InspectorsHelper {
def indentErrorMessages(messages: IndexedSeq[String]) = indentLines(1, messages)
def shouldPropagate(throwable: Throwable): Boolean =
throwable match {
case _: NotAllowedException |
_: TestPendingException |
_: TestCanceledException => true
case _ if Suite.anExceptionThatShouldCauseAnAbort(throwable) => true
case _ => false
}
}