@@ -708,6 +708,12 @@ def test_encodes_the_weird_map_from_qs(self) -> None:
708708 pytest .param ({"a" : {"b" : True }}, "a%5Bb%5D=true" , id = "nested-true" ),
709709 pytest .param ({"b" : False }, "b=false" , id = "top-level-false" ),
710710 pytest .param ({"b" : {"c" : False }}, "b%5Bc%5D=false" , id = "nested-false" ),
711+ pytest .param ({"a" : {"b" : [True , False ]}}, "a%5Bb%5D%5B0%5D=true&a%5Bb%5D%5B1%5D=false" , id = "list-boolean" ),
712+ pytest .param (
713+ {"a" : {"b" : [True , False , None , True ]}},
714+ "a%5Bb%5D%5B0%5D=true&a%5Bb%5D%5B1%5D=false&a%5Bb%5D%5B2%5D=&a%5Bb%5D%5B3%5D=true" ,
715+ id = "list-boolean-with-null" ,
716+ ),
711717 ],
712718 )
713719 def test_encodes_boolean_values (self , data : t .Mapping [str , t .Any ], expected : str ) -> None :
@@ -1805,3 +1811,73 @@ def test_encode_comma_format_serializes_datetime_without_custom_callable(self) -
18051811 dt = datetime (2024 , 1 , 1 )
18061812 options = EncodeOptions (list_format = ListFormat .COMMA , serialize_date = "iso" )
18071813 assert encode ({"a" : [dt ]}, options ) == f"a={ dt .isoformat ().replace (':' , '%3A' )} "
1814+
1815+ @pytest .mark .parametrize (
1816+ "data, list_format, expected" ,
1817+ [
1818+ # ListFormat.COMMA
1819+ pytest .param ({"a" : [True ]}, ListFormat .COMMA , "a=true" , id = "bool-comma" ),
1820+ pytest .param ({"a" : [True , False ]}, ListFormat .COMMA , "a=true,false" , id = "bools-comma" ),
1821+ pytest .param (
1822+ {"a" : {"b" : [True , False ]}},
1823+ ListFormat .COMMA ,
1824+ "a[b]=true,false" ,
1825+ id = "nested-bools-comma" ,
1826+ ),
1827+ pytest .param (
1828+ {"a" : {"b" : [True , False , None , True ]}},
1829+ ListFormat .COMMA ,
1830+ "a[b]=true,false,,true" ,
1831+ id = "nested-bools-with-null-comma" ,
1832+ ),
1833+ # ListFormat.BRACKETS
1834+ pytest .param ({"a" : [True ]}, ListFormat .BRACKETS , "a[]=true" , id = "bool-brackets" ),
1835+ pytest .param ({"a" : [True , False ]}, ListFormat .BRACKETS , "a[]=true&a[]=false" , id = "bools-brackets" ),
1836+ pytest .param (
1837+ {"a" : {"b" : [True , False ]}},
1838+ ListFormat .BRACKETS ,
1839+ "a[b][]=true&a[b][]=false" ,
1840+ id = "nested-bools-brackets" ,
1841+ ),
1842+ pytest .param (
1843+ {"a" : {"b" : [True , False , None , True ]}},
1844+ ListFormat .BRACKETS ,
1845+ "a[b][]=true&a[b][]=false&a[b][]=&a[b][]=true" ,
1846+ id = "nested-bools-with-null-brackets" ,
1847+ ),
1848+ # ListFormat.INDICES
1849+ pytest .param ({"a" : [True ]}, ListFormat .INDICES , "a[0]=true" , id = "bool-indices" ),
1850+ pytest .param ({"a" : [True , False ]}, ListFormat .INDICES , "a[0]=true&a[1]=false" , id = "bools-indices" ),
1851+ pytest .param (
1852+ {"a" : {"b" : [True , False ]}},
1853+ ListFormat .INDICES ,
1854+ "a[b][0]=true&a[b][1]=false" ,
1855+ id = "nested-bools-indices" ,
1856+ ),
1857+ pytest .param (
1858+ {"a" : {"b" : [True , False , None , True ]}},
1859+ ListFormat .INDICES ,
1860+ "a[b][0]=true&a[b][1]=false&a[b][2]=&a[b][3]=true" ,
1861+ id = "nested-bools-with-null-indices" ,
1862+ ),
1863+ # ListFormat.REPEAT
1864+ pytest .param ({"a" : [True ]}, ListFormat .REPEAT , "a=true" , id = "bool-repeat" ),
1865+ pytest .param ({"a" : [True , False ]}, ListFormat .REPEAT , "a=true&a=false" , id = "bools-repeat" ),
1866+ pytest .param (
1867+ {"a" : {"b" : [True , False ]}},
1868+ ListFormat .REPEAT ,
1869+ "a[b]=true&a[b]=false" ,
1870+ id = "nested-bools-repeat" ,
1871+ ),
1872+ pytest .param (
1873+ {"a" : {"b" : [True , False , None , True ]}},
1874+ ListFormat .REPEAT ,
1875+ "a[b]=true&a[b]=false&a[b]=&a[b]=true" ,
1876+ id = "nested-bools-with-null-repeat" ,
1877+ ),
1878+ ],
1879+ )
1880+ def test_encode_serializes_booleans (
1881+ self , data : t .Mapping [str , t .Any ], list_format : ListFormat , expected : str
1882+ ) -> None :
1883+ assert encode (data , EncodeOptions (list_format = list_format , encode = False )) == expected
0 commit comments