[configure] rename "--with-interpreter=yes" to "--enable-interpreter"
[mono.git] / mcs / nunit24 / NUnitFramework / framework / StringAssert.cs
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
6 \r
7 using System.ComponentModel;\r
8 using NUnit.Framework.Constraints;\r
9 \r
10 namespace NUnit.Framework\r
11 {\r
12         /// <summary>\r
13         /// Basic Asserts on strings.\r
14         /// </summary>\r
15         public class StringAssert\r
16         {\r
17                 #region Equals and ReferenceEquals\r
18 \r
19                 /// <summary>\r
20                 /// The Equals method throws an AssertionException. This is done \r
21                 /// to make sure there is no mistake by calling this function.\r
22                 /// </summary>\r
23                 /// <param name="a"></param>\r
24                 /// <param name="b"></param>\r
25                 [EditorBrowsable(EditorBrowsableState.Never)]\r
26                 public static new bool Equals(object a, object b)\r
27                 {\r
28                         throw new AssertionException("Assert.Equals should not be used for Assertions");\r
29                 }\r
30 \r
31                 /// <summary>\r
32                 /// override the default ReferenceEquals to throw an AssertionException. This \r
33                 /// implementation makes sure there is no mistake in calling this function \r
34                 /// as part of Assert. \r
35                 /// </summary>\r
36                 /// <param name="a"></param>\r
37                 /// <param name="b"></param>\r
38                 public static new void ReferenceEquals(object a, object b)\r
39                 {\r
40                         throw new AssertionException("Assert.ReferenceEquals should not be used for Assertions");\r
41                 }\r
42 \r
43                 #endregion\r
44                                 \r
45                 #region Contains\r
46 \r
47                 /// <summary>\r
48                 /// Asserts that a string is found within another string.\r
49                 /// </summary>\r
50                 /// <param name="expected">The expected string</param>\r
51                 /// <param name="actual">The string to be examined</param>\r
52                 /// <param name="message">The message to display in case of failure</param>\r
53                 /// <param name="args">Arguments used in formatting the message</param>\r
54                 static public void Contains( string expected, string actual, string message, params object[] args )\r
55                 {\r
56             Assert.That(actual, new SubstringConstraint(expected), message, args);\r
57                 }\r
58 \r
59                 /// <summary>\r
60                 /// Asserts that a string is found within another string.\r
61                 /// </summary>\r
62                 /// <param name="expected">The expected string</param>\r
63                 /// <param name="actual">The string to be examined</param>\r
64                 /// <param name="message">The message to display in case of failure</param>\r
65                 static public void Contains( string expected, string actual, string message )\r
66                 {\r
67                         Contains( expected, actual, message, null );\r
68                 }\r
69 \r
70                 /// <summary>\r
71                 /// Asserts that a string is found within another string.\r
72                 /// </summary>\r
73                 /// <param name="expected">The expected string</param>\r
74                 /// <param name="actual">The string to be examined</param>\r
75                 static public void Contains( string expected, string actual )\r
76                 {\r
77                         Contains( expected, actual, string.Empty, null );\r
78                 }\r
79 \r
80                 #endregion\r
81 \r
82                 #region StartsWith\r
83 \r
84                 /// <summary>\r
85                 /// Asserts that a string starts with another string.\r
86                 /// </summary>\r
87                 /// <param name="expected">The expected string</param>\r
88                 /// <param name="actual">The string to be examined</param>\r
89                 /// <param name="message">The message to display in case of failure</param>\r
90                 /// <param name="args">Arguments used in formatting the message</param>\r
91                 static public void StartsWith( string expected, string actual, string message, params object[] args )\r
92                 {\r
93             Assert.That(actual, new StartsWithConstraint(expected), message, args);\r
94                 }\r
95 \r
96                 /// <summary>\r
97                 /// Asserts that a string starts with another string.\r
98                 /// </summary>\r
99                 /// <param name="expected">The expected string</param>\r
100                 /// <param name="actual">The string to be examined</param>\r
101                 /// <param name="message">The message to display in case of failure</param>\r
102                 static public void StartsWith( string expected, string actual, string message )\r
103                 {\r
104                         StartsWith( expected, actual, message, null );\r
105                 }\r
106 \r
107                 /// <summary>\r
108                 /// Asserts that a string starts with another string.\r
109                 /// </summary>\r
110                 /// <param name="expected">The expected string</param>\r
111                 /// <param name="actual">The string to be examined</param>\r
112                 static public void StartsWith( string expected, string actual )\r
113                 {\r
114                         StartsWith( expected, actual, string.Empty, null );\r
115                 }\r
116 \r
117                 #endregion\r
118 \r
119                 #region EndsWith\r
120 \r
121                 /// <summary>\r
122                 /// Asserts that a string ends with another string.\r
123                 /// </summary>\r
124                 /// <param name="expected">The expected string</param>\r
125                 /// <param name="actual">The string to be examined</param>\r
126                 /// <param name="message">The message to display in case of failure</param>\r
127                 /// <param name="args">Arguments used in formatting the message</param>\r
128                 static public void EndsWith( string expected, string actual, string message, params object[] args )\r
129                 {\r
130             Assert.That(actual, new EndsWithConstraint(expected), message, args);\r
131                 }\r
132 \r
133                 /// <summary>\r
134                 /// Asserts that a string ends with another string.\r
135                 /// </summary>\r
136                 /// <param name="expected">The expected string</param>\r
137                 /// <param name="actual">The string to be examined</param>\r
138                 /// <param name="message">The message to display in case of failure</param>\r
139                 static public void EndsWith( string expected, string actual, string message )\r
140                 {\r
141                         EndsWith( expected, actual, message, null );\r
142                 }\r
143 \r
144                 /// <summary>\r
145                 /// Asserts that a string ends with another string.\r
146                 /// </summary>\r
147                 /// <param name="expected">The expected string</param>\r
148                 /// <param name="actual">The string to be examined</param>\r
149                 static public void EndsWith( string expected, string actual )\r
150                 {\r
151                         EndsWith( expected, actual, string.Empty, null );\r
152                 }\r
153 \r
154                 #endregion\r
155 \r
156                 #region AreEqualIgnoringCase\r
157                 /// <summary>\r
158                 /// Asserts that two strings are equal, without regard to case.\r
159                 /// </summary>\r
160                 /// <param name="expected">The expected string</param>\r
161                 /// <param name="actual">The actual string</param>\r
162                 /// <param name="message">The message to display in case of failure</param>\r
163                 /// <param name="args">Arguments used in formatting the message</param>\r
164                 static public void AreEqualIgnoringCase( string expected, string actual, string message, params object[] args )\r
165                 {\r
166             Assert.That(actual, new EqualConstraint(expected).IgnoreCase, message, args);\r
167                 }\r
168 \r
169                 /// <summary>\r
170                 /// Asserts that two strings are equal, without regard to case.\r
171                 /// </summary>\r
172                 /// <param name="expected">The expected string</param>\r
173                 /// <param name="actual">The actual string</param>\r
174                 /// <param name="message">The message to display in case of failure</param>\r
175                 static public void AreEqualIgnoringCase( string expected, string actual, string message )\r
176                 {\r
177                         AreEqualIgnoringCase( expected, actual, message, null );\r
178                 }\r
179 \r
180                 /// <summary>\r
181                 /// Asserts that two strings are equal, without regard to case.\r
182                 /// </summary>\r
183                 /// <param name="expected">The expected string</param>\r
184                 /// <param name="actual">The actual string</param>\r
185                 static public void AreEqualIgnoringCase( string expected, string actual )\r
186                 {\r
187                         AreEqualIgnoringCase( expected, actual, string.Empty, null );\r
188                 }\r
189 \r
190                 #endregion\r
191 \r
192                 #region IsMatch\r
193                 /// <summary>\r
194                 /// Asserts that a string matches an expected regular expression pattern.\r
195                 /// </summary>\r
196                 /// <param name="expected">The expected expression</param>\r
197                 /// <param name="actual">The actual string</param>\r
198                 /// <param name="message">The message to display in case of failure</param>\r
199                 /// <param name="args">Arguments used in formatting the message</param>\r
200                 static public void IsMatch( string expected, string actual, string message, params object[] args )\r
201                 {\r
202             Assert.That(actual, new RegexConstraint(expected), message, args);\r
203                 }\r
204 \r
205                 /// <summary>\r
206                 /// Asserts that a string matches an expected regular expression pattern.\r
207                 /// </summary>\r
208                 /// <param name="expected">The expected expression</param>\r
209                 /// <param name="actual">The actual string</param>\r
210                 /// <param name="message">The message to display in case of failure</param>\r
211                 static public void IsMatch( string expected, string actual, string message )\r
212                 {\r
213                         IsMatch( expected, actual, message, null );\r
214                 }\r
215 \r
216                 /// <summary>\r
217                 /// Asserts that a string matches an expected regular expression pattern.\r
218                 /// </summary>\r
219                 /// <param name="expected">The expected expression</param>\r
220                 /// <param name="actual">The actual string</param>\r
221                 static public void IsMatch( string expected, string actual )\r
222                 {\r
223                         IsMatch( expected, actual, string.Empty, null );\r
224                 }\r
225                 #endregion\r
226         }\r
227 }\r