@@ -460,6 +460,19 @@ def test_interpolated_class_attribute():
460460 assert str (node ) == '<button class="btn btn-primary active">Click me</button>'
461461
462462
463+ def test_interpolated_class_attribute_with_multiple_placeholders ():
464+ classes1 = ["btn" , "btn-primary" ]
465+ classes2 = [False and "disabled" , None , {"active" : True }]
466+ node = html (t '<button class="{classes1} {classes2}">Click me</button>' )
467+ # CONSIDER: Is this what we want? Currently, when we have multiple
468+ # placeholders in a single attribute, we treat it as a string attribute.
469+ assert node == Element (
470+ "button" ,
471+ attrs = {"class" : "['btn', 'btn-primary'] [False, None, {'active': True}]" },
472+ children = [Text ("Click me" )],
473+ )
474+
475+
463476def test_interpolated_attribute_spread_with_class_attribute ():
464477 attrs = {"id" : "button1" , "class" : ["btn" , "btn-primary" ]}
465478 node = html (t "<button {attrs}>Click me</button>" )
@@ -471,6 +484,52 @@ def test_interpolated_attribute_spread_with_class_attribute():
471484 assert str (node ) == '<button id="button1" class="btn btn-primary">Click me</button>'
472485
473486
487+ def test_interpolated_attribute_value_embedded_placeholder ():
488+ slug = "item42"
489+ node = html (t "<div data-id='prefix-{slug}'></div>" )
490+ assert node == Element (
491+ "div" ,
492+ attrs = {"data-id" : "prefix-item42" },
493+ children = [],
494+ )
495+ assert str (node ) == '<div data-id="prefix-item42"></div>'
496+
497+
498+ def test_interpolated_attribute_value_with_static_prefix_and_suffix ():
499+ counter = 3
500+ node = html (t '<div data-id="item-{counter}-suffix"></div>' )
501+ assert node == Element (
502+ "div" ,
503+ attrs = {"data-id" : "item-3-suffix" },
504+ children = [],
505+ )
506+ assert str (node ) == '<div data-id="item-3-suffix"></div>'
507+
508+
509+ def test_interpolated_attribute_value_multiple_placeholders ():
510+ start = 1
511+ end = 5
512+ node = html (t '<div data-range="{start}-{end}"></div>' )
513+ assert node == Element (
514+ "div" ,
515+ attrs = {"data-range" : "1-5" },
516+ children = [],
517+ )
518+ assert str (node ) == '<div data-range="1-5"></div>'
519+
520+
521+ def test_interpolated_attribute_value_multiple_placeholders_no_quotes ():
522+ start = 1
523+ end = 5
524+ node = html (t "<div data-range={start}-{end}></div>" )
525+ assert node == Element (
526+ "div" ,
527+ attrs = {"data-range" : "1-5" },
528+ children = [],
529+ )
530+ assert str (node ) == '<div data-range="1-5"></div>'
531+
532+
474533def test_interpolated_data_attributes ():
475534 data = {"user-id" : 123 , "role" : "admin" , "wild" : True }
476535 node = html (t "<div data={data}>User Info</div>" )
@@ -485,6 +544,13 @@ def test_interpolated_data_attributes():
485544 )
486545
487546
547+ def test_interpolated_data_attribute_multiple_placeholders ():
548+ confusing = {"user-id" : "user-123" }
549+ placeholders = {"role" : "admin" }
550+ with pytest .raises (TypeError ):
551+ _ = html (t '<div data="{confusing} {placeholders}">User Info</div>' )
552+
553+
488554def test_interpolated_aria_attributes ():
489555 aria = {"label" : "Close" , "hidden" : True , "another" : False , "more" : None }
490556 node = html (t "<button aria={aria}>X</button>" )
@@ -499,6 +565,13 @@ def test_interpolated_aria_attributes():
499565 )
500566
501567
568+ def test_interpolated_aria_attribute_multiple_placeholders ():
569+ confusing = {"label" : "Close" }
570+ placeholders = {"hidden" : True }
571+ with pytest .raises (TypeError ):
572+ _ = html (t '<button aria="{confusing} {placeholders}">X</button>' )
573+
574+
502575def test_interpolated_style_attribute ():
503576 styles = {"color" : "red" , "font-weight" : "bold" , "font-size" : "16px" }
504577 node = html (t "<p style={styles}>Warning!</p>" )
@@ -513,6 +586,19 @@ def test_interpolated_style_attribute():
513586 )
514587
515588
589+ def test_interpolated_style_attribute_multiple_placeholders ():
590+ styles1 = {"color" : "red" }
591+ styles2 = {"font-weight" : "bold" }
592+ node = html (t "<p style='{styles1} {styles2}'>Warning!</p>" )
593+ # CONSIDER: Is this what we want? Currently, when we have multiple
594+ # placeholders in a single attribute, we treat it as a string attribute.
595+ assert node == Element (
596+ "p" ,
597+ attrs = {"style" : "{'color': 'red'} {'font-weight': 'bold'}" },
598+ children = [Text ("Warning!" )],
599+ )
600+
601+
516602def test_style_attribute_str ():
517603 styles = "color: red; font-weight: bold;"
518604 node = html (t "<p style={styles}>Warning!</p>" )
0 commit comments