Add additional unit tests for RegEx
This commit is contained in:
parent
83b916bb00
commit
b7de8e2c29
1 changed files with 42 additions and 0 deletions
|
@ -184,6 +184,48 @@ TEST_CASE("[RegEx] Empty pattern") {
|
|||
CHECK(re.is_valid());
|
||||
}
|
||||
|
||||
TEST_CASE("[RegEx] Complex Grouping") {
|
||||
const String test = "https://docs.godotengine.org/en/latest/contributing/";
|
||||
|
||||
// Ignored protocol in grouping.
|
||||
RegEx re("^(?:https?://)([a-zA-Z]{2,4})\\.([a-zA-Z][a-zA-Z0-9_\\-]{2,64})\\.([a-zA-Z]{2,4})");
|
||||
REQUIRE(re.is_valid());
|
||||
Ref<RegExMatch> expr = re.search(test);
|
||||
|
||||
CHECK(expr->get_group_count() == 3);
|
||||
|
||||
CHECK(expr->get_string(0) == "https://docs.godotengine.org");
|
||||
|
||||
CHECK(expr->get_string(1) == "docs");
|
||||
CHECK(expr->get_string(2) == "godotengine");
|
||||
CHECK(expr->get_string(3) == "org");
|
||||
}
|
||||
|
||||
TEST_CASE("[RegEx] Number Expression") {
|
||||
const String test = "(2.5e-3 + 35 + 46) / 2.8e0 = 28.9294642857";
|
||||
|
||||
// Not an exact regex for number but a good test.
|
||||
RegEx re("([+-]?\\d+)(\\.\\d+([eE][+-]?\\d+)?)?");
|
||||
REQUIRE(re.is_valid());
|
||||
Array number_match = re.search_all(test);
|
||||
|
||||
CHECK(number_match.size() == 5);
|
||||
|
||||
Ref<RegExMatch> number = number_match[0];
|
||||
CHECK(number->get_string(0) == "2.5e-3");
|
||||
CHECK(number->get_string(1) == "2");
|
||||
number = number_match[1];
|
||||
CHECK(number->get_string(0) == "35");
|
||||
number = number_match[2];
|
||||
CHECK(number->get_string(0) == "46");
|
||||
number = number_match[3];
|
||||
CHECK(number->get_string(0) == "2.8e0");
|
||||
number = number_match[4];
|
||||
CHECK(number->get_string(0) == "28.9294642857");
|
||||
CHECK(number->get_string(1) == "28");
|
||||
CHECK(number->get_string(2) == ".9294642857");
|
||||
}
|
||||
|
||||
TEST_CASE("[RegEx] Invalid end position") {
|
||||
const String s = "Godot";
|
||||
|
||||
|
|
Loading…
Reference in a new issue