@@ -403,69 +403,6 @@ macro_rules! bitflags_array {
403403 } ;
404404}
405405
406- #[ cfg( feature = "serde" ) ]
407- #[ test]
408- fn check_hex ( ) {
409- let mut hex = alloc:: string:: String :: new ( ) ;
410- FeatureBits :: ALL . write_hex ( & mut hex) . unwrap ( ) ;
411- assert_eq ! (
412- FeatureBits :: parse_hex( hex. as_str( ) ) . unwrap( ) ,
413- FeatureBits :: ALL
414- ) ;
415- hex. clear ( ) ;
416- FeatureBits :: EMPTY . write_hex ( & mut hex) . unwrap ( ) ;
417- assert_eq ! (
418- FeatureBits :: parse_hex( hex. as_str( ) ) . unwrap( ) ,
419- FeatureBits :: EMPTY
420- ) ;
421- for feature in Features :: FLAGS {
422- hex. clear ( ) ;
423- feature. value ( ) . bits ( ) . write_hex ( & mut hex) . unwrap ( ) ;
424- assert_eq ! (
425- FeatureBits :: parse_hex( hex. as_str( ) ) . unwrap( ) ,
426- feature. value( ) . bits( ) ,
427- "{hex}"
428- ) ;
429- }
430- }
431-
432- #[ test]
433- fn check_features_display ( ) {
434- use alloc:: format;
435- let feature = Features :: CLEAR_TEXTURE ;
436- assert_eq ! ( format!( "{}" , feature) , "CLEAR_TEXTURE" ) ;
437- let feature = Features :: CLEAR_TEXTURE | Features :: BGRA8UNORM_STORAGE ;
438- assert_eq ! ( format!( "{}" , feature) , "CLEAR_TEXTURE | BGRA8UNORM_STORAGE" ) ;
439- }
440-
441- #[ test]
442- fn check_features_bits ( ) {
443- let bits = Features :: all ( ) . bits ( ) ;
444- assert_eq ! ( Features :: from_bits_retain( bits) , Features :: all( ) ) ;
445- let bits = Features :: empty ( ) . bits ( ) ;
446- assert_eq ! ( Features :: from_bits_retain( bits) , Features :: empty( ) ) ;
447- for feature in Features :: FLAGS {
448- let bits = feature. value ( ) . bits ( ) ;
449- assert_eq ! ( Features :: from_bits_retain( bits) , * feature. value( ) ) ;
450- }
451- let bits = Features :: all ( ) . bits ( ) ;
452- assert_eq ! ( Features :: from_bits_truncate( bits) , Features :: all( ) ) ;
453- let bits = Features :: empty ( ) . bits ( ) ;
454- assert_eq ! ( Features :: from_bits_truncate( bits) , Features :: empty( ) ) ;
455- for feature in Features :: FLAGS {
456- let bits = feature. value ( ) . bits ( ) ;
457- assert_eq ! ( Features :: from_bits_truncate( bits) , * feature. value( ) ) ;
458- }
459- let bits = Features :: all ( ) . bits ( ) ;
460- assert_eq ! ( Features :: from_bits( bits) . unwrap( ) , Features :: all( ) ) ;
461- let bits = Features :: empty ( ) . bits ( ) ;
462- assert_eq ! ( Features :: from_bits( bits) . unwrap( ) , Features :: empty( ) ) ;
463- for feature in Features :: FLAGS {
464- let bits = feature. value ( ) . bits ( ) ;
465- assert_eq ! ( Features :: from_bits( bits) . unwrap( ) , * feature. value( ) ) ;
466- }
467- }
468-
469406impl From < FeatureBits > for Features {
470407 fn from ( value : FeatureBits ) -> Self {
471408 Self :: from_bits_retain ( value)
@@ -1357,3 +1294,90 @@ impl Features {
13571294 formats
13581295 }
13591296}
1297+
1298+ #[ cfg( test) ]
1299+ mod tests {
1300+ use crate :: Features ;
1301+
1302+ #[ cfg( feature = "serde" ) ]
1303+ #[ test]
1304+ fn check_hex ( ) {
1305+ use crate :: FeatureBits ;
1306+
1307+ use bitflags:: {
1308+ parser:: { ParseHex as _, WriteHex as _} ,
1309+ Bits as _,
1310+ } ;
1311+
1312+ let mut hex = alloc:: string:: String :: new ( ) ;
1313+ FeatureBits :: ALL . write_hex ( & mut hex) . unwrap ( ) ;
1314+ assert_eq ! (
1315+ FeatureBits :: parse_hex( hex. as_str( ) ) . unwrap( ) ,
1316+ FeatureBits :: ALL
1317+ ) ;
1318+
1319+ hex. clear ( ) ;
1320+ FeatureBits :: EMPTY . write_hex ( & mut hex) . unwrap ( ) ;
1321+ assert_eq ! (
1322+ FeatureBits :: parse_hex( hex. as_str( ) ) . unwrap( ) ,
1323+ FeatureBits :: EMPTY
1324+ ) ;
1325+
1326+ for feature in Features :: FLAGS {
1327+ hex. clear ( ) ;
1328+ feature. value ( ) . bits ( ) . write_hex ( & mut hex) . unwrap ( ) ;
1329+ assert_eq ! (
1330+ FeatureBits :: parse_hex( hex. as_str( ) ) . unwrap( ) ,
1331+ feature. value( ) . bits( ) ,
1332+ "{hex}"
1333+ ) ;
1334+ }
1335+ }
1336+
1337+ #[ test]
1338+ fn check_features_display ( ) {
1339+ use alloc:: format;
1340+
1341+ let feature = Features :: CLEAR_TEXTURE ;
1342+ assert_eq ! ( format!( "{}" , feature) , "CLEAR_TEXTURE" ) ;
1343+
1344+ let feature = Features :: CLEAR_TEXTURE | Features :: BGRA8UNORM_STORAGE ;
1345+ assert_eq ! ( format!( "{}" , feature) , "CLEAR_TEXTURE | BGRA8UNORM_STORAGE" ) ;
1346+ }
1347+
1348+ #[ test]
1349+ fn check_features_bits ( ) {
1350+ let bits = Features :: all ( ) . bits ( ) ;
1351+ assert_eq ! ( Features :: from_bits_retain( bits) , Features :: all( ) ) ;
1352+
1353+ let bits = Features :: empty ( ) . bits ( ) ;
1354+ assert_eq ! ( Features :: from_bits_retain( bits) , Features :: empty( ) ) ;
1355+
1356+ for feature in Features :: FLAGS {
1357+ let bits = feature. value ( ) . bits ( ) ;
1358+ assert_eq ! ( Features :: from_bits_retain( bits) , * feature. value( ) ) ;
1359+ }
1360+
1361+ let bits = Features :: all ( ) . bits ( ) ;
1362+ assert_eq ! ( Features :: from_bits_truncate( bits) , Features :: all( ) ) ;
1363+
1364+ let bits = Features :: empty ( ) . bits ( ) ;
1365+ assert_eq ! ( Features :: from_bits_truncate( bits) , Features :: empty( ) ) ;
1366+
1367+ for feature in Features :: FLAGS {
1368+ let bits = feature. value ( ) . bits ( ) ;
1369+ assert_eq ! ( Features :: from_bits_truncate( bits) , * feature. value( ) ) ;
1370+ }
1371+
1372+ let bits = Features :: all ( ) . bits ( ) ;
1373+ assert_eq ! ( Features :: from_bits( bits) . unwrap( ) , Features :: all( ) ) ;
1374+
1375+ let bits = Features :: empty ( ) . bits ( ) ;
1376+ assert_eq ! ( Features :: from_bits( bits) . unwrap( ) , Features :: empty( ) ) ;
1377+
1378+ for feature in Features :: FLAGS {
1379+ let bits = feature. value ( ) . bits ( ) ;
1380+ assert_eq ! ( Features :: from_bits( bits) . unwrap( ) , * feature. value( ) ) ;
1381+ }
1382+ }
1383+ }
0 commit comments