Char
Describes the possible expectations for char values.
| Expectation | Negated | Summary |
|---|---|---|
IsEqualTo | IsNotEqualTo | equal to the expected character |
IsOneOf | IsNotOneOf | equal to one of the expected characters |
IsAnAsciiLetter | IsNotAnAsciiLetter | an ASCII letter |
IsAnAsciiDigit | IsNotAnAsciiDigit | an ASCII digit |
IsAnAsciiHexDigit | IsNotAnAsciiHexDigit | an ASCII hexadecimal digit |
IsALetter | IsNotALetter | a Unicode letter |
IsADigit | IsNotADigit | a decimal digit |
IsANumber | IsNotANumber | a Unicode number |
IsUpperCased | IsNotUpperCased | an upper-case letter |
IsLowerCased | IsNotLowerCased | a lower-case letter |
IsAControlCharacter | IsNotAControlCharacter | a control character |
IsWhiteSpace | IsNotWhiteSpace | whitespace |
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:
| Expectation | Method |
|---|---|
IsAnAsciiLetter | char.IsAsciiLetter |
IsAnAsciiDigit | char.IsAsciiDigit |
IsAnAsciiHexDigit | char.IsAsciiHexDigit |
IsALetter | char.IsLetter |
IsADigit | char.IsDigit |
IsANumber | char.IsNumber |
IsUpperCased | char.IsUpper |
IsLowerCased | char.IsLower |
IsAControlCharacter | char.IsControl |
IsWhiteSpace | char.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.