xtd 0.2.0
Loading...
Searching...
No Matches
xtd::tunit::string_assume Class Referencefinal
Inheritance diagram for xtd::tunit::string_assume:
xtd::tunit::base_assert

Definition

The string_assume class contains a collection of static methods that implement the most string assertions used in xtd::tUnit.

Namespace
xtd::tunit
Library
xtd.tunit
Remarks
Assumptions are intended to express the state a test must be in to provide a meaningful result. They are functionally similar to assertions, however a unmet assumption will produce an aborted test result, as opposed to a failure.
Examples
This example show how to used some methods :
#include <xtd/xtd.tunit>
using namespace xtd::io;
using namespace xtd::tunit;
namespace unit_tests {
// The class test must be declared with test_class_ helper.
class test_class_(test) {
void test_method_(test_case1) {
auto s = "A string value";
string_assume::are_equal_ignoring_case("A STRING VALUE", s);
}
void test_method_(test_case2) {
auto s = "A string value";
string_assume::contains("item", s);
}
void test_method_(test_case3) {
auto s = "A string value";
string_assume::matches("item$", s);
}
};
}
auto main() -> int {
return console_unit_test().run();
}
// This code can produce the following output :
//
// Start 3 tests from 1 test case
// Run tests:
// SUCCEED unit_tests::test.test_case1 (0 ms total)
// ABORTED test.test_case2 (0 ms total)
// Test aborted
// Expected: string containing "item"
// But was: "A string value"
// Stack Trace: in |---OMITTED---|/string_assume.cpp:17
// ABORTED test.test_case3 (0 ms total)
// Test aborted
// Expected: string matching "item$"
// But was: "A string value"
// Stack Trace: in |---OMITTED---|/string_assume.cpp:22
//
// Test results:
// SUCCEED 1 test.
// ABORTED 2 tests.
// End 3 tests from 1 test case ran. (0 ms total)
The console_unit_test class is console unit test interface.
Definition console_unit_test.hpp:23
int32 run() noexcept
Runs all tests in this unit_test object and prints the result.
#define test_method_(method_name)
Add test method to class test.
Definition test_method_attribute.hpp:73
@ s
The S key.
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:16
The tunit namespace contains a unit test library.
Definition abort_error.hpp:10

Public Static Methods

