| 11 | }; |
| 12 | |
| 13 | int main() { |
| 14 | std::vector<TestCase> test_cases = { |
| 15 | {"color:red;font-size:12px;", 2, {{"color", "red"}, {"font-size", "12px"}}}, //1 |
| 16 | {" color : red ; font-size : 12px ; ", 2, {{"color", "red"}, {"font-size", "12px"}}},//2 |
| 17 | {"color:red;", 1, {{"color", "red"}}},//3 |
| 18 | {"color:red;;;font-weight:bold;", 2, {{"color", "red"}, {"font-weight", "bold"}}},//4 |
| 19 | {"color:red; ; ;", 1, {{"color", "red"}}},//5 |
| 20 | {"color:red; font-size:12px", 2, {{"color", "red"}, {"font-size", "12px"}}},//6 |
| 21 | {"margin:10px", 1, {{"margin", "10px"}}},//7 |
| 22 | {"color:; font-weight:bold;", 1, {{"font-weight", "bold"}}},//8 |
| 23 | {":red; color:blue;", 1, {{"color", "blue"}}},//9 |
| 24 | {"color red; font-size:12px;", 1, {{"font-size", "12px"}}}, //10 |
| 25 | {"border: 1px solid red; margin: 10px 20px;", 2, {{"border", "1px solid red"}, {"margin", "10px 20px"}}},//11 |
| 26 | {"COLOR:RED; Font-Size:12Px;", 2, {{"color", "red"}, {"font-size", "12px"}}},//12 |
| 27 | {"background-image: url(http://a.com/b;c.png); color: blue;", 2, {{"background-image", "url(http://a.com/b;c.png)"}, {"color", "blue"}}},//13 |
| 28 | {"list-style: url('data:image/png;base64,123');", 1, {{"list-style", "url('data:image/png;base64,123')"}}} //14 |
| 29 | }; |
| 30 | |
| 31 | std::vector<int> passed_indices; |
| 32 | std::vector<int> failed_indices; |
| 33 | |
| 34 | for (size_t i = 0; i < test_cases.size(); ++i) { |
| 35 | const auto& test = test_cases[i]; |
| 36 | std::cout << "--- TEST CASE (" << i + 1 << ") ---" << std::endl; |
| 37 | std::cout << "Input: " << test.input << std::endl; |
| 38 | |
| 39 | auto result = parse_inline_style(test.input); |
| 40 | bool is_correct = true; |
| 41 | |
| 42 | // 1. Check total count |
| 43 | if (result.size() != test.expected_count) { |
| 44 | std::cerr << "[FAIL] Count mismatch. Got: " << result.size() << ", Expected: " << test.expected_count << std::endl; |
| 45 | is_correct = false; |
| 46 | } |
| 47 | |
| 48 | // 2. Check each expected value |
| 49 | for (const auto& [expected_name, expected_val] : test.expected_values) { |
| 50 | if (result.find(expected_name) == result.end()) { |
| 51 | std::cerr << "[FAIL] Missing property: " << expected_name << std::endl; |
| 52 | is_correct = false; |
| 53 | } else if (result[expected_name] != expected_val) { |
| 54 | std::cerr << "[FAIL] Value mismatch for '" << expected_name << "'. Got: '" << result[expected_name] << "', Expected: '" << expected_val << "'" << std::endl; |
| 55 | is_correct = false; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if (is_correct) { |
| 60 | std::cout << "[SUCCESS] All properties matched." << std::endl; |
| 61 | passed_indices.push_back(i + 1); |
| 62 | } else { |
| 63 | failed_indices.push_back(i + 1); |
| 64 | } |
| 65 | std::cout << std::endl; |
| 66 | } |
| 67 | |
| 68 | // --- Statistics Summary --- |
| 69 | std::cout << "========================================" << std::endl; |
| 70 | std::cout << "TEST SUMMARY" << std::endl; |
nothing calls this directly
no test coverage detected