diff --git a/Tests/subset/svg_test.py b/Tests/subset/svg_test.py
index acaeb57db..bdfc4d68c 100644
--- a/Tests/subset/svg_test.py
+++ b/Tests/subset/svg_test.py
@@ -1,4 +1,5 @@
from string import ascii_letters
+import textwrap
from fontTools.misc.testTools import getXML
from fontTools import subset
@@ -111,3 +112,344 @@ def test_subset_svg_simple(empty_svg_font, tmp_path):
' ]]>',
"",
]
+
+
+# This contains a bunch of cross-references between glyphs, paths, gradients, etc.
+# Note the path coordinates are completely made up and not meant to be rendered.
+# We only care about the tree structure, not it's visual content.
+COMPLEX_SVG = """\
+
+"""
+
+
+def _lines(s):
+ return textwrap.dedent(s).splitlines()
+
+
+@pytest.mark.parametrize(
+ "subset_gids, expected_xml",
+ [
+ # we only keep gid=2, with 'glyph2' defined inside 'glyph1': 'glyph2'
+ # is renamed 'glyph1' to match the new subset indices, and the old 'glyph1'
+ # is kept (as it contains 'glyph2') but renamed '.glyph1' to avoid clash
+ (
+ "2",
+ _lines(
+ """\
+
+
+
+
+
+
+
+
+ ]]>
+
+ """
+ ),
+ ),
+ # we keep both gid 1 and 2: the glyph elements' ids stay as they are (only the
+ # range endGlyphID change); a gradient is kept since it's referenced by glyph1
+ (
+ "1,2",
+ _lines(
+ """\
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ]]>
+
+ """
+ ),
+ ),
+ (
+ # both gid 3 and 6 refer (via