@@ -433,3 +433,39 @@ fn test_render_long_html() {
433433 ) ;
434434 } )
435435}
436+
437+ #[ test]
438+ fn test_simplify_with ( ) {
439+ // This is a tiny subset of things that could be simplified, but it likely covers 90% of
440+ // real world usecases well.
441+ with_default_session_globals ( || {
442+ let foo = word_cfg ( "foo" ) ;
443+ let bar = word_cfg ( "bar" ) ;
444+ let baz = word_cfg ( "baz" ) ;
445+ let quux = word_cfg ( "quux" ) ;
446+
447+ let foobar = Cfg :: All ( vec ! [ foo. clone( ) , bar. clone( ) ] ) ;
448+ let barbaz = Cfg :: All ( vec ! [ bar. clone( ) , baz. clone( ) ] ) ;
449+ let foobarbaz = Cfg :: All ( vec ! [ foo. clone( ) , bar. clone( ) , baz. clone( ) ] ) ;
450+ let bazquux = Cfg :: All ( vec ! [ baz. clone( ) , quux. clone( ) ] ) ;
451+
452+ // Unrelated cfgs don't affect each other
453+ assert_eq ! ( foo. simplify_with( & bar) . as_ref( ) , Some ( & foo) ) ;
454+ assert_eq ! ( foobar. simplify_with( & bazquux) . as_ref( ) , Some ( & foobar) ) ;
455+
456+ // Identical cfgs are eliminated
457+ assert_eq ! ( foo. simplify_with( & foo) , None ) ;
458+ assert_eq ! ( foobar. simplify_with( & foobar) , None ) ;
459+
460+ // Multiple cfgs eliminate a single assumed cfg
461+ assert_eq ! ( foobar. simplify_with( & foo) . as_ref( ) , Some ( & bar) ) ;
462+ assert_eq ! ( foobar. simplify_with( & bar) . as_ref( ) , Some ( & foo) ) ;
463+
464+ // A single cfg is eliminated by multiple assumed cfg containing it
465+ assert_eq ! ( foo. simplify_with( & foobar) , None ) ;
466+
467+ // Multiple cfgs eliminate the matching subset of multiple assumed cfg
468+ assert_eq ! ( foobar. simplify_with( & barbaz) . as_ref( ) , Some ( & foo) ) ;
469+ assert_eq ! ( foobar. simplify_with( & foobarbaz) , None ) ;
470+ } ) ;
471+ }
0 commit comments