Skip to content

Commit 56b4b27

Browse files
committed
pnpm run format
1 parent cea938a commit 56b4b27

11 files changed

Lines changed: 488 additions & 510 deletions

File tree

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,73 @@
1-
import { describe, it, expect } from 'vitest'
2-
import { isEmailAddress, validateEmail } from './emailValidator'
1+
import { describe, expect, it } from 'vitest';
2+
import { isEmailAddress, validateEmail } from './emailValidator';
33

44
describe('isEmailAddress', () => {
55
it('returns false for empty string', () => {
6-
expect(isEmailAddress('')).toBe(false)
7-
})
6+
expect(isEmailAddress('')).toBe(false);
7+
});
88

99
it('returns false when missing "@" or has multiple "@"', () => {
10-
expect(isEmailAddress('plainaddress')).toBe(false)
11-
expect(isEmailAddress('a@b@c.com')).toBe(false)
12-
})
10+
expect(isEmailAddress('plainaddress')).toBe(false);
11+
expect(isEmailAddress('a@b@c.com')).toBe(false);
12+
});
1313

1414
it('returns false when total length exceeds 320 characters', () => {
15-
const localPart = 'a'.repeat(64)
16-
const domainLabel = 'b'.repeat(63)
17-
const domain = Array(5).fill(domainLabel).join('.') // 5×63 + 4 dots = 319
18-
const validEmail = `${localPart}@${domain}` // 384 chars total
19-
expect(validEmail.length).toBe(64 + 1 + 319)
20-
expect(isEmailAddress(validEmail)).toBe(false)
21-
})
15+
const localPart = 'a'.repeat(64);
16+
const domainLabel = 'b'.repeat(63);
17+
const domain = Array(5).fill(domainLabel).join('.'); // 5×63 + 4 dots = 319
18+
const validEmail = `${localPart}@${domain}`; // 384 chars total
19+
expect(validEmail.length).toBe(64 + 1 + 319);
20+
expect(isEmailAddress(validEmail)).toBe(false);
21+
});
2222

2323
it('returns false when local part exceeds 64 characters', () => {
24-
const account = 'x'.repeat(65)
25-
const address = 'domain.com'
26-
expect(isEmailAddress(`${account}@${address}`)).toBe(false)
27-
})
24+
const account = 'x'.repeat(65);
25+
const address = 'domain.com';
26+
expect(isEmailAddress(`${account}@${address}`)).toBe(false);
27+
});
2828

2929
it('returns false when domain part exceeds 255 characters', () => {
30-
const account = 'user'
31-
const longLabel = 'd'.repeat(63)
30+
const account = 'user';
31+
const longLabel = 'd'.repeat(63);
3232
// 4 labels of 63 chars + 3 dots = 4*63 + 3 = 255
33-
const domain = Array(4).fill(longLabel).join('.')
34-
expect(domain.length).toBe(255)
33+
const domain = Array(4).fill(longLabel).join('.');
34+
expect(domain.length).toBe(255);
3535
// Prepend one character to push domain over 255
36-
const tooLongDomain = 'e' + domain
37-
expect(isEmailAddress(`${account}@${tooLongDomain}`)).toBe(false)
38-
})
36+
const tooLongDomain = 'e' + domain;
37+
expect(isEmailAddress(`${account}@${tooLongDomain}`)).toBe(false);
38+
});
3939

4040
it('returns false when any domain label exceeds 63 characters', () => {
41-
const account = 'user'
42-
const longLabel = 'd'.repeat(64)
43-
const address = `${longLabel}.com`
44-
expect(isEmailAddress(`${account}@${address}`)).toBe(false)
45-
})
41+
const account = 'user';
42+
const longLabel = 'd'.repeat(64);
43+
const address = `${longLabel}.com`;
44+
expect(isEmailAddress(`${account}@${address}`)).toBe(false);
45+
});
4646

4747
it('returns false for invalid characters or formats not matching regex', () => {
4848
// starts with a dot
49-
expect(isEmailAddress('.user@domain.com')).toBe(false)
49+
expect(isEmailAddress('.user@domain.com')).toBe(false);
5050
// consecutive dots in local part
51-
expect(isEmailAddress('user..name@domain.com')).toBe(false)
51+
expect(isEmailAddress('user..name@domain.com')).toBe(false);
5252
// hyphen at start of domain label
53-
expect(isEmailAddress('user@-domain.com')).toBe(false)
53+
expect(isEmailAddress('user@-domain.com')).toBe(false);
5454
// no TLD
55-
expect(isEmailAddress('user@domain')).toBe(false)
56-
})
55+
expect(isEmailAddress('user@domain')).toBe(false);
56+
});
5757

