|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | + Module: Unit tests for parsing generic classes |
| 4 | +
|
| 5 | + Author: Diffblue Limited |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +#include <java_bytecode/load_method_by_regex.h> |
| 10 | +#include <testing-utils/catch.hpp> |
| 11 | + |
| 12 | +class load_method_by_regex_testt |
| 13 | +{ |
| 14 | +public: |
| 15 | + static bool does_pattern_miss_descriptor(const std::string &pattern) |
| 16 | + { |
| 17 | + return load_method_by_regext::does_pattern_miss_descriptor(pattern); |
| 18 | + } |
| 19 | +}; |
| 20 | + |
| 21 | +SCENARIO( |
| 22 | + "load_method_by_regex::does_pattern_miss_descriptor", |
| 23 | + "[core][java_bytecode][load_method_by_regex]") |
| 24 | +{ |
| 25 | + GIVEN("A string with a java prefix and no descriptor") |
| 26 | + { |
| 27 | + const std::string pattern = "java::com.diffblue.ClassName.methodName"; |
| 28 | + WHEN("When calling does_pattern_miss_descriptor") |
| 29 | + { |
| 30 | + bool result = |
| 31 | + load_method_by_regex_testt::does_pattern_miss_descriptor(pattern); |
| 32 | + THEN("It should miss discriptor") |
| 33 | + { |
| 34 | + REQUIRE(result); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + GIVEN("A string with a java prefix and a descriptor") |
| 39 | + { |
| 40 | + const std::string pattern = "java::com.diffblue.ClassName.methodName:()V"; |
| 41 | + WHEN("When calling does_pattern_miss_descriptor") |
| 42 | + { |
| 43 | + bool result = |
| 44 | + load_method_by_regex_testt::does_pattern_miss_descriptor(pattern); |
| 45 | + THEN("It should have the discriptor") |
| 46 | + { |
| 47 | + REQUIRE_FALSE(result); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + GIVEN("A string without a java prefix and without a descriptor") |
| 52 | + { |
| 53 | + const std::string pattern = "com.diffblue.ClassName.methodName"; |
| 54 | + WHEN("When calling does_pattern_miss_descriptor") |
| 55 | + { |
| 56 | + bool result = |
| 57 | + load_method_by_regex_testt::does_pattern_miss_descriptor(pattern); |
| 58 | + THEN("It should miss discriptor") |
| 59 | + { |
| 60 | + REQUIRE(result); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + GIVEN("A string without a java prefix and with a descriptor") |
| 65 | + { |
| 66 | + const std::string pattern = "com.diffblue.ClassName.methodName:()V"; |
| 67 | + WHEN("When calling does_pattern_miss_descriptor") |
| 68 | + { |
| 69 | + bool result = |
| 70 | + load_method_by_regex_testt::does_pattern_miss_descriptor(pattern); |
| 71 | + THEN("It should have the discriptor") |
| 72 | + { |
| 73 | + REQUIRE_FALSE(result); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + GIVEN("A string with an almost java prefix and no descriptor") |
| 78 | + { |
| 79 | + const std::string pattern = "java:com.diffblue.ClassName.methodName"; |
| 80 | + WHEN("When calling does_pattern_miss_descriptor") |
| 81 | + { |
| 82 | + bool result = |
| 83 | + load_method_by_regex_testt::does_pattern_miss_descriptor(pattern); |
| 84 | + THEN("It should classify the last : as a descriptor") |
| 85 | + { |
| 86 | + REQUIRE_FALSE(result); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + GIVEN("A string with an almost java prefix and with a descriptor") |
| 91 | + { |
| 92 | + const std::string pattern = "java:com.diffblue.ClassName.methodName:()V"; |
| 93 | + WHEN("When calling does_pattern_miss_descriptor") |
| 94 | + { |
| 95 | + bool result = |
| 96 | + load_method_by_regex_testt::does_pattern_miss_descriptor(pattern); |
| 97 | + THEN("It should have the discriptor") |
| 98 | + { |
| 99 | + REQUIRE_FALSE(result); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments