Skip to content

Commit

Permalink
Add tests for searching decimal and lengths units
Browse files Browse the repository at this point in the history
Added 2 new tests:

test_decimal_size test returns an error code when decimal numbers are
detected in width, height, or viewBox attributes. It is impossible to
create a pixel-perfect icon if its size does not fit into the pixel grid.

test_lengths_units returns an error code when any lengths units are set
in width, height, and viewBox attributes. This is protect the icon theme
from icons with mm, inch, and others grids.
Also, the test ban px units, because the pixel grid is a default units
for SVG.

A few tests have been renamed, and its description has been updated.
  • Loading branch information
SmartFinn committed Nov 29, 2023
1 parent 2178c0e commit 10d5cc1
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,38 @@ test: test_short
test-all: test_short test_long

.PHONY: test_short
test_short: test_renderer test_optimization test_svg_elems test_symlinks test_filenames
test_short: test_rendering_glitches test_optimization test_svg_elems test_symlinks test_filenames test_decimal_size test_lengths_units

.PHONY: test_long
test_long: test_xml_struct

.PHONY: test_renderer
test_renderer:
# >>> Searching for icons with renderer bugs
.PHONY: test_rendering_glitches
test_rendering_glitches:
# >>> Searching for icons with rendering glitches
@! LC_ALL=C grep -E -rl --include='*.svg' \
-e 'd="[a-zA-Z0-9 -.]+-\.[a-zA-Z0-9 -.]+"' \
-e 'd="[a-zA-Z0-9 -.]+\s\.[a-zA-Z0-9 -.]+"' \
$(ICON_THEMES)

.PHONY: test_decimal_size
test_decimal_size:
# >>> Detecting decimal numbers in width/height/viewBox attrs
@! LC_ALL=C grep -E -rl --include='*.svg' \
-e '<svg[ ].*(width|height)="[0-9]+\.[0-9]*"' \
-e '<svg[ ].*viewBox="0 0 [0-9]+\.[0-9]+ [0-9]+(|\.[0-9]+)"' \
-e '<svg[ ].*viewBox="0 0 [0-9]+(|\.[0-9]+) [0-9]+\.[0-9]+"' \
$(ICON_THEMES)

.PHONY: test_lengths_units
test_lengths_units:
# >>> Detecting lengths units
@! LC_ALL=C grep -E -r --include='*.svg' \
-e '<svg[ ].*(width|height|viewBox)="[0-9]+(|\.[0-9]*)[a-z]+' \
$(ICON_THEMES)

.PHONY: test_optimization
test_optimization:
# >>> Searching for unoptimized icons
# >>> Searching for non-optimized icons
@! LC_ALL=C grep -E -rl --include='*.svg' \
-e '^<\?xml' \
$(ICON_THEMES)
Expand All @@ -89,13 +105,13 @@ test_symlinks:

.PHONY: test_filenames
test_filenames:
# >>> Searching for invalid filenames
# >>> Searching for invalid icon names
@LC_ALL=C find $(ICON_THEMES) -not -iregex '[-_/\.+@a-z0-9]+' -print \
-exec false '{}' +

.PHONY: test_xml_struct
test_xml_struct:
# >>> Searching for broken SVG icons
# >>> Searching for non-valid SVG files
@find $(ICON_THEMES) -type f -name '*.svg' \
-exec xmlstarlet validate --list-bad '{}' +

Expand Down

0 comments on commit 10d5cc1

Please sign in to comment.