1 | <!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
---|
2 | <html>
|
---|
3 | <!-- Standard Head Part -->
|
---|
4 | <head>
|
---|
5 | <title>NUnit - StringConstraints</title>
|
---|
6 | <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
---|
7 | <meta http-equiv="Content-Language" content="en-US">
|
---|
8 | <link rel="stylesheet" type="text/css" href="nunit.css">
|
---|
9 | <link rel="shortcut icon" href="favicon.ico">
|
---|
10 | </head>
|
---|
11 | <!-- End Standard Head Part -->
|
---|
12 |
|
---|
13 | <body>
|
---|
14 |
|
---|
15 | <!-- Standard Header for NUnit.org -->
|
---|
16 | <div id="header">
|
---|
17 | <a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
|
---|
18 | <div id="nav">
|
---|
19 | <a href="http://www.nunit.org">NUnit</a>
|
---|
20 | <a class="active" href="index.html">Documentation</a>
|
---|
21 | </div>
|
---|
22 | </div>
|
---|
23 | <!-- End of Header -->
|
---|
24 |
|
---|
25 | <div id="content">
|
---|
26 |
|
---|
27 | <h2>String Constraints (NUnit 2.4)</h2>
|
---|
28 |
|
---|
29 | <p>String constraints perform tests that are specific to strings.
|
---|
30 | Attempting to test a non-string value with a string constraint
|
---|
31 | is an error and gives an exception.
|
---|
32 |
|
---|
33 | <p>The <b>Text</b> prefix is deprecated beginning with NUnit 2.5.1
|
---|
34 | and will be removed in NUnit 3.0.
|
---|
35 |
|
---|
36 | <h3>SubstringConstraint</h3>
|
---|
37 |
|
---|
38 | <h4>Action</h4>
|
---|
39 | <p>Tests for a substring.
|
---|
40 |
|
---|
41 | <h4>Constructor</h4>
|
---|
42 | <div class="code"><pre>
|
---|
43 | SubstringConstraint(string expected)
|
---|
44 | </pre></div>
|
---|
45 |
|
---|
46 | <h4>Syntax</h4>
|
---|
47 | <div class="code"><pre>
|
---|
48 | Is.StringContaining(string expected)
|
---|
49 | Contains.Substring(string expected)
|
---|
50 | ContainsSubstring(string expected)
|
---|
51 | Contains(string expected)
|
---|
52 | [Obsolete] Text.Contains(string expected)
|
---|
53 | [Obsolete] Text.DoesNotContain(string expected)
|
---|
54 | </pre></div>
|
---|
55 |
|
---|
56 | <h4>Modifiers</h4>
|
---|
57 | <div class="code"><pre>
|
---|
58 | ...IgnoreCase
|
---|
59 | </pre></div>
|
---|
60 |
|
---|
61 | <h4>Examples of Use</h4>
|
---|
62 | <div class="code"><pre>
|
---|
63 | string phrase = "Make your tests fail before passing!"
|
---|
64 |
|
---|
65 | Assert.That( phrase, Is.StringContaining( "tests fail" ) );
|
---|
66 | Assert.That( phrase, Contains.Substring( "tests fail" ) );
|
---|
67 | Assert.That( phrase, Is.Not.StringContaining( "tests pass" ) );
|
---|
68 | Assert.That( phrase, Is.StringContaining( "make" ).IgnoreCase );
|
---|
69 | Expect (phrase, Contains.Substring( "make" ).IgnoreCase );
|
---|
70 | </pre></div>
|
---|
71 |
|
---|
72 | <h4>Notes</h4>
|
---|
73 | <ol>
|
---|
74 | <li><b>ContainsSubstring</b> and <b>Contains</b> may appear only in the
|
---|
75 | body of a constraint expression or when the inherited syntax is used.
|
---|
76 | <li><b>Contains</b> is not actually a string constraint but is converted
|
---|
77 | to one when a string is being tested.
|
---|
78 | </ol>
|
---|
79 |
|
---|
80 | <h3>StartsWithConstraint</h3>
|
---|
81 |
|
---|
82 | <h4>Action</h4>
|
---|
83 | <p>Tests for an initial string.
|
---|
84 |
|
---|
85 | <h4>Constructor</h4>
|
---|
86 | <div class="code"><pre>
|
---|
87 | StartsWithConstraint(string expected)
|
---|
88 | </pre></div>
|
---|
89 |
|
---|
90 | <h4>Syntax</h4>
|
---|
91 | <div class="code"><pre>
|
---|
92 | Is.StringStarting(string expected)
|
---|
93 | StartsWith(string expected)
|
---|
94 | [Obsolete] Text.StartsWith(string expected)
|
---|
95 | [Obsolete] Text.DoesNotStartWith(string expected)
|
---|
96 | </pre></div>
|
---|
97 |
|
---|
98 | <h4>Modifiers</h4>
|
---|
99 | <div class="code"><pre>
|
---|
100 | ...IgnoreCase
|
---|
101 | </pre></div>
|
---|
102 |
|
---|
103 | <h4>Examples of Use</h4>
|
---|
104 | <div class="code"><pre>
|
---|
105 | string phrase = "Make your tests fail before passing!"
|
---|
106 |
|
---|
107 | Assert.That( phrase, Is.StringStarting( "Make" ) );
|
---|
108 | Assert.That( phrase, Is.Not.StringStarting( "Break" ) );
|
---|
109 | Assert.That( phrase, Has.Length.GreaterThan(10)
|
---|
110 | .And.Not.StartsWith( "Break" ) );
|
---|
111 | Expect( phrase, StartsWith( "Make" ) );
|
---|
112 | </pre></div>
|
---|
113 |
|
---|
114 | <h4>Notes</h4>
|
---|
115 | <ol>
|
---|
116 | <li><b>StartsWith</b> may appear only in the body of a constraint
|
---|
117 | expression or when the inherited syntax is used.
|
---|
118 | </ol>
|
---|
119 |
|
---|
120 | <h3>EndsWithConstraint</h3>
|
---|
121 |
|
---|
122 | <h4>Action</h4>
|
---|
123 | <p>Tests for an ending string.
|
---|
124 |
|
---|
125 | <h4>Constructor</h4>
|
---|
126 | <div class="code"><pre>
|
---|
127 | EndsWithConstraint(string expected)
|
---|
128 | </pre></div>
|
---|
129 |
|
---|
130 | <h4>Syntax</h4>
|
---|
131 | <div class="code"><pre>
|
---|
132 | Is.StringEnding(string expected)
|
---|
133 | EndsWith(string expected)
|
---|
134 | [Obsolete] Text.EndsWith(string expected)
|
---|
135 | [Obsolete] Text.DoesNotEndWith(string expected)
|
---|
136 | </pre></div>
|
---|
137 |
|
---|
138 | <h4>Modifiers</h4>
|
---|
139 | <div class="code"><pre>
|
---|
140 | ...IgnoreCase
|
---|
141 | </pre></div>
|
---|
142 |
|
---|
143 | <h4>Examples of Use</h4>
|
---|
144 | <div class="code"><pre>
|
---|
145 | string phrase = "Make your tests fail before passing!"
|
---|
146 |
|
---|
147 | Assert.That( phrase, Is.StringEnding( "!" ) );
|
---|
148 | Assert.That( phrase, Is.StringEnding( "PASSING!" ).IgnoreCase );
|
---|
149 | Expect( phrase, EndsWith( "!" ) );
|
---|
150 | </pre></div>
|
---|
151 |
|
---|
152 | <h4>Notes</h4>
|
---|
153 | <ol>
|
---|
154 | <li><b>EndsWith</b> may appear only in the body of a constraint
|
---|
155 | expression or when the inherited syntax is used.
|
---|
156 | </ol>
|
---|
157 |
|
---|
158 | <h3>RegexConstraint</h3>
|
---|
159 |
|
---|
160 | <h4>Action</h4>
|
---|
161 | <p>Tests that a pattern is matched.
|
---|
162 |
|
---|
163 | <h4>Constructor</h4>
|
---|
164 | <div class="code"><pre>
|
---|
165 | RegexConstraint(string pattern)
|
---|
166 | </pre></div>
|
---|
167 |
|
---|
168 | <h4>Syntax</h4>
|
---|
169 | <div class="code"><pre>
|
---|
170 | Is.StringMatching(string pattern)
|
---|
171 | Matches(string pattern)
|
---|
172 | [Obsolete] Text.Matches(string pattern)
|
---|
173 | [Obsolete] Text.DoesNotMatch(string pattern)
|
---|
174 | </pre></div>
|
---|
175 |
|
---|
176 | <h4>Modifiers</h4>
|
---|
177 | <div class="code"><pre>
|
---|
178 | ...IgnoreCase
|
---|
179 | </pre></div>
|
---|
180 |
|
---|
181 | <h4>Examples of Use</h4>
|
---|
182 | <div class="code"><pre>
|
---|
183 | string phrase = "Make your tests fail before passing!"
|
---|
184 |
|
---|
185 | Assert.That( phrase, Is.StringMatching( "Make.*tests.*pass" ) );
|
---|
186 | Assert.That( phrase, Is.Not.StringMatching( "your.*passing.*tests" ) );
|
---|
187 | Assert.That( phrase, Has.Length.GreaterThan(10)
|
---|
188 | .And.Not.Matches( "your.*passing.*tests" ) );
|
---|
189 | Expect( phrase, Matches( "Make.*pass" ) );
|
---|
190 | </pre></div>
|
---|
191 |
|
---|
192 | <h4>Notes</h4>
|
---|
193 | <ol>
|
---|
194 | <li><b>Matches</b> may appear only in the body of a constraint
|
---|
195 | expression or when the inherited syntax is used.
|
---|
196 | </ol>
|
---|
197 |
|
---|
198 | </div>
|
---|
199 |
|
---|
200 | <!-- Submenu -->
|
---|
201 | <div id="subnav">
|
---|
202 | <ul>
|
---|
203 | <li><a href="index.html">NUnit 2.5.10</a></li>
|
---|
204 | <ul>
|
---|
205 | <li><a href="getStarted.html">Getting Started</a></li>
|
---|
206 | <li><a href="assertions.html">Assertions</a></li>
|
---|
207 | <li><a href="constraintModel.html">Constraints</a></li>
|
---|
208 | <ul>
|
---|
209 | <li><a href="equalConstraint.html">Equal Constraint</a></li>
|
---|
210 | <li><a href="sameasConstraint.html">SameAs Constraint</a></li>
|
---|
211 | <li><a href="conditionConstraints.html">Condition Constraints</a></li>
|
---|
212 | <li><a href="comparisonConstraints.html">Comparison Constrants</a></li>
|
---|
213 | <li><a href="pathConstraints.html">Path Constraints</a></li>
|
---|
214 | <li><a href="typeConstraints.html">Type Constraints</a></li>
|
---|
215 | <li id="current"><a href="stringConstraints.html">String Constraints</a></li>
|
---|
216 | <li><a href="collectionConstraints.html">Collection Constraints</a></li>
|
---|
217 | <li><a href="propertyConstraint.html">Property Constraint</a></li>
|
---|
218 | <li><a href="throwsConstraint.html">Throws Constraint</a></li>
|
---|
219 | <li><a href="compoundConstraints.html">Compound Constraints</a></li>
|
---|
220 | <li><a href="delayedConstraint.html">Delayed Constraint</a></li>
|
---|
221 | <li><a href="listMapper.html">List Mapper</a></li>
|
---|
222 | <li><a href="reusableConstraint.html">Reusable Constraint</a></li>
|
---|
223 | </ul>
|
---|
224 | <li><a href="attributes.html">Attributes</a></li>
|
---|
225 | <li><a href="runningTests.html">Running Tests</a></li>
|
---|
226 | <li><a href="extensibility.html">Extensibility</a></li>
|
---|
227 | <li><a href="releaseNotes.html">Release Notes</a></li>
|
---|
228 | <li><a href="samples.html">Samples</a></li>
|
---|
229 | <li><a href="license.html">License</a></li>
|
---|
230 | </ul>
|
---|
231 | </ul>
|
---|
232 | </div>
|
---|
233 | <!-- End of Submenu -->
|
---|
234 |
|
---|
235 |
|
---|
236 | <!-- Standard Footer for NUnit.org -->
|
---|
237 | <div id="footer">
|
---|
238 | Copyright © 2010 Charlie Poole. All Rights Reserved.
|
---|
239 | </div>
|
---|
240 | <!-- End of Footer -->
|
---|
241 |
|
---|
242 | </body>
|
---|
243 | </html>
|
---|