|
| 1 | +#include "emails.hpp" |
| 2 | +#include "gtest/gtest.h" |
| 3 | + |
| 4 | +TEST(EmailExtractionTest, EmptyInput) { EXPECT_EQ(emails(""), std::vector<std::string>({})); } |
| 5 | + |
| 6 | +TEST(EmailExtractionTest, NoEmailsInText) { |
| 7 | + const std::string text = R"( |
| 8 | + This is just regular text without any emails. |
| 9 | + Some symbols: @hello, test@, @test.com |
| 10 | + Numbers: 12345, random!text |
| 11 | + )"; |
| 12 | + EXPECT_EQ(emails(text), std::vector<std::string>({})); |
| 13 | +} |
| 14 | + |
| 15 | +TEST(EmailExtractionTest, ValidEmails) { |
| 16 | + const std::string text = R"( |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + )"; |
| 21 | + EXPECT_EQ(emails(text), |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +} |
| 26 | + |
| 27 | +TEST(EmailExtractionTest, InvalidEmails) { |
| 28 | + const std::string text = R"( |
| 29 | + Invalid formats: |
| 30 | + plaintext |
| 31 | + @missing.start |
| 32 | + missing@at |
| 33 | + double@@sign.com |
| 34 | + invalid@chars_here.com |
| 35 | + missing@tld. |
| 36 | + )"; |
| 37 | + EXPECT_EQ(emails(text), std::vector<std::string>({})); |
| 38 | +} |
| 39 | + |
| 40 | +TEST(EmailExtractionTest, MixedContent) { |
| 41 | + const std::string text = R"( |
| 42 | + |
| 43 | + Invalid: bad@email, @wrong.com |
| 44 | + Almost valid: almost@valid. but with space |
| 45 | + Trash: !@#$%^&* |
| 46 | + Valid but tricky: "[email protected]" (should extract without quotes) |
| 47 | + )"; |
| 48 | + EXPECT_EQ(emails(text), std::vector<std::string>( |
| 49 | + |
| 50 | +} |
| 51 | + |
| 52 | +TEST(EmailExtractionTest, EdgeCases) { |
| 53 | + const std::string text = R"( |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + )"; |
| 61 | + EXPECT_EQ(emails(text), |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +} |
0 commit comments