@@ -8,10 +8,12 @@ const {
88 checkStatedClassSpellings,
99 collectAlphaValueProperties,
1010 collectData,
11+ collectFamilyLonghands,
1112 collectGradientFunctions,
1213 collectMergeableAtRules,
1314 collectRatioProperties,
1415 isSpelledSyntax,
16+ longhandType,
1517 parseValueSyntax,
1618 shorthandSlots,
1719 slotSpellings,
@@ -483,6 +485,168 @@ describe("CssValueSyntax", () => {
483485 } ) ;
484486 } ) ;
485487
488+ describe ( "longhandType" , ( ) => {
489+ it ( "reads the one type a longhand's whole value is" , ( ) => {
490+ expect ( longhandType ( "border-top-color" , 0 ) ) . toBe ( "color" ) ;
491+ } ) ;
492+
493+ it ( "follows the `<'other'>` a longhand is stated as" , ( ) => {
494+ expect (
495+ longhandType ( "a" , 0 , {
496+ a : { syntax : "<'b'>" } ,
497+ b : { syntax : "<color>" }
498+ } )
499+ ) . toBe ( "color" ) ;
500+ } ) ;
501+
502+ it ( "reads none for a name the table does not hold" , ( ) => {
503+ expect ( longhandType ( "gone" , 0 , { } ) ) . toBeNull ( ) ;
504+ } ) ;
505+
506+ it ( "reads none where the entry states no syntax" , ( ) => {
507+ expect ( longhandType ( "a" , 0 , { a : { } } ) ) . toBeNull ( ) ;
508+ } ) ;
509+
510+ it ( "reads none where the chain of references has no end" , ( ) => {
511+ expect ( longhandType ( "a" , 0 , { a : { syntax : "<'a'>" } } ) ) . toBeNull ( ) ;
512+ } ) ;
513+
514+ it ( "reads none where the value is more than one type" , ( ) => {
515+ expect (
516+ longhandType ( "a" , 0 , { a : { syntax : "red | <color>" } } )
517+ ) . toBeNull ( ) ;
518+ } ) ;
519+ } ) ;
520+
521+ describe ( "collectFamilyLonghands" , ( ) => {
522+ it ( "names each shorthand's slots in grammar order" , ( ) => {
523+ expect ( collectFamilyLonghands ( ) ) . toEqual (
524+ expect . arrayContaining ( [
525+ [
526+ "border-top" ,
527+ [ "border-top-width" , "border-top-style" , "border-top-color" ]
528+ ] ,
529+ [ "outline" , [ "outline-width" , "outline-style" , "outline-color" ] ]
530+ ] )
531+ ) ;
532+ } ) ;
533+
534+ it ( "names them in one order whatever order the table states them in" , ( ) => {
535+ expect (
536+ collectFamilyLonghands (
537+ {
538+ b : {
539+ syntax : "<'b-one'> || <'b-two'>" ,
540+ computed : [ "b-one" , "b-two" ]
541+ } ,
542+ a : {
543+ syntax : "<'a-one'> || <'a-two'>" ,
544+ computed : [ "a-one" , "a-two" ]
545+ }
546+ } ,
547+ [ "a" , "b" ]
548+ )
549+ ) . toEqual ( [
550+ [ "a" , [ "a-one" , "a-two" ] ] ,
551+ [ "b" , [ "b-one" , "b-two" ] ]
552+ ] ) ;
553+ } ) ;
554+
555+ it ( "names none where a slot is a keyword rather than a longhand" , ( ) => {
556+ expect (
557+ collectFamilyLonghands (
558+ { a : { syntax : "none || <length>" , computed : [ "a-one" , "a-two" ] } } ,
559+ [ "a" ]
560+ )
561+ ) . toEqual ( [ ] ) ;
562+ } ) ;
563+
564+ it ( "names none where a type names more than one of the longhands" , ( ) => {
565+ expect (
566+ collectFamilyLonghands (
567+ {
568+ a : { syntax : "<color> || <length>" , computed : [ "a-one" , "a-two" ] } ,
569+ "a-one" : { syntax : "<color>" } ,
570+ "a-two" : { syntax : "<color>" }
571+ } ,
572+ [ "a" ]
573+ )
574+ ) . toEqual ( [ ] ) ;
575+ } ) ;
576+
577+ it ( "names none where the grammar reaches fewer slots than longhands" , ( ) => {
578+ expect (
579+ collectFamilyLonghands (
580+ {
581+ a : {
582+ syntax : "<'a-one'> || <'a-two'>" ,
583+ computed : [ "a-one" , "a-two" , "a-three" ]
584+ }
585+ } ,
586+ [ "a" ]
587+ )
588+ ) . toEqual ( [ ] ) ;
589+ } ) ;
590+
591+ it ( "names none where the grammar is not an order-free alternation" , ( ) => {
592+ expect (
593+ collectFamilyLonghands (
594+ {
595+ a : { syntax : "<'a-one'> <'a-two'>" , computed : [ "a-one" , "a-two" ] }
596+ } ,
597+ [ "a" ]
598+ )
599+ ) . toEqual ( [ ] ) ;
600+ } ) ;
601+
602+ it ( "names none where the grammar cannot be parsed" , ( ) => {
603+ expect (
604+ collectFamilyLonghands (
605+ { a : { syntax : "<" , computed : [ "a-one" , "a-two" ] } } ,
606+ [ "a" ]
607+ )
608+ ) . toEqual ( [ ] ) ;
609+ } ) ;
610+
611+ it ( "names none where the entry states no syntax or no longhands" , ( ) => {
612+ expect (
613+ collectFamilyLonghands (
614+ {
615+ a : { computed : [ "a-one" , "a-two" ] } ,
616+ b : { syntax : "<'b-one'> || <'b-two'>" } ,
617+ c : { syntax : "<'c-one'> || <'c-two'>" , computed : [ "c-one" ] }
618+ } ,
619+ [ "a" , "b" , "c" ]
620+ )
621+ ) . toEqual ( [ ] ) ;
622+ } ) ;
623+
624+ it ( "names none for a shorthand no verified list holds" , ( ) => {
625+ expect (
626+ collectFamilyLonghands (
627+ {
628+ a : {
629+ syntax : "<'a-one'> || <'a-two'>" ,
630+ computed : [ "a-one" , "a-two" ]
631+ }
632+ } ,
633+ [ ]
634+ )
635+ ) . toEqual ( [ ] ) ;
636+ } ) ;
637+
638+ it ( "names none where a slot is not one of the longhands" , ( ) => {
639+ expect (
640+ collectFamilyLonghands (
641+ {
642+ a : { syntax : "<'x'> || <'a-two'>" , computed : [ "a-one" , "a-two" ] }
643+ } ,
644+ [ "a" ]
645+ )
646+ ) . toEqual ( [ ] ) ;
647+ } ) ;
648+ } ) ;
649+
486650 describe ( "the guards on what those datasets still publish" , ( ) => {
487651 it ( "accepts a `syntaxes.json` that states no class the SUPPLEMENT does" , ( ) => {
488652 expect ( ( ) => checkStatedClassSpellings ( { } ) ) . not . toThrow ( ) ;
0 commit comments