mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
Co-authored-by: Selis <12716288+ItsSelis@users.noreply.github.com> Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com>
99 lines
3.4 KiB
Plaintext
99 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.
|
|
*/
|
|
/* NOT IMPLEMENTED
|
|
/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 sortList(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'")
|