mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 04:30:44 +01:00
## About The Pull Request Hey there, This was broken in an update from #74573 (3902973978), the RegEx was only catching a fraction of the cases it was meant to be. This is what we were finding on 74573 version of the RegEx:  This is what we should be finding for all of the cases that `define_sanity` will need to check for:  This is what was broken as a consequence:  As stated in the introductory PR #74333 (ccef887efe), it's not the end of the world if we miss unmanaged local defines, but it's still useful to have this as a maintainability tool to ensure that everything remains as clean as it possibly can. I wish we could do the whole matching method like the aforementioned PR supposed could happen, but it simply doesn't appear to work the way we want it to. ## Changelog Nothing player facing. I tried to experiment with `UNLINT()` but I got absolutely ganked by getting the regex to work, so the fix for the FA Icon file may not be super duper great unfortunately. Let me know if you have a showstopper idea, this is just a stopguard so this PR can get merged and I don't have to keep talking about unmanaged local defines while reviewing PRs.
97 lines
3.4 KiB
Plaintext
97 lines
3.4 KiB
Plaintext
/**
|
|
* This unit test verifies that all Font Awesome icons are present in code, and that all quirk icons are valid.
|
|
*/
|
|
/datum/unit_test/font_awesome_icons
|
|
var/font_awesome_css
|
|
var/list/allowed_icons
|
|
|
|
/datum/unit_test/font_awesome_icons/Run()
|
|
var/font_awesome_file = file('html/font-awesome/css/all.min.css')
|
|
if(isnull(font_awesome_file))
|
|
TEST_FAIL("Font Awesome CSS file could not be found!")
|
|
return
|
|
|
|
font_awesome_css = file2text(font_awesome_file)
|
|
if(isnull(font_awesome_css))
|
|
TEST_NOTICE(src, "Font Awesome CSS file could not be loaded.")
|
|
return
|
|
|
|
load_parse_verify()
|
|
verify_quirk_icons()
|
|
generate_helper_dm_file()
|
|
|
|
/**
|
|
* Loads the Font Awesome CSS file, parses it into a list of icon names, and compares it to the list of icons in code.
|
|
* If there are any differences, note them.
|
|
*/
|
|
/datum/unit_test/font_awesome_icons/proc/load_parse_verify()
|
|
log_test("CSS Actual: [length(font_awesome_css)]")
|
|
allowed_icons = parse_fa_css_into_icon_list(font_awesome_css)
|
|
|
|
/**
|
|
* Verifies that all quirk icons are valid.
|
|
*/
|
|
/datum/unit_test/font_awesome_icons/proc/verify_quirk_icons()
|
|
for(var/datum/quirk/quirk as anything in subtypesof(/datum/quirk))
|
|
if(quirk == initial(quirk.abstract_parent_type))
|
|
continue
|
|
|
|
var/quirk_icon = initial(quirk.icon)
|
|
if(findtext(quirk_icon, "tg-") == 1) // TODO: Validate these as well
|
|
continue
|
|
|
|
if(findtext(quirk_icon, " "))
|
|
var/list/split = splittext(quirk_icon, " ")
|
|
quirk_icon = split[length(split)] // respect modifier classes
|
|
|
|
if(!(quirk_icon in allowed_icons))
|
|
TEST_FAIL("Quirk [initial(quirk.name)]([quirk]) has invalid icon: [quirk_icon]")
|
|
|
|
/// Parses the given Font Awesome CSS file into a list of icon names.
|
|
/datum/unit_test/font_awesome_icons/proc/parse_fa_css_into_icon_list(css)
|
|
css = replacetext(css, "\n", "")
|
|
var/list/css_entries = splittext(css, "}")
|
|
var/list/icons = list()
|
|
for(var/entry in css_entries)
|
|
entry = replacetext(entry, "\t", "")
|
|
if(!length(entry))
|
|
continue
|
|
|
|
var/entry_contents = splittext(entry, "{")
|
|
var/list/entry_names = splittext(entry_contents[1], ",")
|
|
for(var/entry_name in entry_names)
|
|
entry_names -= entry_name
|
|
|
|
if(!findtext(entry_name, ":"))
|
|
continue
|
|
|
|
entry_name = splittext(entry_name, ":")[1]
|
|
if(!findtext(entry_name, ".fa-"))
|
|
continue
|
|
|
|
entry_name = replacetext(entry_name, ".fa-", "fa-")
|
|
entry_names |= entry_name
|
|
icons |= entry_names
|
|
|
|
return sort_list(icons)
|
|
|
|
/datum/unit_test/font_awesome_icons/proc/generate_helper_dm_file()
|
|
var/list/output = list()
|
|
output += "/* This file is automatically generated by the unit test. Do not edit it manually."
|
|
output += " * Generating this file is done by running the unit test locally, see the fail message for more details."
|
|
output += " * All valid font awesome icons should be here."
|
|
output += " */"
|
|
output += ""
|
|
|
|
for(var/icon in allowed_icons)
|
|
var/icon_name = replacetext(icon, "fa-", "")
|
|
output += "#define FA_ICON_[uppertext(replacetext(icon_name, "-", "_"))] \"[icon]\"" // #undef FA_ICON_ // we have this here to avoid define_sanity throwing a fit
|
|
|
|
var/output_file = "[output.Join("\n")]\n"
|
|
rustg_file_write(output_file, "data/font_awesome_icons.dm")
|
|
var/current = file2text('code/__DEFINES/font_awesome_icons.dm')
|
|
if(current == output_file)
|
|
return
|
|
|
|
TEST_FAIL("Font Awesome helper file is out of date. Run locally by enabling unit tests, (see _compile_options.dm) and copy 'data/font_awesome_icons.dm' to 'code/__DEFINES/font_awesome_icons.dm'")
|