@@ -1328,27 +1328,68 @@ pub(crate) mod test {
1328
1328
1329
1329
use super :: * ;
1330
1330
1331
- /// Transform the output of functions like
1332
- /// `ValidatorSchema::from_cedarschema_str()`, which has type `(ValidatorSchema, impl Iterator<...>)`,
1333
- /// into `(ValidatorSchema, Vec<...>)`, which implements `Debug` and thus can be used with
1334
- /// `assert_matches`, `.unwrap_err()`, etc
1335
- pub fn collect_warnings < A , B , E > (
1336
- r : std:: result:: Result < ( A , impl Iterator < Item = B > ) , E > ,
1337
- ) -> std:: result:: Result < ( A , Vec < B > ) , E > {
1338
- r. map ( |( a, iter) | ( a, iter. collect ( ) ) )
1339
- }
1340
-
1341
- /// Given an entity type as string, get the `ValidatorEntityType` from the
1342
- /// schema, panicking if it does not exist (or if `etype` fails to parse as
1343
- /// an entity type)
1344
- #[ track_caller]
1345
- pub fn assert_entity_type_exists < ' s > (
1346
- schema : & ' s ValidatorSchema ,
1347
- etype : & str ,
1348
- ) -> & ' s ValidatorEntityType {
1349
- schema. get_entity_type ( & etype. parse ( ) . unwrap ( ) ) . unwrap ( )
1331
+ pub ( crate ) mod utils {
1332
+ use super :: { CedarSchemaError , SchemaError , ValidatorEntityType , ValidatorSchema } ;
1333
+ use cedar_policy_core:: extensions:: Extensions ;
1334
+
1335
+ /// Transform the output of functions like
1336
+ /// `ValidatorSchema::from_cedarschema_str()`, which has type `(ValidatorSchema, impl Iterator<...>)`,
1337
+ /// into `(ValidatorSchema, Vec<...>)`, which implements `Debug` and thus can be used with
1338
+ /// `assert_matches`, `.unwrap_err()`, etc
1339
+ pub fn collect_warnings < A , B , E > (
1340
+ r : std:: result:: Result < ( A , impl Iterator < Item = B > ) , E > ,
1341
+ ) -> std:: result:: Result < ( A , Vec < B > ) , E > {
1342
+ r. map ( |( a, iter) | ( a, iter. collect ( ) ) )
1343
+ }
1344
+
1345
+ /// Given an entity type as string, get the `ValidatorEntityType` from the
1346
+ /// schema, panicking if it does not exist (or if `etype` fails to parse as
1347
+ /// an entity type)
1348
+ #[ track_caller]
1349
+ pub fn assert_entity_type_exists < ' s > (
1350
+ schema : & ' s ValidatorSchema ,
1351
+ etype : & str ,
1352
+ ) -> & ' s ValidatorEntityType {
1353
+ schema. get_entity_type ( & etype. parse ( ) . unwrap ( ) ) . unwrap ( )
1354
+ }
1355
+
1356
+ #[ track_caller]
1357
+ pub fn assert_valid_cedar_schema ( src : & str ) -> ValidatorSchema {
1358
+ match ValidatorSchema :: from_cedarschema_str ( src, Extensions :: all_available ( ) ) {
1359
+ Ok ( ( schema, _) ) => schema,
1360
+ Err ( e) => panic ! ( "{:?}" , miette:: Report :: new( e) ) ,
1361
+ }
1362
+ }
1363
+
1364
+ #[ track_caller]
1365
+ pub fn assert_invalid_cedar_schema ( src : & str ) {
1366
+ match ValidatorSchema :: from_cedarschema_str ( src, Extensions :: all_available ( ) ) {
1367
+ Ok ( _) => panic ! ( "{src} should be an invalid schema" ) ,
1368
+ Err ( CedarSchemaError :: Parsing ( _) ) => { }
1369
+ Err ( e) => panic ! ( "unexpected error: {:?}" , miette:: Report :: new( e) ) ,
1370
+ }
1371
+ }
1372
+
1373
+ #[ track_caller]
1374
+ pub fn assert_valid_json_schema ( json : serde_json:: Value ) -> ValidatorSchema {
1375
+ match ValidatorSchema :: from_json_value ( json, Extensions :: all_available ( ) ) {
1376
+ Ok ( schema) => schema,
1377
+ Err ( e) => panic ! ( "{:?}" , miette:: Report :: new( e) ) ,
1378
+ }
1379
+ }
1380
+
1381
+ #[ track_caller]
1382
+ pub fn assert_invalid_json_schema ( json : serde_json:: Value ) {
1383
+ match ValidatorSchema :: from_json_value ( json. clone ( ) , Extensions :: all_available ( ) ) {
1384
+ Ok ( _) => panic ! ( "{json} should be an invalid schema" ) ,
1385
+ Err ( SchemaError :: JsonDeserialization ( _) ) => { }
1386
+ Err ( e) => panic ! ( "unexpected error: {:?}" , miette:: Report :: new( e) ) ,
1387
+ }
1388
+ }
1350
1389
}
1351
1390
1391
+ use utils:: * ;
1392
+
1352
1393
// Well-formed schema
1353
1394
#[ test]
1354
1395
fn test_from_schema_file ( ) {
@@ -3443,15 +3484,23 @@ pub(crate) mod test {
3443
3484
) ;
3444
3485
} ) ;
3445
3486
}
3487
+
3488
+ #[ test]
3489
+ fn attr_named_tags ( ) {
3490
+ let src = r#"
3491
+ entity E { tags: Set<{key: String, value: Set<String>}> };
3492
+ "# ;
3493
+ assert_valid_cedar_schema ( src) ;
3494
+ }
3446
3495
}
3447
3496
3448
3497
#[ cfg( test) ]
3449
3498
mod test_579; // located in separate file test_579.rs
3450
3499
3451
3500
#[ cfg( test) ]
3452
3501
mod test_rfc70 {
3453
- use super :: test:: { assert_entity_type_exists , collect_warnings } ;
3454
- use super :: { CedarSchemaError , SchemaError , ValidatorSchema } ;
3502
+ use super :: test:: utils :: * ;
3503
+ use super :: ValidatorSchema ;
3455
3504
use crate :: types:: Type ;
3456
3505
use cedar_policy_core:: {
3457
3506
extensions:: Extensions ,
@@ -3460,40 +3509,6 @@ mod test_rfc70 {
3460
3509
use cool_asserts:: assert_matches;
3461
3510
use serde_json:: json;
3462
3511
3463
- #[ track_caller]
3464
- fn assert_valid_cedar_schema ( src : & str ) -> ValidatorSchema {
3465
- match ValidatorSchema :: from_cedarschema_str ( src, Extensions :: all_available ( ) ) {
3466
- Ok ( ( schema, _) ) => schema,
3467
- Err ( e) => panic ! ( "{:?}" , miette:: Report :: new( e) ) ,
3468
- }
3469
- }
3470
-
3471
- #[ track_caller]
3472
- fn assert_invalid_cedar_schema ( src : & str ) {
3473
- match ValidatorSchema :: from_cedarschema_str ( src, Extensions :: all_available ( ) ) {
3474
- Ok ( _) => panic ! ( "{src} should be an invalid schema" ) ,
3475
- Err ( CedarSchemaError :: Parsing ( _) ) => { }
3476
- Err ( e) => panic ! ( "unexpected error: {:?}" , miette:: Report :: new( e) ) ,
3477
- }
3478
- }
3479
-
3480
- #[ track_caller]
3481
- fn assert_valid_json_schema ( json : serde_json:: Value ) -> ValidatorSchema {
3482
- match ValidatorSchema :: from_json_value ( json, Extensions :: all_available ( ) ) {
3483
- Ok ( schema) => schema,
3484
- Err ( e) => panic ! ( "{:?}" , miette:: Report :: new( e) ) ,
3485
- }
3486
- }
3487
-
3488
- #[ track_caller]
3489
- fn assert_invalid_json_schema ( json : serde_json:: Value ) {
3490
- match ValidatorSchema :: from_json_value ( json. clone ( ) , Extensions :: all_available ( ) ) {
3491
- Ok ( _) => panic ! ( "{json} should be an invalid schema" ) ,
3492
- Err ( SchemaError :: JsonDeserialization ( _) ) => { }
3493
- Err ( e) => panic ! ( "unexpected error: {:?}" , miette:: Report :: new( e) ) ,
3494
- }
3495
- }
3496
-
3497
3512
/// Common type shadowing a common type is disallowed in both syntaxes
3498
3513
#[ test]
3499
3514
fn common_common_conflict ( ) {
@@ -4476,10 +4491,7 @@ mod test_rfc70 {
4476
4491
mod entity_tags {
4477
4492
use crate :: types:: Primitive ;
4478
4493
4479
- use super :: {
4480
- test:: { assert_entity_type_exists, collect_warnings} ,
4481
- * ,
4482
- } ;
4494
+ use super :: { test:: utils:: * , * } ;
4483
4495
use cedar_policy_core:: {
4484
4496
extensions:: Extensions ,
4485
4497
test_utils:: { expect_err, ExpectedErrorMessageBuilder } ,
0 commit comments