1 // ****************************************************************
\r
2 // Copyright 2007, Charlie Poole
\r
3 // This is free software licensed under the NUnit license. You may
\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
\r
5 // ****************************************************************
\r
8 using NUnit.Framework.Constraints;
\r
10 namespace NUnit.Framework.SyntaxHelpers
\r
13 /// The Text class is a helper class with properties and methods
\r
14 /// that supply a number of constraints used with strings.
\r
19 /// Text.All returns a ConstraintBuilder, which will apply
\r
20 /// the following constraint to all members of a collection,
\r
21 /// succeeding if all of them succeed.
\r
23 public static ConstraintBuilder All
\r
25 get { return new ConstraintBuilder().All; }
\r
29 /// Contains returns a constraint that succeeds if the actual
\r
30 /// value contains the substring supplied as an argument.
\r
32 public static Constraint Contains(string substring)
\r
34 return new SubstringConstraint(substring);
\r
38 /// DoesNotContain returns a constraint that fails if the actual
\r
39 /// value contains the substring supplied as an argument.
\r
41 public static Constraint DoesNotContain(string substring)
\r
43 return new NotConstraint( Contains(substring) );
\r
47 /// StartsWith returns a constraint that succeeds if the actual
\r
48 /// value starts with the substring supplied as an argument.
\r
50 public static Constraint StartsWith(string substring)
\r
52 return new StartsWithConstraint(substring);
\r
56 /// DoesNotStartWith returns a constraint that fails if the actual
\r
57 /// value starts with the substring supplied as an argument.
\r
59 public static Constraint DoesNotStartWith(string substring)
\r
61 return new NotConstraint( StartsWith(substring) );
\r
65 /// EndsWith returns a constraint that succeeds if the actual
\r
66 /// value ends with the substring supplied as an argument.
\r
68 public static Constraint EndsWith(string substring)
\r
70 return new EndsWithConstraint(substring);
\r
74 /// DoesNotEndWith returns a constraint that fails if the actual
\r
75 /// value ends with the substring supplied as an argument.
\r
77 public static Constraint DoesNotEndWith(string substring)
\r
79 return new NotConstraint( EndsWith(substring) );
\r
83 /// Matches returns a constraint that succeeds if the actual
\r
84 /// value matches the pattern supplied as an argument.
\r
86 /// <param name="pattern"></param>
\r
87 /// <returns></returns>
\r
88 public static Constraint Matches(string pattern)
\r
90 return new RegexConstraint(pattern);
\r
94 /// DoesNotMatch returns a constraint that failss if the actual
\r
95 /// value matches the pattern supplied as an argument.
\r
97 /// <param name="pattern"></param>
\r
98 /// <returns></returns>
\r
99 public static Constraint DoesNotMatch(string pattern)
\r
101 return new NotConstraint( Matches(pattern) );
\r