@@ -392,3 +392,44 @@ def test_get_heading_and_level_non_heading(
392392 label , level = backend ._get_heading_and_level (style_label )
393393 assert label == expected_label
394394 assert level == expected_level
395+
396+
397+ def test_list_counter_and_enum_marker (docx_paths ):
398+ """Test list counter increment, sub-level reset, marker building, and sequence reset."""
399+ docx_path = docx_paths [0 ]
400+ in_doc = InputDocument (
401+ path_or_stream = docx_path ,
402+ format = InputFormat .DOCX ,
403+ backend = MsWordDocumentBackend ,
404+ )
405+ backend = in_doc ._backend
406+
407+ # Basic increment
408+ assert backend ._get_list_counter (1 , 0 ) == 1
409+ assert backend ._get_list_counter (1 , 0 ) == 2
410+ assert backend ._get_list_counter (1 , 1 ) == 1
411+ assert backend ._get_list_counter (1 , 1 ) == 2
412+ assert backend ._get_list_counter (1 , 1 ) == 3
413+
414+ # Advancing parent level resets sub-levels
415+ backend ._get_list_counter (1 , 2 ) # (1,2) = 1
416+ backend ._get_list_counter (1 , 0 ) # (1,0) = 3, resets lvl 1 and 2
417+ assert backend .list_counters [(1 , 1 )] == 0
418+ assert backend .list_counters [(1 , 2 )] == 0
419+ assert backend ._get_list_counter (1 , 1 ) == 1 # restarts from 1
420+
421+ # Hierarchical enum markers
422+ backend .list_counters [(1 , 0 )] = 2
423+ backend .list_counters [(1 , 1 )] = 3
424+ backend .list_counters [(1 , 2 )] = 1
425+ assert backend ._build_enum_marker (1 , 0 ) == "2."
426+ assert backend ._build_enum_marker (1 , 1 ) == "2.3."
427+ assert backend ._build_enum_marker (1 , 2 ) == "2.3.1."
428+ assert backend ._build_enum_marker (99 , 0 ) == "1." # missing counter defaults to 1
429+
430+ # Reset sequence for a specific numid
431+ backend ._get_list_counter (2 , 0 ) # (2,0) = 1
432+ backend ._reset_list_counters_for_new_sequence (1 )
433+ assert backend .list_counters [(1 , 0 )] == 0
434+ assert backend .list_counters [(1 , 1 )] == 0
435+ assert backend .list_counters [(2 , 0 )] == 1 # unaffected
0 commit comments