@@ -1048,40 +1048,66 @@ mod tests {
1048
1048
r#"{"title": "Foo", "type": "string", "format": "uri"}"# ,
1049
1049
URI ,
1050
1050
vec ! [
1051
- " http://example.com",
1052
- " https://example.com/path?query=param#fragment",
1053
- " ftp://ftp.example.com/resource",
1054
- " urn:isbn:0451450523",
1051
+ r#"" http://example.com""# ,
1052
+ r#"" https://example.com/path?query=param#fragment""# ,
1053
+ r#"" ftp://ftp.example.com/resource""# ,
1054
+ r#"" urn:isbn:0451450523""# ,
1055
1055
] ,
1056
1056
vec ! [
1057
- " http:/example.com", // missing slash
1058
- " htp://example.com", // invalid scheme
1059
- " http://", // missing host
1060
- " example.com", // missing scheme
1057
+ r#"" http:/example.com""# , // missing slash
1058
+ r#"" htp://example.com""# , // invalid scheme
1059
+ r#"" http://""# , // missing host
1060
+ r#"" example.com""# , // missing scheme
1061
1061
]
1062
1062
) ,
1063
1063
(
1064
1064
r#"{"title": "Bar", "type": "string", "format": "email"}"# ,
1065
1065
EMAIL ,
1066
1066
vec ! [
1067
1067
// Valid emails
1068
- " user@example.com", // valid
1069
- " user.name+tag+sorting@example.com", // valid
1070
- " user_name@example.co.uk", // valid
1071
- " user-name@sub.example.com", // valid
1068
+ r#"" user@example.com""# , // valid
1069
+ r#"" user.name+tag+sorting@example.com""# , // valid
1070
+ r#"" user_name@example.co.uk""# , // valid
1071
+ r#"" user-name@sub.example.com""# , // valid
1072
1072
] ,
1073
1073
vec ! [
1074
1074
// Invalid emails
1075
- "plainaddress" , // missing '@' and domain
1076
- "@missingusername.com" , // missing username
1077
- "username@.com" , // leading dot in domain
1078
- "username@com" , // TLD must have at least 2 characters
1079
- "username@example,com" , // invalid character in domain
1080
- "username@.example.com" , // leading dot in domain
1081
- "username@-example.com" , // domain cannot start with a hyphen
1082
- "username@example-.com" , // domain cannot end with a hyphen
1083
- "username@example..com" , // double dot in domain name
1084
- "username@.example..com" , // multiple errors in domain
1075
+ r#""plainaddress""# , // missing '@' and domain
1076
+ r#""@missingusername.com""# , // missing username
1077
+ r#""username@.com""# , // leading dot in domain
1078
+ r#""username@com""# , // TLD must have at least 2 characters
1079
+ r#""username@example,com""# , // invalid character in domain
1080
+ r#""username@.example.com""# , // leading dot in domain
1081
+ r#""username@-example.com""# , // domain cannot start with a hyphen
1082
+ r#""username@example-.com""# , // domain cannot end with a hyphen
1083
+ r#""username@example..com""# , // double dot in domain name
1084
+ r#""username@.example..com""# , // multiple errors in domain
1085
+ ]
1086
+ ) ,
1087
+ // Nested URI and email
1088
+ (
1089
+ r#"{
1090
+ "title": "Test Schema",
1091
+ "type": "object",
1092
+ "properties": {
1093
+ "test_str": {"title": "Test string", "type": "string"},
1094
+ "test_uri": {"title": "Test URI", "type": "string", "format": "uri"},
1095
+ "test_email": {"title": "Test email", "type": "string", "format": "email"}
1096
+ },
1097
+ "required": ["test_str", "test_uri", "test_email"]
1098
+ }"# ,
1099
+ format ! (
1100
+ r#"\{{{0}"test_str"{0}:{0}{STRING}{0},{0}"test_uri"{0}:{0}{URI}{0},{0}"test_email"{0}:{0}{EMAIL}{0}\}}"# ,
1101
+ WHITESPACE
1102
+ ) . as_str ( ) ,
1103
+ vec ! [
1104
+ r#"{ "test_str": "cat", "test_uri": "http://example.com", "test_email": "user@example.com" }"# ,
1105
+ ] ,
1106
+ vec ! [
1107
+ // Invalid URI
1108
+ r#"{ "test_str": "cat", "test_uri": "http:/example.com", "test_email": "user@example.com" }"# ,
1109
+ // Invalid email
1110
+ r#"{ "test_str": "cat", "test_uri": "http://example.com", "test_email": "username@.com" }"# ,
1085
1111
]
1086
1112
) ,
1087
1113
0 commit comments