/
NotWord.scala
1618 lines (1510 loc) · 61.8 KB
/
NotWord.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.dsl
import org.scalactic._
import org.scalatest.enablers._
import org.scalatest.matchers._
import org.scalatest._
import org.scalactic.TripleEqualsSupport.Spread
import org.scalactic.DefaultEquality.areEqualComparingArraysStructurally
import scala.collection.GenTraversable
import TripleEqualsSupport.TripleEqualsInvocation
// SKIP-SCALATESTJS,NATIVE-START
import org.scalatest.matchers.MatchersHelper.matchSymbolToPredicateMethod
// SKIP-SCALATESTJS,NATIVE-END
import org.scalatest.FailureMessages
import org.scalatest.matchers.MatchersHelper.endWithRegexWithGroups
import org.scalatest.matchers.MatchersHelper.fullyMatchRegexWithGroups
import org.scalatest.matchers.MatchersHelper.includeRegexWithGroups
import org.scalatest.matchers.MatchersHelper.startWithRegexWithGroups
import org.scalatest.Resources
import org.scalatest.Suite.getObjectsForFailureMessage
import org.scalatest.UnquotedString
import scala.annotation.tailrec
import org.scalatest.exceptions.NotAllowedException
/**
* This class is part of the ScalaTest matchers DSL. Please see the documentation for <a href="../Matchers.html"><code>Matchers</code></a> for an overview of
* the matchers DSL.
*
* @author Bill Venners
*/
final class NotWord {
/**
* This method enables the following syntax, where <code>tempFile</code>, for example, refers to a <code>java.io.File</code>
* and <code>exist</code> is a <code>Matcher[java.io.File]</code>:
*
* <pre class="stHighlighted">
* tempFile should not (exist)
* ^
* </pre>
**/
def apply[S](matcher: Matcher[S]): Matcher[S] =
new Matcher[S] {
def apply(left: S): MatchResult = matcher(left).negated
override def toString: String = "not (" + Prettifier.default(matcher) + ")"
}
import scala.language.higherKinds
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* hasNoSize should not { have size (<span class="stLiteral">2</span>) and equal (hasNoSize) }
* ^
* </pre>
**/
def apply[S, TYPECLASS[_]](matcherGen1: MatcherFactory1[S, TYPECLASS]): MatcherFactory1[S, TYPECLASS] = {
new MatcherFactory1[S, TYPECLASS] {
def matcher[V <: S : TYPECLASS]: Matcher[V] = {
val innerMatcher: Matcher[V] = matcherGen1.matcher
new Matcher[V] {
def apply(left: V): MatchResult = innerMatcher(left).negated
override def toString: String = "not (" + Prettifier.default(matcherGen1) + ")"
}
}
override def toString: String = "not (" + Prettifier.default(matcherGen1) + ")"
}
}
def apply[S, TYPECLASS1[_], TYPECLASS2[_]](matcherGen2: MatcherFactory2[S, TYPECLASS1, TYPECLASS2]): MatcherFactory2[S, TYPECLASS1, TYPECLASS2] = {
new MatcherFactory2[S, TYPECLASS1, TYPECLASS2] {
def matcher[V <: S : TYPECLASS1 : TYPECLASS2]: Matcher[V] = {
val innerMatcher: Matcher[V] = matcherGen2.matcher
new Matcher[V] {
def apply(left: V): MatchResult = innerMatcher(left).negated
override def toString: String = "not (" + Prettifier.default(matcherGen2) + ")"
}
}
override def toString: String = "not (" + Prettifier.default(matcherGen2) + ")"
}
}
/**
* This method enables any <code>BeMatcher</code> to be negated by passing it to <code>not</code>.
* For example, if you have a <code>BeMatcher[Int]</code> called <code>odd</code>, which matches
* <code>Int</code>s that are odd, you can negate it to get a <code>BeMatcher[Int]</code> that matches
* even <code>Int</code>s, like this:
*
* <pre class="stHighlighted">
* <span class="stReserved">val</span> even = not (odd)
* ^
* </pre>
*
* <p>
* In addition, this method enables you to negate a <code>BeMatcher</code> at its point of use, like this:
* </p>
*
* <pre class="stHighlighted">
* num should be (not (odd))
* </pre>
*
* <p>
* Nevertheless, in such as case it would be more idiomatic to write:
* </p>
*
* <pre class="stHighlighted">
* num should not be (odd)
* </pre>
*/
def apply[S](beMatcher: BeMatcher[S]): BeMatcher[S] =
new BeMatcher[S] {
def apply(left: S): MatchResult = beMatcher(left).negated
override def toString: String = "not (" + Prettifier.default(beMatcher) + ")"
}
/**
* This method enables syntax such as the following:
*
* <pre class="stHighlighted">
* file should not (exist)
* ^
* </pre>
**/
def apply(existWord: ExistWord): ResultOfNotExist =
new ResultOfNotExist(this)
/*
* This is used in logical expression like:
* outerInstance.and(MatcherWords.not.exist)
* ^
*/
private[scalatest] val exist: MatcherFactory1[Any, Existence] =
new MatcherFactory1[Any, Existence] {
def matcher[T : Existence]: Matcher[T] =
new Matcher[T] {
def apply(left: T): MatchResult = {
val existence = implicitly[Existence[T]]
MatchResult(
!existence.exists(left),
Resources.rawExists,
Resources.rawDoesNotExist,
Vector(left)
)
}
override def toString: String = "not exist"
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* num should (not equal (<span class="stLiteral">7</span>) and be < (<span class="stLiteral">9</span>))
* ^
* </pre>
**/
def equal(right: Any): MatcherFactory1[Any, Equality] = apply(MatcherWords.equal(right))
/**
* This method enables the following syntax for the "primitive" numeric types:
*
* <pre class="stHighlighted">
* sevenDotOh should ((not equal (<span class="stLiteral">17.1</span> +- <span class="stLiteral">0.2</span>)) and (not equal (<span class="stLiteral">27.1</span> +- <span class="stLiteral">0.2</span>)))
* ^
* </pre>
**/
def equal[U](spread: Spread[U]): Matcher[U] = {
new Matcher[U] {
def apply(left: U): MatchResult = {
MatchResult(
!(spread.isWithin(left)),
Resources.rawEqualedPlusOrMinus,
Resources.rawDidNotEqualPlusOrMinus,
Vector(left, spread.pivot, spread.tolerance)
)
}
override def toString: String = "not equal " + Prettifier.default(spread)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* map should (not equal (<span class="stReserved">null</span>))
* ^
* </pre>
**/
def equal(o: Null): Matcher[AnyRef] =
new Matcher[AnyRef] {
def apply(left: AnyRef): MatchResult = {
MatchResult(
left != null,
Resources.rawEqualedNull,
Resources.rawDidNotEqualNull,
Resources.rawMidSentenceEqualedNull,
Resources.rawDidNotEqualNull,
Vector.empty,
Vector(left),
Vector.empty,
Vector(left)
)
}
override def toString: String = "not equal null"
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* <span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>) should (not have length (<span class="stLiteral">5</span>) and not have length (<span class="stLiteral">3</span>))
* ^
* </pre>
**/
def have(resultOfLengthWordApplication: ResultOfLengthWordApplication): MatcherFactory1[Any, Length] =
apply(MatcherWords.have.length(resultOfLengthWordApplication.expectedLength))
// This looks similar to the AndNotWord one, but not quite the same because no and
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* <span class="stType">Array</span>(<span class="stLiteral">1</span>, <span class="stLiteral">2</span>) should (not have size (<span class="stLiteral">5</span>) and not have size (<span class="stLiteral">3</span>))
* ^
* </pre>
**/
def have(resultOfSizeWordApplication: ResultOfSizeWordApplication): MatcherFactory1[Any, Size] =
apply(MatcherWords.have.size(resultOfSizeWordApplication.expectedSize))
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* result should (not have message (<span class="stQuotedString">"Message from Mars!"</span>) and not have message (<span class="stQuotedString">"Message from Mars!"</span>))
* ^
* </pre>
**/
def have(resultOfMessageWordApplication: ResultOfMessageWordApplication): MatcherFactory1[Any, Messaging] =
apply(MatcherWords.have.message(resultOfMessageWordApplication.expectedMessage))
/**
* This method enables the following syntax, where, for example, <code>book</code> is of type <code>Book</code> and <code>title</code> and <code>author</code>
* are both of type <code>HavePropertyMatcher[Book, String]</code>:
*
* <pre class="stHighlighted">
* book should (not have (title (<span class="stQuotedString">"Moby Dick"</span>)) and (not have (author (<span class="stQuotedString">"Melville"</span>))))
* ^
* </pre>
**/
def have[T](firstPropertyMatcher: HavePropertyMatcher[T, _], propertyMatchers: HavePropertyMatcher[T, _]*): Matcher[T] =
apply(MatcherWords.have(firstPropertyMatcher, propertyMatchers: _*))
/**
* This method enables the following syntax, where, for example, <code>num</code> is an <code>Int</code> and <code>odd</code>
* of type <code>BeMatcher[Int]</code>:
*
* <pre class="stHighlighted">
* num should (not be (odd) and be <= (<span class="stLiteral">8</span>))
* ^
* </pre>
**/
def be[T](beMatcher: BeMatcher[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = beMatcher(left).negated
override def toString: String = "not be " + Prettifier.default(beMatcher)
}
}
import scala.language.experimental.macros
/**
* This method enables the following syntax, where, for example, <code>num</code> is an <code>Int</code> and <code>odd</code>
* of type <code>BeMatcher[Int]</code>:
*
* <pre class="stHighlighted">
* result should (not matchPattern { <span class="stReserved">case</span> <span class="stType">Person</span>(<span class="stQuotedString">"Bob"</span>, _)} and equal (result2))
* ^
* </pre>
**/
def matchPattern(right: PartialFunction[Any, _]): Matcher[Any] = macro MatchPatternMacro.notMatchPatternMatcher
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* map should (not be (<span class="stReserved">null</span>))
* ^
* </pre>
**/
def be(o: Null): Matcher[AnyRef] =
new Matcher[AnyRef] {
def apply(left: AnyRef): MatchResult = {
MatchResult(
left != null,
Resources.rawWasNull,
Resources.rawWasNotNull,
Resources.rawMidSentenceWasNull,
Resources.rawWasNotNull,
Vector.empty,
Vector(left),
Vector.empty,
Vector(left)
)
}
override def toString: String = "not be null"
}
// These next four are for things like not be </>/<=/>=:
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* num should (not be < (<span class="stLiteral">7</span>) and not be > (<span class="stLiteral">10</span>))
* ^
* </pre>
**/
def be[T](resultOfLessThanComparison: ResultOfLessThanComparison[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult =
MatchResult(
!resultOfLessThanComparison(left),
Resources.rawWasLessThan,
Resources.rawWasNotLessThan,
Vector(left, resultOfLessThanComparison.right)
)
override def toString: String = "not be " + Prettifier.default(resultOfLessThanComparison)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* num should (not be > (<span class="stLiteral">10</span>) and not be < (<span class="stLiteral">7</span>))
* ^
* </pre>
**/
def be[T](resultOfGreaterThanComparison: ResultOfGreaterThanComparison[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult =
MatchResult(
!resultOfGreaterThanComparison(left),
Resources.rawWasGreaterThan,
Resources.rawWasNotGreaterThan,
Vector(left, resultOfGreaterThanComparison.right)
)
override def toString: String = "not be " + Prettifier.default(resultOfGreaterThanComparison)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* num should (not be <= (<span class="stLiteral">7</span>) and not be > (<span class="stLiteral">10</span>))
* ^
* </pre>
**/
def be[T](resultOfLessThanOrEqualToComparison: ResultOfLessThanOrEqualToComparison[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult =
MatchResult(
!resultOfLessThanOrEqualToComparison(left),
Resources.rawWasLessThanOrEqualTo,
Resources.rawWasNotLessThanOrEqualTo,
Vector(left, resultOfLessThanOrEqualToComparison.right)
)
override def toString: String = "not be " + Prettifier.default(resultOfLessThanOrEqualToComparison)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* num should (not be >= (<span class="stLiteral">10</span>) and not be < (<span class="stLiteral">7</span>))
* ^
* </pre>
**/
def be[T](resultOfGreaterThanOrEqualToComparison: ResultOfGreaterThanOrEqualToComparison[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult =
MatchResult(
!resultOfGreaterThanOrEqualToComparison(left),
Resources.rawWasGreaterThanOrEqualTo,
Resources.rawWasNotGreaterThanOrEqualTo,
Vector(left, resultOfGreaterThanOrEqualToComparison.right)
)
override def toString: String = "not be " + Prettifier.default(resultOfGreaterThanOrEqualToComparison)
}
}
/**
* <strong>
* The deprecation period for the "be ===" syntax has expired, and the syntax
* will now throw <code>NotAllowedException</code>. Please use should equal, should ===, shouldEqual,
* should be, or shouldBe instead.
* </strong>
*
* <p>
* Note: usually syntax will be removed after its deprecation period. This was left in because otherwise the syntax could in some
* cases still compile, but silently wouldn't work.
* </p>
*/
@deprecated("The deprecation period for the be === syntax has expired. Please use should equal, should ===, shouldEqual, should be, or shouldBe instead.")
def be(tripleEqualsInvocation: TripleEqualsInvocation[_])(implicit pos: source.Position): Matcher[Any] = {
throw new NotAllowedException(FailureMessages.beTripleEqualsNotAllowed, pos)
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* myFile should (not be (<span class="stQuotedString">'hidden</span>) and have (name (<span class="stQuotedString">"temp.txt"</span>)))
* ^
* </pre>
**/
def be[T <: AnyRef](symbol: Symbol)(implicit prettifier: Prettifier, pos: source.Position): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
val positiveMatchResult = matchSymbolToPredicateMethod(left, symbol, false, false, prettifier, pos)
MatchResult(
!positiveMatchResult.matches,
positiveMatchResult.rawNegatedFailureMessage,
positiveMatchResult.rawFailureMessage,
positiveMatchResult.negatedFailureMessageArgs,
positiveMatchResult.failureMessageArgs
)
}
override def toString: String = "not be " + Prettifier.default(symbol)
}
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* This method enables the following syntax, where <code>tempFile</code>, for example, refers to a <code>java.io.File</code>
* and <code>hidden</code> is a <code>BePropertyMatcher[java.io.File]</code>:
*
* <pre class="stHighlighted">
* tempFile should (not be (hidden) and have (<span class="stQuotedString">'name</span> (<span class="stQuotedString">"temp.txt"</span>)))
* ^
* </pre>
**/
def be[T <: AnyRef](bePropertyMatcher: BePropertyMatcher[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
val result = bePropertyMatcher(left)
MatchResult(
!result.matches,
Resources.rawWas,
Resources.rawWasNot,
Vector(left, UnquotedString(result.propertyName))
)
}
override def toString: String = "not be " + Prettifier.default(bePropertyMatcher)
}
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* isNotFileMock should (not be a (<span class="stQuotedString">'file</span>) and have (<span class="stQuotedString">'name</span> (<span class="stQuotedString">"temp.txt"</span>))))
* ^
* </pre>
**/
def be[T <: AnyRef](resultOfAWordApplication: ResultOfAWordToSymbolApplication)(implicit prettifier: Prettifier, pos: source.Position): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
val positiveMatchResult = matchSymbolToPredicateMethod(left, resultOfAWordApplication.symbol, true, true, prettifier, pos)
MatchResult(
!positiveMatchResult.matches,
positiveMatchResult.rawNegatedFailureMessage,
positiveMatchResult.rawFailureMessage,
positiveMatchResult.negatedFailureMessageArgs,
positiveMatchResult.failureMessageArgs
)
}
override def toString: String = "not be " + Prettifier.default(resultOfAWordApplication)
}
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* This method enables the following syntax, where <code>notSoSecretFile</code>, for example, refers to a <code>java.io.File</code>
* and <code>directory</code> is a <code>BePropertyMatcher[java.io.File]</code>:
*
* <pre class="stHighlighted">
* notSoSecretFile should (not be a (directory) and have (<span class="stQuotedString">'name</span> (<span class="stQuotedString">"passwords.txt"</span>)))
* ^
* </pre>
**/
def be[T <: AnyRef](resultOfAWordApplication: ResultOfAWordToBePropertyMatcherApplication[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
val result = resultOfAWordApplication.bePropertyMatcher(left)
MatchResult(
!result.matches,
Resources.rawWasA,
Resources.rawWasNotA,
Vector(left, UnquotedString(result.propertyName))
)
}
override def toString: String = "not be " + Prettifier.default(resultOfAWordApplication)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* result should (not be a (passedMarks) and be a (validMarks)))
* ^
* </pre>
**/
def be[T](resultOfAWordApplication: ResultOfAWordToAMatcherApplication[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
val result = resultOfAWordApplication.aMatcher(left)
MatchResult(
!result.matches,
result.rawNegatedFailureMessage,
result.rawFailureMessage,
result.negatedFailureMessageArgs,
result.failureMessageArgs
)
}
override def toString: String = "not be " + Prettifier.default(resultOfAWordApplication)
}
}
// SKIP-SCALATESTJS,NATIVE-START
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* isNotAppleMock should (not be an (<span class="stQuotedString">'apple</span>) and not be (<span class="stQuotedString">'rotten</span>))
* ^
* </pre>
**/
def be[T <: AnyRef](resultOfAnWordApplication: ResultOfAnWordToSymbolApplication)(implicit prettifier: Prettifier, pos: source.Position): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
val positiveMatchResult = matchSymbolToPredicateMethod(left, resultOfAnWordApplication.symbol, true, false, prettifier, pos)
MatchResult(
!positiveMatchResult.matches,
positiveMatchResult.rawNegatedFailureMessage,
positiveMatchResult.rawFailureMessage,
positiveMatchResult.negatedFailureMessageArgs,
positiveMatchResult.failureMessageArgs
)
}
override def toString: String = "not be " + Prettifier.default(resultOfAnWordApplication)
}
}
// SKIP-SCALATESTJS,NATIVE-END
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* myFile should (not be an (directory) and not be an (directory))
* ^
* </pre>
**/
def be[T <: AnyRef](resultOfAnWordApplication: ResultOfAnWordToBePropertyMatcherApplication[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
val result = resultOfAnWordApplication.bePropertyMatcher(left)
MatchResult(
!result.matches,
Resources.rawWasAn,
Resources.rawWasNotAn,
Vector(left, UnquotedString(result.propertyName))
)
}
override def toString: String = "not be " + Prettifier.default(resultOfAnWordApplication)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* result should (not be a (passedMarks) and be a (validMarks)))
* ^
* </pre>
**/
def be[T](resultOfAnWordApplication: ResultOfAnWordToAnMatcherApplication[T]): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
val result = resultOfAnWordApplication.anMatcher(left)
MatchResult(
!result.matches,
result.rawNegatedFailureMessage,
result.rawFailureMessage,
result.negatedFailureMessageArgs,
result.failureMessageArgs
)
}
override def toString: String = "not be " + Prettifier.default(resultOfAnWordApplication)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* myFish should (not be theSameInstanceAs (redFish) and not be theSameInstanceAs (blueFish))
* ^
* </pre>
**/
def be[T <: AnyRef](resultOfTheSameInstanceAsApplication: ResultOfTheSameInstanceAsApplication): Matcher[T] = {
new Matcher[T] {
def apply(left: T): MatchResult = {
MatchResult(
resultOfTheSameInstanceAsApplication.right ne left,
Resources.rawWasSameInstanceAs,
Resources.rawWasNotSameInstanceAs,
Vector(left, resultOfTheSameInstanceAsApplication.right)
)
}
override def toString: String = "not be " + Prettifier.default(resultOfTheSameInstanceAsApplication)
}
}
/**
* This method enables the following syntax for the "primitive" numeric types:
*
* <pre class="stHighlighted">
* sevenDotOh should ((not be (<span class="stLiteral">17.1</span> +- <span class="stLiteral">0.2</span>)) and (not be (<span class="stLiteral">27.1</span> +- <span class="stLiteral">0.2</span>)))
* ^
* </pre>
**/
def be[U](spread: Spread[U]): Matcher[U] = {
new Matcher[U] {
def apply(left: U): MatchResult = {
MatchResult(
!(spread.isWithin(left)),
Resources.rawWasPlusOrMinus,
Resources.rawWasNotPlusOrMinus,
Vector(left, spread.pivot, spread.tolerance)
)
}
override def toString: String = "not be " + Prettifier.default(spread)
}
}
/**
* This method enables the following syntax, where fraction is a <code>PartialFunction</code>:
*
* <pre class="stHighlighted">
* fraction should (not be definedAt (<span class="stLiteral">8</span>) and not be definedAt (<span class="stLiteral">0</span>))
* ^
* </pre>
**/
def be[A, U <: PartialFunction[A, _]](resultOfDefinedAt: ResultOfDefinedAt[A]): Matcher[U] = {
new Matcher[U] {
def apply(left: U): MatchResult =
MatchResult(
!(left.isDefinedAt(resultOfDefinedAt.right)),
Resources.rawWasDefinedAt,
Resources.rawWasNotDefinedAt,
Vector(left, resultOfDefinedAt.right)
)
override def toString: String = "not be " + Prettifier.default(resultOfDefinedAt)
}
}
/**
* This method enables <code>be</code> to be used for inequality comparison. Here are some examples:
*
* <pre class="stHighlighted">
* result should not be (<span class="stType">None</span>)
* ^
* result should not be (<span class="stType">Some</span>(<span class="stLiteral">1</span>))
* ^
* result should not be (<span class="stReserved">true</span>)
* ^
* result should not be (<span class="stReserved">false</span>)
* ^
* sum should not be (<span class="stLiteral">19</span>)
* ^
* </pre>
**/
def be(right: Any): Matcher[Any] = {
new Matcher[Any] {
def apply(left: Any): MatchResult = {
left match {
case null =>
MatchResult(
right != null,
Resources.rawWasNull,
Resources.rawWasNotNull,
Resources.rawMidSentenceWasNull,
Resources.rawWasNotNull,
Vector.empty,
Vector(right)
)
case _ =>
val (leftee, rightee) = getObjectsForFailureMessage(left, right) // TODO: To move this to reporter
MatchResult(
!areEqualComparingArraysStructurally(left, right),
Resources.rawWasEqualTo,
Resources.rawWasNotEqualTo,
Vector(left, right),
Vector(leftee, rightee)
)
}
}
override def toString: String = "not be " + Prettifier.default(right)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* fraction should (not be sorted and not be sorted)
* ^
* </pre>
**/
def be[T](sortedWord: SortedWord): MatcherFactory1[Any, Sortable] =
apply(MatcherWords.be(sortedWord))
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* fraction should (not be readable and not equal readableFile)
* ^
* </pre>
**/
def be(readableWord: ReadableWord): MatcherFactory1[Any, Readability] =
apply(MatcherWords.be(readableWord))
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* fraction should (not be writable and not be writableFile)
* ^
* </pre>
**/
def be(writableWord: WritableWord): MatcherFactory1[Any, Writability] =
apply(MatcherWords.be(writableWord))
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* nonEmptyList should (not be empty and not equal emptyList)
* ^
* </pre>
**/
def be(emptyWord: EmptyWord): MatcherFactory1[Any, Emptiness] =
apply(MatcherWords.be(emptyWord))
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* result should (not be defined and not equal something)
* ^
* </pre>
**/
def be(definedWord: DefinedWord): MatcherFactory1[Any, Definition] =
apply(MatcherWords.be(definedWord))
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* result should (not be a [<span class="stType">Book</span>] and not be sorted)
* ^
* </pre>
**/
def be(aType: ResultOfATypeInvocation[_]): Matcher[Any] = macro TypeMatcherMacro.notATypeMatcher
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* result should (not be an [<span class="stType">Book</span>] and not be sorted)
* ^
* </pre>
**/
def be(anType: ResultOfAnTypeInvocation[_]): Matcher[Any] = macro TypeMatcherMacro.notAnTypeMatcher
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* string should (not fullyMatch regex (<span class="stQuotedString">"Hel*o"</span>) and not include (<span class="stQuotedString">"orld"</span>))
* ^
* </pre>
**/
def fullyMatch(resultOfRegexWordApplication: ResultOfRegexWordApplication): Matcher[String] = {
new Matcher[String] {
def apply(left: String): MatchResult = {
val result = fullyMatchRegexWithGroups(left, resultOfRegexWordApplication.regex, resultOfRegexWordApplication.groups)
MatchResult(
!result.matches,
result.rawNegatedFailureMessage,
result.rawFailureMessage,
result.negatedFailureMessageArgs,
result.failureMessageArgs
)
}
override def toString: String = "not fullyMatch " + Prettifier.default(resultOfRegexWordApplication)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* string should (not include regex (<span class="stQuotedString">"Hel.o"</span>) and not include regex (<span class="stQuotedString">"""(-)?(\d+)(\.\d*)?"""</span>))
* ^
* </pre>
**/
def include(resultOfRegexWordApplication: ResultOfRegexWordApplication): Matcher[String] = {
val rightRegex = resultOfRegexWordApplication.regex
new Matcher[String] {
def apply(left: String): MatchResult = {
val result = includeRegexWithGroups(left, resultOfRegexWordApplication.regex, resultOfRegexWordApplication.groups)
MatchResult(
!result.matches,
result.rawNegatedFailureMessage,
result.rawFailureMessage,
result.negatedFailureMessageArgs,
result.failureMessageArgs
)
}
override def toString: String = "not include " + Prettifier.default(resultOfRegexWordApplication)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* string should (not include (<span class="stQuotedString">"cat"</span>) and not include (<span class="stQuotedString">"1.7"</span>))
* ^
* </pre>
**/
def include(expectedSubstring: String): Matcher[String] = {
new Matcher[String] {
def apply(left: String): MatchResult =
MatchResult(
!(left.indexOf(expectedSubstring) >= 0),
Resources.rawIncludedSubstring,
Resources.rawDidNotIncludeSubstring,
Vector(left, expectedSubstring)
)
override def toString: String = "not include " + Prettifier.default(expectedSubstring)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* string should (not startWith regex (<span class="stQuotedString">"hel*o"</span>) and not endWith regex (<span class="stQuotedString">"wor.d"</span>))
* ^
* </pre>
**/
def startWith(resultOfRegexWordApplication: ResultOfRegexWordApplication): Matcher[String] = {
val rightRegex = resultOfRegexWordApplication.regex
new Matcher[String] {
def apply(left: String): MatchResult = {
val result = startWithRegexWithGroups(left, resultOfRegexWordApplication.regex, resultOfRegexWordApplication.groups)
MatchResult(
!result.matches,
result.rawNegatedFailureMessage,
result.rawFailureMessage,
result.negatedFailureMessageArgs,
result.failureMessageArgs
)
}
override def toString: String = "not startWith " + Prettifier.default(resultOfRegexWordApplication)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* string should ((not startWith (<span class="stQuotedString">"red"</span>)) and (not startWith (<span class="stQuotedString">"1.7"</span>)))
* ^
* </pre>
**/
def startWith(expectedSubstring: String): Matcher[String] = {
new Matcher[String] {
def apply(left: String): MatchResult =
MatchResult(
left.indexOf(expectedSubstring) != 0,
Resources.rawStartedWith,
Resources.rawDidNotStartWith,
Vector(left, expectedSubstring)
)
override def toString: String = "not startWith " + Prettifier.default(expectedSubstring)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* string should (not endWith regex (<span class="stQuotedString">"wor.d"</span>) and not startWith regex (<span class="stQuotedString">"Hel*o"</span>))
* ^
* </pre>
**/
def endWith(resultOfRegexWordApplication: ResultOfRegexWordApplication): Matcher[String] = {
val rightRegex = resultOfRegexWordApplication.regex
new Matcher[String] {
def apply(left: String): MatchResult = {
val result = endWithRegexWithGroups(left, resultOfRegexWordApplication.regex, resultOfRegexWordApplication.groups)
MatchResult(
!result.matches,
result.rawNegatedFailureMessage,
result.rawFailureMessage,
result.negatedFailureMessageArgs,
result.failureMessageArgs
)
}
override def toString: String = "not endWith " + Prettifier.default(resultOfRegexWordApplication)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* string should (not endWith (<span class="stQuotedString">"blue"</span>) and not endWith (<span class="stQuotedString">"1.7"</span>))
* ^
* </pre>
**/
def endWith(expectedSubstring: String): Matcher[String] = {
new Matcher[String] {
def apply(left: String): MatchResult = {
MatchResult(
!(left endsWith expectedSubstring),
Resources.rawEndedWith,
Resources.rawDidNotEndWith,
Vector(left, expectedSubstring)
)
}
override def toString: String = "not endWith " + Prettifier.default(expectedSubstring)
}
}
/**
* This method enables the following syntax:
*
* <pre class="stHighlighted">
* list should (not contain (<span class="stReserved">null</span>))
* ^
* </pre>
**/
def contain(nullValue: Null): MatcherFactory1[Any, Containing] = {
new MatcherFactory1[Any, Containing] {
def matcher[U : Containing]: Matcher[U] =
new Matcher[U] {
def apply(left: U): MatchResult = {
val containing = implicitly[Containing[U]]
MatchResult(
!containing.contains(left, null),
Resources.rawContainedNull,
Resources.rawDidNotContainNull,
Vector(left)
)
}
override def toString: String = "not contain null"
}
override def toString: String = "not contain null"
}
}
/**
* This method enables the following syntax:
*