Skip to main content

Char

Describes the possible expectations for char values.

ExpectationNegatedSummary
IsEqualToIsNotEqualToequal to the expected character
IsOneOfIsNotOneOfequal to one of the expected characters
IsAnAsciiLetterIsNotAnAsciiLetteran ASCII letter
IsAnAsciiDigitIsNotAnAsciiDigitan ASCII digit
IsAnAsciiHexDigitIsNotAnAsciiHexDigitan ASCII hexadecimal digit
IsALetterIsNotALettera Unicode letter
IsADigitIsNotADigita decimal digit
IsANumberIsNotANumbera Unicode number
IsUpperCasedIsNotUpperCasedan upper-case letter
IsLowerCasedIsNotLowerCaseda lower-case letter
IsAControlCharacterIsNotAControlCharactera control character
IsWhiteSpaceIsNotWhiteSpacewhitespace

Equality​

You can verify that the char is equal to another one or not:

char initial = 'a';

await Expect.That(initial).IsEqualTo('a');
await Expect.That(initial).IsNotEqualTo('b');
await Expect.That(initial).IsEqualTo('A').IgnoringCase();

IgnoringCase() compares the characters the same way as strings with IgnoringCase(), i.e. with StringComparison.OrdinalIgnoreCase.

One of​

You can verify that the char is one of many alternatives:

char initial = 'a';

await Expect.That(initial).IsOneOf('a', 'b', 'c');
await Expect.That(initial).IsNotOneOf('x', 'y', 'z');
await Expect.That(initial).IsOneOf('A', 'B', 'C').IgnoringCase();

Categories​

You can verify the category of the char, or that it does not belong to it:

await Expect.That('a').IsAnAsciiLetter();
await Expect.That('乐').IsALetter();
await Expect.That('3').IsADigit();
await Expect.That('½').IsANumber().And.IsNotADigit();
await Expect.That('A').IsUpperCased();
await Expect.That('\t').IsWhiteSpace().And.IsAControlCharacter();
await Expect.That(' ').IsNotAControlCharacter();

Each expectation follows the corresponding method of char:

ExpectationMethod
IsAnAsciiLetterchar.IsAsciiLetter
IsAnAsciiDigitchar.IsAsciiDigit
IsAnAsciiHexDigitchar.IsAsciiHexDigit
IsALetterchar.IsLetter
IsADigitchar.IsDigit
IsANumberchar.IsNumber
IsUpperCasedchar.IsUpper
IsLowerCasedchar.IsLower
IsAControlCharacterchar.IsControl
IsWhiteSpacechar.IsWhiteSpace

IsADigit only accepts decimal digits, while IsANumber also accepts characters like '½'.

IsUpperCased and IsLowerCased differ from the string casing expectations, which only look at cased letters: '1' is neither upper-cased nor lower-cased, while "1" is both.