scour/unittests
Niels Thykier d6406a3470 shortenIDs: Avoid pointless renames of IDs
With the current code, scour could do a pointless remap of an ID,
where there is no benefit in it.  Consider:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 <defs>
  <rect id="a" width="80" height="50" fill="red"/>
  <rect id="b" width="80" height="50" fill="blue"/>
 </defs>
 <use xlink:href="#a"/>
 <use xlink:href="#b"/>
 <use xlink:href="#b"/>
</svg>
```

In this example, there is no point in swapping the IDs - even if "#b"
is used more often than "#a", they have the same length.  Besides a
performance win on an already scour'ed image, it also mean scour will
behave like a function with a fixed-point (i.e. scour eventually stops
altering the image).

To solve this, we no longer check whether an we find exactly the same
ID.  Instead, we look at the length of the new ID compared to the
original.  This gives us a slight complication as we can now "reserve"
a "future" ID to avoid the rename.

Thanks to Eduard "Ede_123" Braun for providing the test case.

Signed-off-by: Niels Thykier <niels@thykier.net>
2018-04-15 17:34:24 +00:00
..
adobe.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
cascading-default-attribute-removal.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
cdata.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
collapse-gradients-gradientUnits.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
collapse-gradients.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
collapse-same-path-points.svg Fix a unittest that failed due to the increased accuracy of paths after 29e005bf7b 2016-08-31 06:32:05 +02:00
collapse-straight-path-segments.svg Improve and fix behaviour when collapsing straight paths segments (#146) 2017-05-18 00:53:25 +02:00
color-formats.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
comment-beside-xml-decl.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
comments.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
commonized-referenced-elements.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
css-reference.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
descriptive-elements-with-text.svg Add options to remove descriptive elements (#102) 2016-08-29 21:05:12 +02:00
doctype.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
dont-collapse-gradients.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
dont-convert-short-color-names.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
duplicate-gradient-stops-pct.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
duplicate-gradient-stops.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
duplicate-gradients-update-style.svg Fix replacement of duplicate gradients if "fill/stroke" contains fallbacks (#109) 2016-09-05 22:44:55 +02:00
empty-descriptive-elements.svg Add options to remove descriptive elements (#102) 2016-08-29 21:05:12 +02:00
empty-g.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
empty-style.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
encoding-iso-8859-15.svg Unittests: Add a test for proper decoding of ISO 8859-15 2015-12-09 21:32:18 +01:00
encoding-utf8.svg Unittests: Add a test for proper decoding of ISO 8859-15 2015-12-09 21:32:18 +01:00
entities.svg tests: Add unit tests for the escaping of quote characters in attribute values 2017-09-03 18:07:27 +02:00
fill-none.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
flowtext-less.svg add option to check and warn or bail out on flowtext 2016-04-02 16:49:10 +02:00
flowtext.svg add option to check and warn or bail out on flowtext 2016-04-02 16:49:10 +02:00
font-styles.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
full-descriptive-elements.svg Add options to remove descriptive elements (#102) 2016-08-29 21:05:12 +02:00
gradient-default-attrs.svg Add unittests for #66 2016-08-26 23:45:44 +02:00
group-creation.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
group-no-creation-tspan.svg Only attempt to group elements that the content model allows to be children of a <g> when --create-groups is specified. (#98) 2016-08-29 02:33:13 +02:00
group-no-creation.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
groups-in-switch-with-id.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
groups-in-switch.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
groups-with-title-desc.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
ids-protect.svg Add unittests for --protect-ids-_ options 2016-09-18 18:29:13 +02:00
ids-to-strip.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
ids.svg Allow elements to be found via Document.getElementById() in the minidom document returned by scourXmlFile() (#68) 2016-08-25 21:13:09 +02:00
important-groups-in-defs.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
inkscape.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
minimal.svg Add unittests which emulate calling the scour module from command line 2016-09-18 17:13:00 +02:00
move-common-attributes-to-grandparent.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
move-common-attributes-to-parent.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
nested-defs.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
nested-useless-groups.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
no-collapse-lines.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
orient-marker.svg Fix improper comparison of numeric default attribute values with textvalues resulting in wrongly removed attributes (#101) 2016-08-29 06:37:28 +02:00
overflow-marker.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
overflow-svg.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-abs-to-rel.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-bez-optimize.svg Fix conversion of cubic Bézier "curveto" commands into "shorthand/smooth curveto" commands. (#110) 2016-09-06 01:43:36 +02:00
path-elliptical-flags.svg Fix handling of boolean flags in elliptical path commands (#183) 2018-04-08 15:32:47 +02:00
path-empty-move.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-implicit-line.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-line-optimize.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-no-optimize.svg Add a check to prevent we make path data longer by "optimization" 2016-08-31 07:06:42 +02:00
path-precision-control-points.svg Add unittest for --set-c-precision (7cb0d36d72) 2017-02-25 19:44:18 +01:00
path-precision.svg Improve and fix behaviour when collapsing straight paths segments (#146) 2017-05-18 00:53:25 +02:00
path-quad-optimize.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-simple-triangle.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-sn.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-truncate-zeros-calc.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-truncate-zeros.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-use-scientific-notation.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
path-with-caps.svg Improve and fix behaviour when collapsing straight paths segments (#146) 2017-05-18 00:53:25 +02:00
path-with-closepath.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
polygon-coord-neg-first.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
polygon-coord-neg.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
polygon-coord.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
polygon.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
polyline-coord-neg-first.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
polyline-coord-neg.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
polyline-coord.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
protection.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
quot-in-url.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
quotes-in-styles.svg tests: Add unit tests for preservation of quotes in CSS styles 2017-09-03 18:07:27 +02:00
raster-formats.svg Add unittests for embedding rasters (and --disable-embed-rasters) 2016-09-23 23:14:56 +02:00
raster-paths-local.svg Exclude (system specific) absolute paths from test file and add a unittest that creates/tests absolute paths on-the-fly 2016-09-23 23:16:19 +02:00
raster-paths-remote.svg Add unittests for embedding rasters (and --disable-embed-rasters) 2016-09-23 23:14:56 +02:00
raster.gif Add three images (for usage with a future unittest) 2016-09-18 22:41:24 +02:00
raster.jpg Add three images (for usage with a future unittest) 2016-09-18 22:41:24 +02:00
raster.png Add three images (for usage with a future unittest) 2016-09-18 22:41:24 +02:00
redundant-svg-namespace.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
referenced-elements-1.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
referenced-font.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
refs-in-defs.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
remove-duplicate-gradients.svg Fix replacement of duplicate gradients if "fill/stroke" contains fallbacks (#109) 2016-09-05 22:44:55 +02:00
remove-unused-attributes-on-parent.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
scour-lengths.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
shorten-ids-stable-output.svg shortenIDs: Avoid pointless renames of IDs 2018-04-15 17:34:24 +00:00
shorten-ids.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
sodipodi.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
straight-curve.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
stroke-none.svg Add unittests for 1cde426009 and 641d2db08a392e4a7df20c700e1accb9cd8d1341 2016-09-11 00:16:17 +02:00
stroke-nowidth.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
stroke-transparent.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
style-cdata.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
style-to-attr.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
style.svg Throw some line breaks in there... 2016-09-11 14:03:31 +02:00
transform-matrix-is-identity.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-rotate-45.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-rotate-90.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-rotate-135.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-rotate-225.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-rotate-neg-45.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-rotate-neg-90.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-scale-2-3.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-scale-neg-1.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-matrix-is-translate.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-rotate-fold-3args.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-rotate-is-identity.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-rotate-trim-range-719.5.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-rotate-trim-range-neg-540.0.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-skewX-is-identity.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-skewY-is-identity.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
transform-translate-is-identity.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
unreferenced-defs.svg Don't remove unreferenced defs if --keep-unreferenced-defs is specified (#62) 2016-08-14 18:52:55 +02:00
unreferenced-font.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
unreferenced-linearGradient.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
unreferenced-pattern.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
unreferenced-radialGradient.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
useless-defs.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
viewbox-create.svg Unittests for --enable-viewboxing 2017-02-19 16:10:01 +01:00
viewbox-remove.svg Unittests for --enable-viewboxing 2017-02-19 16:10:01 +01:00
whitespace-defs.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
whitespace-important.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
whitespace-nested.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
xml-namespace-attrs.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
xml-ns-decl.svg Restore unittests from history 2015-12-06 19:59:06 +01:00
xml-space.svg Add unittest for --strip-xml-space 2016-09-18 17:13:00 +02:00
xml-well-formed.svg Unittests: Account for b979fe19e5 (fix one test and add two more) 2015-12-07 00:33:08 +01:00