5858
it('returns true for valid standard email addresses', () => {
59-
expect(isEmailAddress('simple@example.com')).toBe(true)
60-
expect(isEmailAddress('very.common@example.co.uk')).toBe(true)
61-
expect(isEmailAddress("o'reilly@example.io")).toBe(true)
62-
expect(isEmailAddress('user_name-123@sub.domain.com')).toBe(true)
63-
})
64-
})
59+
expect(isEmailAddress('simple@example.com')).toBe(true);
60+
expect(isEmailAddress('very.common@example.co.uk')).toBe(true);
61+
expect(isEmailAddress("o'reilly@example.io")).toBe(true);
62+
expect(isEmailAddress('user_name-123@sub.domain.com')).toBe(true);
63+
});
64+
});
6565

6666
describe('validateEmail', () => {
6767
it('returns null for empty input', () => {
68-
const result = validateEmail('')
69-
expect(result).toBeNull()
70-
})
68+
const result = validateEmail('');
69+
expect(result).toBeNull();
70+
});
7171

7272
it('returns valid: false and message "Invalid email" for syntactically invalid addresses', () => {
7373
const invalids = [
@@ -76,55 +76,55 @@ describe('validateEmail', () => {
7676
'user@domain..com',
7777
'user@domain',
7878
'toolong' + 'a'.repeat(320) + '@example.com',
79-
]
79+
];
8080
for (const addr of invalids) {
81-
const result = validateEmail(addr)
82-
expect(result).not.toBeNull()
83-
expect(result?.valid).toBe(false)
84-
expect(result?.message).toBe('Invalid email')
81+
const result = validateEmail(addr);
82+
expect(result).not.toBeNull();
83+
expect(result?.valid).toBe(false);
84+
expect(result?.message).toBe('Invalid email');
8585
}
86-
})
86+
});
8787

8888
it('returns valid: false and message "Email cannot contain aliases" when email contains "+"', () => {
89-
const withAlias = 'user+alias@example.com'
90-
const result = validateEmail(withAlias)
91-
expect(result).not.toBeNull()
92-
expect(result?.valid).toBe(false)
93-
expect(result?.message).toBe('Email cannot contain aliases')
94-
})
89+
const withAlias = 'user+alias@example.com';
90+
const result = validateEmail(withAlias);
91+
expect(result).not.toBeNull();
92+
expect(result?.valid).toBe(false);
93+
expect(result?.message).toBe('Email cannot contain aliases');
94+
});
9595

9696
it('returns valid: true for valid email without "+"', () => {
97-
const valid = 'firstname.lastname@domain.com'
98-
const result = validateEmail(valid)
99-
expect(result).not.toBeNull()
100-
expect(result?.valid).toBe(true)
101-
expect(result).not.toHaveProperty('message')
102-
})
97+
const valid = 'firstname.lastname@domain.com';
98+
const result = validateEmail(valid);
99+
expect(result).not.toBeNull();
100+
expect(result?.valid).toBe(true);
101+
expect(result).not.toHaveProperty('message');
102+
});
103103

104104
it('treats "+" anywhere in the local part as invalid alias', () => {
105105
const examples = [
106106
'plus+sign@domain.com',
107107
'+start@domain.com',
108108
'end+@domain.com',
109109
'middle+more@sub.domain.org',
110-
]
110+
];
111111
for (const addr of examples) {
112-
const result = validateEmail(addr)
113-
expect(result).not.toBeNull()
114-
expect(result?.valid).toBe(false)
115-
expect(result?.message).toBe('Email cannot contain aliases')
112+
const result = validateEmail(addr);
113+
expect(result).not.toBeNull();
114+
expect(result?.valid).toBe(false);
115+
expect(result?.message).toBe('Email cannot contain aliases');
116116
}
117-
})
117+
});
118118

119119
it('does not reject valid emails with hyphens in domain or underscores in local part', () => {
120120
const examples = [
121121
'user_name@example-domain.com', // underscore in local, hyphen in domain
122122
'another.user-name@sub.domain.com', // hyphen in both portions
123-
]
123+
];
124124
for (const addr of examples) {
125-
const result = validateEmail(addr)
126-
expect(result).not.toBeNull()
127-
expect(result?.valid).toBe(true)
125+
const result = validateEmail(addr);
126+
expect(result).not.toBeNull();
127+
expect(result?.valid).toBe(true);
128128
}
129-
})
130-
})
129+
});
130+
});

0 commit comments

Comments
 (0)