You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
ikvm-native
libgc
llvm
m4
man
mcs
build
class
docs
errors
ilasm
jay
mcs
nunit24
ClientUtilities
ConsoleRunner
NUnitCore
NUnitExtensions
NUnitFramework
framework
Constraints
BinaryOperations.cs
CollectionConstraints.cs
ComparisonConstraints.cs
Constraint.cs
ConstraintBuilder.cs
ContainsConstraint.cs
EmptyConstraint.cs
EqualConstraint.cs
Numerics.cs
PrefixConstraints.cs
PropertyConstraint.cs
SameAsConstraint.cs
StringConstraints.cs
TypeConstraints.cs
SyntaxHelpers
AbstractAsserter.cs
AssemblyInfo.cs
Assert.cs.REMOVED.git-id
Assertion.cs
AssertionException.cs
AssertionFailureMessage.cs
AssertionHelper.cs
CategoryAttribute.cs
CollectionAssert.cs
DescriptionAttribute.cs
ExpectedExceptionAttribute.cs
ExplicitAttribute.cs
FileAssert.cs
GlobalSettings.cs
IAsserter.cs
IExpectException.cs
IgnoreAttribute.cs
IgnoreException.cs
IncludeExcludeAttributes.cs
Makefile
MessageWriter.cs
MsgUtils.cs
NUnit.Framework.dll.sources
OldTestCase.cs
PropertyAttribute.cs
SetCultureAttribute.cs
SetUpAttribute.cs
SetUpFixtureAttribute.cs
StringAssert.cs
SuiteAttribute.cs
TearDownAttribute.cs
TestAttribute.cs
TestFixtureAttribute.cs
TestFixtureSetUpAttribute.cs
TestFixtureTearDownAttribute.cs
TextMessageWriter.cs
nunit.framework.dll.csproj
nunit.framework.dll_VS2005.csproj
NUnitMocks
CommonAssemblyInfo.cs
Makefile
license.rtf
nunit.sln
nunit.snk
nunit_VS2005.sln
packages
tests
tools
AUTHORS
COPYING
INSTALL.txt
Makefile
MonoIcon.png
README
ScalableMonoIcon.svg
mkinstalldirs
mk
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
235 lines
7.9 KiB
C#
235 lines
7.9 KiB
C#
![]() |
// ****************************************************************
|
||
|
// Copyright 2007, Charlie Poole
|
||
|
// This is free software licensed under the NUnit license. You may
|
||
|
// obtain a copy of the license at http://nunit.org/?p=license&r=2.4
|
||
|
// ****************************************************************
|
||
|
|
||
|
using System;
|
||
|
using System.Text.RegularExpressions;
|
||
|
|
||
|
namespace NUnit.Framework.Constraints
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// EmptyStringConstraint tests whether a string is empty.
|
||
|
/// </summary>
|
||
|
public class EmptyStringConstraint : EmptyConstraint
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Test whether the constraint is satisfied by a given value
|
||
|
/// </summary>
|
||
|
/// <param name="actual">The value to be tested</param>
|
||
|
/// <returns>True for success, false for failure</returns>
|
||
|
public override bool Matches(object actual)
|
||
|
{
|
||
|
this.actual = actual;
|
||
|
|
||
|
if ( !(actual is string) )
|
||
|
return false;
|
||
|
|
||
|
return (string)actual == string.Empty;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Write the constraint description to a MessageWriter
|
||
|
/// </summary>
|
||
|
/// <param name="writer">The writer on which the description is displayed</param>
|
||
|
public override void WriteDescriptionTo(MessageWriter writer)
|
||
|
{
|
||
|
writer.Write( "<empty>" );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// SubstringConstraint can test whether a string contains
|
||
|
/// the expected substring.
|
||
|
/// </summary>
|
||
|
public class SubstringConstraint : Constraint
|
||
|
{
|
||
|
string expected;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Initializes a new instance of the <see cref="T:SubstringConstraint"/> class.
|
||
|
/// </summary>
|
||
|
/// <param name="expected">The expected.</param>
|
||
|
public SubstringConstraint(string expected)
|
||
|
{
|
||
|
this.expected = expected;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Test whether the constraint is satisfied by a given value
|
||
|
/// </summary>
|
||
|
/// <param name="actual">The value to be tested</param>
|
||
|
/// <returns>True for success, false for failure</returns>
|
||
|
public override bool Matches(object actual)
|
||
|
{
|
||
|
this.actual = actual;
|
||
|
|
||
|
if ( !(actual is string) )
|
||
|
return false;
|
||
|
|
||
|
if (this.caseInsensitive)
|
||
|
return ((string)actual).ToLower().IndexOf(expected.ToLower()) >= 0;
|
||
|
else
|
||
|
return ((string)actual).IndexOf(expected) >= 0;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Write the constraint description to a MessageWriter
|
||
|
/// </summary>
|
||
|
/// <param name="writer">The writer on which the description is displayed</param>
|
||
|
public override void WriteDescriptionTo(MessageWriter writer)
|
||
|
{
|
||
|
writer.WritePredicate("String containing");
|
||
|
writer.WriteExpectedValue(expected);
|
||
|
if ( this.caseInsensitive )
|
||
|
writer.WriteModifier( "ignoring case" );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// StartsWithConstraint can test whether a string starts
|
||
|
/// with an expected substring.
|
||
|
/// </summary>
|
||
|
public class StartsWithConstraint : Constraint
|
||
|
{
|
||
|
private string expected;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Initializes a new instance of the <see cref="T:StartsWithConstraint"/> class.
|
||
|
/// </summary>
|
||
|
/// <param name="expected">The expected string</param>
|
||
|
public StartsWithConstraint(string expected)
|
||
|
{
|
||
|
this.expected = expected;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Test whether the constraint is matched by the actual value.
|
||
|
/// This is a template method, which calls the IsMatch method
|
||
|
/// of the derived class.
|
||
|
/// </summary>
|
||
|
/// <param name="actual"></param>
|
||
|
/// <returns></returns>
|
||
|
public override bool Matches(object actual)
|
||
|
{
|
||
|
this.actual = actual;
|
||
|
|
||
|
if (!(actual is string))
|
||
|
return false;
|
||
|
|
||
|
if ( this.caseInsensitive )
|
||
|
return ((string)actual).ToLower().StartsWith(expected.ToLower());
|
||
|
else
|
||
|
return ((string)actual).StartsWith(expected);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Write the constraint description to a MessageWriter
|
||
|
/// </summary>
|
||
|
/// <param name="writer">The writer on which the description is displayed</param>
|
||
|
public override void WriteDescriptionTo(MessageWriter writer)
|
||
|
{
|
||
|
writer.WritePredicate("String starting with");
|
||
|
writer.WriteExpectedValue( MsgUtils.ClipString(expected, writer.MaxLineLength - 40, 0) );
|
||
|
if ( this.caseInsensitive )
|
||
|
writer.WriteModifier( "ignoring case" );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// EndsWithConstraint can test whether a string ends
|
||
|
/// with an expected substring.
|
||
|
/// </summary>
|
||
|
public class EndsWithConstraint : Constraint
|
||
|
{
|
||
|
private string expected;
|
||
|
/// <summary>
|
||
|
/// Initializes a new instance of the <see cref="T:EndsWithConstraint"/> class.
|
||
|
/// </summary>
|
||
|
/// <param name="expected">The expected string</param>
|
||
|
public EndsWithConstraint(string expected)
|
||
|
{
|
||
|
this.expected = expected;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Test whether the constraint is matched by the actual value.
|
||
|
/// This is a template method, which calls the IsMatch method
|
||
|
/// of the derived class.
|
||
|
/// </summary>
|
||
|
/// <param name="actual"></param>
|
||
|
/// <returns></returns>
|
||
|
public override bool Matches(object actual)
|
||
|
{
|
||
|
this.actual = actual;
|
||
|
|
||
|
if (!(actual is string))
|
||
|
return false;
|
||
|
|
||
|
if ( this.caseInsensitive )
|
||
|
return ((string)actual).ToLower().EndsWith(expected.ToLower());
|
||
|
else
|
||
|
return ((string)actual).EndsWith(expected);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Write the constraint description to a MessageWriter
|
||
|
/// </summary>
|
||
|
/// <param name="writer">The writer on which the description is displayed</param>
|
||
|
public override void WriteDescriptionTo(MessageWriter writer)
|
||
|
{
|
||
|
writer.WritePredicate("String ending with");
|
||
|
writer.WriteExpectedValue(expected);
|
||
|
if ( this.caseInsensitive )
|
||
|
writer.WriteModifier( "ignoring case" );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// RegexConstraint can test whether a string matches
|
||
|
/// the pattern provided.
|
||
|
/// </summary>
|
||
|
public class RegexConstraint : Constraint
|
||
|
{
|
||
|
string pattern;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Initializes a new instance of the <see cref="T:RegexConstraint"/> class.
|
||
|
/// </summary>
|
||
|
/// <param name="pattern">The pattern.</param>
|
||
|
public RegexConstraint(string pattern)
|
||
|
{
|
||
|
this.pattern = pattern;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Test whether the constraint is satisfied by a given value
|
||
|
/// </summary>
|
||
|
/// <param name="actual">The value to be tested</param>
|
||
|
/// <returns>True for success, false for failure</returns>
|
||
|
public override bool Matches(object actual)
|
||
|
{
|
||
|
this.actual = actual;
|
||
|
|
||
|
return actual is string &&
|
||
|
Regex.IsMatch(
|
||
|
(string)actual,
|
||
|
this.pattern,
|
||
|
this.caseInsensitive ? RegexOptions.IgnoreCase : RegexOptions.None );
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Write the constraint description to a MessageWriter
|
||
|
/// </summary>
|
||
|
/// <param name="writer">The writer on which the description is displayed</param>
|
||
|
public override void WriteDescriptionTo(MessageWriter writer)
|
||
|
{
|
||
|
writer.WritePredicate("String matching");
|
||
|
writer.WriteExpectedValue(this.pattern);
|
||
|
if ( this.caseInsensitive )
|
||
|
writer.WriteModifier( "ignoring case" );
|
||
|
}
|
||
|
}
|
||
|
}
|