@@ -960,6 +960,158 @@ test('select.matches()', function(t) {
960
960
sst . end ( )
961
961
} )
962
962
963
+ st . test ( ':dir()' , function ( sst ) {
964
+ var ltr = 'a'
965
+ var rtl = 'أ'
966
+ var neutral = '!'
967
+
968
+ sst . ok (
969
+ matches ( ':dir(ltr)' , h ( 'html' , { dir : 'ltr' } ) ) ,
970
+ 'matching `ltr` if the element has a matching explicit `dir` attribute'
971
+ )
972
+
973
+ sst . ok (
974
+ matches ( ':dir(rtl)' , h ( 'html' , { dir : 'rtl' } ) ) ,
975
+ 'matching `rtl` if the element has a matching explicit `dir` attribute'
976
+ )
977
+
978
+ sst . ok (
979
+ matches ( ':dir(ltr)' , h ( 'html' ) ) ,
980
+ 'matching `ltr` if the element is `html` with no `dir` attribute'
981
+ )
982
+
983
+ sst . ok (
984
+ matches ( ':dir(ltr)' , h ( 'html' , { dir : 'foo' } ) ) ,
985
+ 'matching `ltr` if the element is `html` with an invalid `dir` attribute'
986
+ )
987
+
988
+ sst . ok (
989
+ matches ( ':dir(ltr)' , h ( 'input' , { type : 'tel' } ) ) ,
990
+ 'matching `ltr` if the element is `input[type=tel]` with no `dir` attribute'
991
+ )
992
+
993
+ sst . ok (
994
+ matches ( ':dir(ltr)' , h ( 'input' , { type : 'tel' , dir : 'foo' } ) ) ,
995
+ 'matching `ltr` if the element is `input[type=tel]` with an invalid `dir` attribute'
996
+ )
997
+
998
+ sst . ok (
999
+ matches ( ':dir(ltr)' , h ( 'textarea' , { dir : 'auto' } , ltr ) ) ,
1000
+ 'matching `ltr` if `[dir=auto]` on a textarea and it’s content is BIDI LTR'
1001
+ )
1002
+
1003
+ sst . ok (
1004
+ matches ( ':dir(rtl)' , h ( 'textarea' , { dir : 'auto' } , rtl ) ) ,
1005
+ 'matching `rtl` if `[dir=auto]` on a textarea and it’s content is BIDI RTL'
1006
+ )
1007
+
1008
+ sst . ok (
1009
+ matches ( ':dir(ltr)' , h ( 'textarea' , { dir : 'auto' } , neutral ) ) ,
1010
+ 'matching `ltr` if `[dir=auto]` on a textarea and it’s content is BIDI neutral'
1011
+ )
1012
+
1013
+ sst . ok (
1014
+ matches ( ':dir(ltr)' , h ( 'input' , { dir : 'auto' , value : ltr } ) ) ,
1015
+ 'matching `ltr` if `[dir=auto]` on a text input and it’s value is BIDI LTR'
1016
+ )
1017
+
1018
+ sst . ok (
1019
+ matches (
1020
+ ':dir(rtl)' ,
1021
+ h ( 'input' , { type : 'search' , dir : 'auto' , value : rtl } )
1022
+ ) ,
1023
+ 'matching `rtl` if `[dir=auto]` on a search input and it’s value is BIDI RTL'
1024
+ )
1025
+
1026
+ sst . ok (
1027
+ matches (
1028
+ ':dir(ltr)' ,
1029
+ h ( 'input' , { type : 'url' , dir : 'auto' , value : neutral } )
1030
+ ) ,
1031
+ 'matching `ltr` if `[dir=auto]` on a URL input and it’s value is BIDI neutral'
1032
+ )
1033
+
1034
+ sst . ok (
1035
+ matches ( ':dir(ltr)' , h ( 'input' , { type : 'email' , dir : 'auto' } ) ) ,
1036
+ 'matching `ltr` if `[dir=auto]` on an email input without value'
1037
+ )
1038
+
1039
+ sst . ok (
1040
+ matches ( ':dir(ltr)' , h ( 'p' , { dir : 'auto' } , ltr ) ) ,
1041
+ 'matching `ltr` if `[dir=auto]` and the element has BIDI LTR text'
1042
+ )
1043
+
1044
+ sst . ok (
1045
+ matches ( ':dir(rtl)' , h ( 'p' , { dir : 'auto' } , rtl ) ) ,
1046
+ 'matching `rtl` if `[dir=auto]` and the element has BIDI RTL text'
1047
+ )
1048
+
1049
+ sst . ok (
1050
+ matches ( ':dir(ltr)' , h ( 'p' , { dir : 'auto' } , neutral ) ) ,
1051
+ 'matching `ltr` if `[dir=auto]` and the element has BIDI neutral text'
1052
+ )
1053
+
1054
+ sst . ok (
1055
+ matches ( ':dir(ltr)' , h ( 'p' , { dir : 'auto' } , [ neutral , ltr , rtl ] ) ) ,
1056
+ 'matching `ltr` if `[dir=auto]` and the element has BIDI neutral text followed by LTR text'
1057
+ )
1058
+
1059
+ sst . ok (
1060
+ matches ( ':dir(rtl)' , h ( 'p' , { dir : 'auto' } , [ neutral , rtl , ltr ] ) ) ,
1061
+ 'matching `rtl` if `[dir=auto]` and the element has BIDI neutral text followed by RTL text'
1062
+ )
1063
+
1064
+ sst . ok (
1065
+ matches (
1066
+ ':dir(ltr)' ,
1067
+ h ( 'p' , { dir : 'auto' } , [ neutral , h ( 'script' , rtl ) , ltr ] )
1068
+ ) ,
1069
+ 'matching `ltr` if `[dir=auto]`, ignoring BIDI text in scripts, followed by LTR text'
1070
+ )
1071
+
1072
+ sst . ok (
1073
+ matches (
1074
+ ':dir(rtl)' ,
1075
+ h ( 'p' , { dir : 'auto' } , [ neutral , h ( 'style' , ltr ) , rtl ] )
1076
+ ) ,
1077
+ 'matching `rtl` if `[dir=auto]`, ignoring BIDI text in styles, followed by RTL text'
1078
+ )
1079
+
1080
+ sst . ok (
1081
+ matches (
1082
+ ':dir(ltr)' ,
1083
+ h ( 'p' , { dir : 'auto' } , [ neutral , h ( 'span' , { dir : 'rtl' } , rtl ) , ltr ] )
1084
+ ) ,
1085
+ 'matching `ltr` if `[dir=auto]`, ignoring elements with directions, followed by LTR text'
1086
+ )
1087
+
1088
+ sst . ok (
1089
+ matches (
1090
+ ':dir(rtl)' ,
1091
+ h ( 'p' , { dir : 'auto' } , [ neutral , h ( 'span' , { dir : 'ltr' } , ltr ) , rtl ] )
1092
+ ) ,
1093
+ 'matching `rtl` if `[dir=auto]`, ignoring elements with directions, followed by RTL text'
1094
+ )
1095
+
1096
+ sst . ok (
1097
+ matches (
1098
+ ':dir(ltr)' ,
1099
+ h ( 'bdi' , [ neutral , h ( 'span' , { dir : 'rtl' } , rtl ) , ltr ] )
1100
+ ) ,
1101
+ 'matching `ltr` on `bdi` elements, ignoring elements with directions, followed by LTR text'
1102
+ )
1103
+
1104
+ sst . ok (
1105
+ matches (
1106
+ ':dir(rtl)' ,
1107
+ h ( 'bdi' , [ neutral , h ( 'span' , { dir : 'ltr' } , ltr ) , rtl ] )
1108
+ ) ,
1109
+ 'matching `rtl` on `bdi` elements, ignoring elements with directions, followed by RTL text'
1110
+ )
1111
+
1112
+ sst . end ( )
1113
+ } )
1114
+
963
1115
st . test ( ':root' , function ( sst ) {
964
1116
sst . ok ( matches ( ':root' , h ( 'html' ) ) , 'true if `<html>` in HTML space' )
965
1117
0 commit comments