Skip to content

Commit 70ccfdf

Browse files
committed
Added first tests for microsoft#6579
1 parent a7d97c0 commit 70ccfdf

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

Diff for: tests/cases/compiler/regexValidatedType.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type CssColor = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
2+
type Email = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
3+
type Gmail = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@gmail\.com$/i;

Diff for: tests/cases/compiler/regexValidatedTypeAssignment.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
type Email = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
2+
type Gmail = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@gmail\.com$/i;
3+
4+
let email: Email;
5+
let gmail: Gmail;
6+
7+
8+
9+
10+
gmail = email;
11+
email = gmail;
12+
13+
gmail = <Gmail>email;
14+
if (Gmail.test(email)) {
15+
gmail = email;
16+
}
17+
18+
let someEmail = '[email protected]';
19+
let someGmail = '[email protected]';
20+
email = someEmail;
21+
gmail = someGmail;
22+
email = <Email>someEmail;
23+
gmail = <Gmail>someGmail;
24+
if (Email.test(someEmail)) {
25+
email = someEmail;
26+
}
27+
if (Gmail.test(someGmail)) {
28+
gmail = someGmail;
29+
}
30+
31+
let someEmailLiteral: '[email protected]' = '[email protected]';
32+
let someGmailLiteral: '[email protected]' = '[email protected]';
33+
email = someEmailLiteral;
34+
gmail = someGmailLiteral;

Diff for: tests/cases/compiler/regexValidatedTypeIndex.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
type Email = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
2+
type Gmail = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@gmail\.com$/i;
3+
4+
interface User {
5+
usersProperty: number;
6+
}
7+
interface GmailUser {
8+
gmailProperty: number;
9+
}
10+
11+
interface UsersCollection {
12+
[email: Email]: User;
13+
[gmail: Gmail]: GmailUser;
14+
}
15+
16+
let collection: UsersCollection;
17+
let someEmail = 'test@example.com';
18+
let someGmail = '[email protected]';
19+
20+
collection['[email protected]'].usersProperty;
21+
collection['[email protected]'].gmailProperty;
22+
collection['[email protected]'].usersProperty;
23+
collection['[email protected]'].gmailProperty;
24+
25+
collection[someEmail].usersProperty;
26+
collection[someEmail].gmailProperty;
27+
collection[someGmail].usersProperty;
28+
collection[someGmail].gmailProperty;
29+
30+
collection[<Email>someEmail].usersProperty;
31+
collection[<Email>someEmail].gmailProperty;
32+
collection[<Gmail>someGmail].usersProperty;
33+
collection[<Gmail>someGmail].gmailProperty;
34+
collection[<Email & Gmail> someGmail].usersProperty;
35+
collection[<Email & Gmail> someGmail].gmailProperty;

0 commit comments

Comments
 (0)