@@ -763,6 +763,56 @@ def assert_tag_list(x: TagList, contents: list[str]) -> None:
763763 assert_tag_list ("foo" + tl_bar , ["foo" , "bar" ])
764764
765765
766+ def test_taglist_methods ():
767+ # Testing methods from https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
768+ #
769+ # Operation | Result | Notes
770+ # --------- | ------ | -----
771+ # x in s | True if an item of s is equal to x, else False | (1)
772+ # x not in s | False if an item of s is equal to x, else True | (1)
773+ # s + t | the concatenation of s and t | (6)(7)
774+ # s * n or n * s | equivalent to adding s to itself n times | (2)(7)
775+ # s[i] | ith item of s, origin 0 | (3)
776+ # s[i:j] | slice of s from i to j | (3)(4)
777+ # s[i:j:k] | slice of s from i to j with step k | (3)(5)
778+ # len(s) | length of s
779+ # min(s) | smallest item of s
780+ # max(s) | largest item of s
781+ # s.index(x[, i[, j]]) | index of the first occurrence of x in s (at or after index i and before index j) | (8)
782+ # s.count(x) | total number of occurrences of x in s
783+
784+ x = TagList ("foo" , "bar" , "foo" , "baz" )
785+ y = TagList ("a" , "b" , "c" )
786+
787+ assert "bar" in x
788+ assert "qux" not in x
789+
790+ add = x + y
791+ assert isinstance (add , TagList )
792+ assert list (add ) == ["foo" , "bar" , "foo" , "baz" , "a" , "b" , "c" ]
793+
794+ mul = x * 2
795+ assert isinstance (mul , TagList )
796+ assert list (mul ) == ["foo" , "bar" , "foo" , "baz" , "foo" , "bar" , "foo" , "baz" ]
797+
798+ assert x [1 ] == "bar"
799+ assert x [1 :3 ] == TagList ("bar" , "foo" )
800+ assert mul [1 :6 :2 ] == TagList ("bar" , "baz" , "bar" )
801+
802+ assert len (x ) == 4
803+
804+ assert min (x ) == "bar" # pyright: ignore[reportArgumentType]
805+ assert max (x ) == "foo" # pyright: ignore[reportArgumentType]
806+
807+ assert x .index ("foo" ) == 0
808+ assert x .index ("foo" , 1 ) == 2
809+ with pytest .raises (ValueError ):
810+ x .index ("foo" , 1 , 1 )
811+
812+ assert x .count ("foo" ) == 2
813+ assert mul .count ("foo" ) == 4
814+
815+
766816def test_taglist_extend ():
767817 x = TagList ("foo" )
768818 y = ["bar" , "baz" ]
0 commit comments