static void are_equal_ignoring_case (const xtd::string &expected, const xtd::string &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that two type are equal ignoring case.
 
static void are_equal_ignoring_case (const xtd::string &expected, const xtd::string &actual, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that two type are equal ignoring case.
 
static void are_not_equal_ignoring_case (const xtd::string &expected, const xtd::string &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that two type are not equal ignoring case.
 
static void are_not_equal_ignoring_case (const xtd::string &expected, const xtd::string &actual, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that two type are not equal ignoring case.
 
static void contains (const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string contains an item.
 
static void contains (const xtd::string &item, const xtd::string &string, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string contains an item.
 
static void does_not_contain (const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string contains an item.
 
static void does_not_contain (const xtd::string &item, const xtd::string &string, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string contains an item.
 
static void does_not_end_with (const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string starts with item.
 
static void does_not_end_with (const xtd::string &item, const xtd::string &string, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string starts with item.
 
static void does_not_match (const xtd::string &regex_pattern, const xtd::string &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that does not match regex pattern.
 
static void does_not_match (const xtd::string &regex_pattern, const xtd::string &actual, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that does not match regex pattern.
 
static void does_not_start_with (const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string starts with item.
 
static void does_not_start_with (const xtd::string &item, const xtd::string &string, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string starts with item.
 
static void ends_with (const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string starts with item.
 
static void ends_with (const xtd::string &item, const xtd::string &string, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string starts with item.
 
static void matches (const xtd::string &regex_pattern, const xtd::string &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that matches regex pattern.
 
static void matches (const xtd::string &regex_pattern, const xtd::string &actual, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that matches regex pattern.
 
static void starts_with (const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string starts with item.
 
static void starts_with (const xtd::string &item, const xtd::string &string, const xtd::string &message, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
 Validates that string starts with item.
 

Member Function Documentation

◆ are_equal_ignoring_case() [1/2]

static void xtd::tunit::string_assume::are_equal_ignoring_case ( const xtd::string expected,
const xtd::string actual,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that two type are equal ignoring case.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::tunit::string_assume::are_equal_ignoring_case("key", xtd::string("VALUE")); // test throws an abort_error exception.
Represents text as a sequence of character units.
Definition basic_string.hpp:79
static void are_equal_ignoring_case(const xtd::string &expected, const xtd::string &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that two type are equal ignoring case.

◆ are_equal_ignoring_case() [2/2]

static void xtd::tunit::string_assume::are_equal_ignoring_case ( const xtd::string expected,
const xtd::string actual,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that two type are equal ignoring case.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::tunit::string_assume::are_equal_ignoring_case("value", xtd::string("VALUE"), "User message..."); // test ok.
xtd::tunit::string_assume::are_equal_ignoring_case("key", xtd::string("VALUE"), "User message..."); // test throws an abort_error exception.

◆ are_not_equal_ignoring_case() [1/2]

static void xtd::tunit::string_assume::are_not_equal_ignoring_case ( const xtd::string expected,
const xtd::string actual,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that two type are not equal ignoring case.

Parameters
expectedthe expected value.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::tunit::string_assume::are_not_equal_ignoring_case("value", xtd::string("VALUE")); // test throws an abort_error exception.
static void are_not_equal_ignoring_case(const xtd::string &expected, const xtd::string &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that two type are not equal ignoring case.

◆ are_not_equal_ignoring_case() [2/2]

static void xtd::tunit::string_assume::are_not_equal_ignoring_case ( const xtd::string expected,
const xtd::string actual,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that two type are not equal ignoring case.

Parameters
expectedthe expected value.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::tunit::string_assume::are_not_equal_ignoring_case("key", xtd::string("VALUE"), "User message..."); // test ok.
xtd::tunit::string_assume::are_not_equal_ignoring_case("value", xtd::string("VALUE"), "User message..."); // test throws an abort_error exception.

◆ contains() [1/2]

static void xtd::tunit::string_assume::contains ( const xtd::string item,
const xtd::string string,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string contains an item.

Parameters
itemobject to verify.
collectionthat contains object.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::contains("z", s); // test throws an abort_error exception.
static void contains(const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that string contains an item.

◆ contains() [2/2]

static void xtd::tunit::string_assume::contains ( const xtd::string item,
const xtd::string string,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string contains an item.

Parameters
itemobject to verify.
collectionthat contains object.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::contains("a", s, "User message..."); // test ok.
xtd::tunit::string_assume::contains("z", s, "User message..."); // test throws an abort_error exception.

◆ does_not_contain() [1/2]

static void xtd::tunit::string_assume::does_not_contain ( const xtd::string item,
const xtd::string string,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string contains an item.

Parameters
itemobject to verify.
collectionthat contains object.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::contains("z", s); // test throws an abort_error exception.

◆ does_not_contain() [2/2]

static void xtd::tunit::string_assume::does_not_contain ( const xtd::string item,
const xtd::string string,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string contains an item.

Parameters
itemobject to verify.
collectionthat contains object.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::contains("a", s, "User message..."); // test ok.
xtd::tunit::string_assume::contains("z", s, "User message..."); // test throws an abort_error exception.

◆ does_not_end_with() [1/2]

static void xtd::tunit::string_assume::does_not_end_with ( const xtd::string item,
const xtd::string string,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string starts with item.

Parameters
itemobject to verify.
collectionthat contains object.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::does_not_end_with("lue", s); // test throws an abort_error exception.
static void does_not_end_with(const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that string starts with item.

◆ does_not_end_with() [2/2]

static void xtd::tunit::string_assume::does_not_end_with ( const xtd::string item,
const xtd::string string,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string starts with item.

Parameters
itemobject to verify.
collectionthat contains object.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::does_not_end_with("law", s, "User message..."); // test ok.
xtd::tunit::string_assume::does_not_end_with("lue", s, "User message..."); // test throws an abort_error exception.

◆ does_not_match() [1/2]

static void xtd::tunit::string_assume::does_not_match ( const xtd::string regex_pattern,
const xtd::string actual,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that does not match regex pattern.

Parameters
regex_patternthe regex pattern.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::tunit::string_assume::does_not_match("^Salut", xtd::string("Hello, World!")); // test ok.
xtd::tunit::string_assume::does_not_match("^Hello", xtd::string("Hello, World!")); // test throws an abort_error exception.
static void does_not_match(const xtd::string &regex_pattern, const xtd::string &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that does not match regex pattern.

◆ does_not_match() [2/2]

static void xtd::tunit::string_assume::does_not_match ( const xtd::string regex_pattern,
const xtd::string actual,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that does not match regex pattern.

Parameters
regex_patternthe regex pattern.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::tunit::string_assume::does_not_match("^Salut", "Hello, World!", xtd::string("User message...")); // test ok.
xtd::tunit::string_assume::does_not_match("^Hello", "Hello, World!", xtd::string("User message...")); // test throws an abort_error exception.

◆ does_not_start_with() [1/2]

static void xtd::tunit::string_assume::does_not_start_with ( const xtd::string item,
const xtd::string string,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string starts with item.

Parameters
itemobject to verify.
collectionthat contains object.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::does_not_start_with("val", s); // test throws an abort_error exception.
static void does_not_start_with(const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that string starts with item.

◆ does_not_start_with() [2/2]

static void xtd::tunit::string_assume::does_not_start_with ( const xtd::string item,
const xtd::string string,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string starts with item.

Parameters
itemobject to verify.
collectionthat contains object.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::does_not_start_with("zoe", s, "User message..."); // test ok.
xtd::tunit::string_assume::does_not_start_with("val", s, "User message..."); // test throws an abort_error exception.

◆ ends_with() [1/2]

static void xtd::tunit::string_assume::ends_with ( const xtd::string item,
const xtd::string string,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string starts with item.

Parameters
itemobject to verify.
collectionthat contains object.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::ends_with("law", s); // test throws an abort_error exception.
static void ends_with(const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that string starts with item.

◆ ends_with() [2/2]

static void xtd::tunit::string_assume::ends_with ( const xtd::string item,
const xtd::string string,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string starts with item.

Parameters
itemobject to verify.
collectionthat contains object.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::ends_with("lue", s, "User message..."); // test ok.
xtd::tunit::string_assume::ends_with("law", s, "User message..."); // test throws an abort_error exception.

◆ matches() [1/2]

static void xtd::tunit::string_assume::matches ( const xtd::string regex_pattern,
const xtd::string actual,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that matches regex pattern.

Parameters
regex_patternthe regex pattern.
actualthe actual value.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::tunit::string_assume::matches("^Hello", xtd::string("Hello, World!")); // test ok.
xtd::tunit::string_assume::matches("^Salut", xtd::string("Hello, World!")); // test throws an abort_error exception.
static void matches(const xtd::string &regex_pattern, const xtd::string &actual, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that matches regex pattern.

◆ matches() [2/2]

static void xtd::tunit::string_assume::matches ( const xtd::string regex_pattern,
const xtd::string actual,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that matches regex pattern.

Parameters
regex_patternthe regex pattern.
actualthe actual value.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::tunit::string_assume::matches("^Hello", "Hello, World!", xtd::string("User message...")); // test ok.
xtd::tunit::string_assume::matches("^Salut", "Hello, World!", xtd::string("User message...")); // test throws an abort_error exception.

◆ starts_with() [1/2]

static void xtd::tunit::string_assume::starts_with ( const xtd::string item,
const xtd::string string,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string starts with item.

Parameters
itemobject to verify.
collectionthat contains object.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::starts_with("zoe", s); // test throws an abort_error exception.
static void starts_with(const xtd::string &item, const xtd::string &string, const xtd::diagnostics::stack_frame &stack_frame=xtd::diagnostics::stack_frame::current())
Validates that string starts with item.

◆ starts_with() [2/2]

static void xtd::tunit::string_assume::starts_with ( const xtd::string item,
const xtd::string string,
const xtd::string message,
const xtd::diagnostics::stack_frame stack_frame = xtd::diagnostics::stack_frame::current() 
)
static

Validates that string starts with item.

Parameters
itemobject to verify.
collectionthat contains object.
messageA user message to display if the assertion fails. This message can be seen in the unit test results.
stack_frameContains information about current file and current line.
Exceptions
xtd::tunit::abort_errorIf bad assertion.
Examples
xtd::string s = "value";
xtd::tunit::string_assume::starts_with("val", s, "User message..."); // test ok.
xtd::tunit::string_assume::starts_with("zoe", s, "User message..."); // test throws an abort_error exception.

The documentation for this class was generated from the following file: