2024-05-03 14:50:22 +00:00
|
|
|
#! /usr/bin/env sh
|
|
|
|
# Copyright (C) 2024 - 2024:
|
|
|
|
# The Trinitrix Project <bpeetz@b-peetz.de, antifallobst@systemausfall.org>
|
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
2024-05-03 14:40:06 +00:00
|
|
|
#
|
|
|
|
# This file is part of the Trinitry crate for Trinitrix.
|
|
|
|
#
|
|
|
|
# Trinitry is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the Lesser GNU General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of
|
|
|
|
# the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# and the Lesser GNU General Public License along with this program.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# This script generates ./src/tests.rs
|
|
|
|
|
|
|
|
# Library {{{
|
|
|
|
mktmp() {
|
2024-05-03 14:50:22 +00:00
|
|
|
ensure_tmp_dir
|
|
|
|
mktemp -p "$LIB_TEMP_DIR_FOR_SCRIPT"
|
2024-05-03 14:40:06 +00:00
|
|
|
}
|
|
|
|
ensure_tmp_dir() {
|
2024-05-03 14:50:22 +00:00
|
|
|
if ! [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ]; then
|
|
|
|
LIB_TEMP_DIR_FOR_SCRIPT="$(mktemp -d)"
|
|
|
|
export LIB_TEMP_DIR_FOR_SCRIPT
|
|
|
|
fi
|
2024-05-03 14:40:06 +00:00
|
|
|
}
|
|
|
|
remove_tmp_dir() {
|
2024-05-03 14:50:22 +00:00
|
|
|
# The test is here because some scripts still delete this on their own
|
|
|
|
if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ]; then
|
|
|
|
rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"
|
|
|
|
fi
|
2024-05-03 14:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trap remove_tmp_dir EXIT
|
|
|
|
ensure_tmp_dir # ensure that the variable has been set, even in subshells
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
tmp="$(mktmp)"
|
|
|
|
|
|
|
|
curl https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.txt |
|
2024-05-03 14:50:22 +00:00
|
|
|
awk '!/^#/' |
|
|
|
|
awk '!/^[\s\t]*$/' |
|
|
|
|
awk -v s="'" '!/.*s.*/' |
|
2024-05-03 14:40:06 +00:00
|
|
|
|
2024-05-03 14:50:22 +00:00
|
|
|
# This entry contains duplicated spaces, just ignore it
|
|
|
|
awk '!/Power/' |
|
|
|
|
iconv -c -f utf-8 -t ascii \
|
|
|
|
>"$tmp"
|
2024-05-03 14:40:06 +00:00
|
|
|
|
|
|
|
counter=0
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
// DO NOT EDIT
|
|
|
|
// This file is automatically generated by the 'update.sh' file, with data from:
|
|
|
|
// https://raw.githubusercontent.com/minimaxir/big-list-of-naughty-strings/master/blns.txt
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use crate::Trinitry;
|
|
|
|
EOF
|
|
|
|
|
|
|
|
while read -r name; do
|
2024-05-03 14:50:22 +00:00
|
|
|
tmp2="$(mktmp)"
|
|
|
|
printf "%s" "$name" >"$tmp2"
|
|
|
|
if rg '^[A-Za-z0-9_.-]+$' "$tmp2" -q; then
|
|
|
|
cat <<EOF
|
2024-05-03 14:40:06 +00:00
|
|
|
#[test]
|
|
|
|
fn parse_$counter() {
|
|
|
|
let p = Trinitry::new(r##"$name"##).unwrap_or_else(|e| {
|
|
|
|
panic!("{}", e);
|
|
|
|
});
|
|
|
|
assert_eq!(r##"$name"##, &p.to_string());
|
|
|
|
}
|
|
|
|
EOF
|
2024-05-03 14:50:22 +00:00
|
|
|
elif rg '^[A-Za-z0-9_.-]+ [A-Za-z0-9_.(){}<>?!+^@&*~|=,/\\ -]*$' "$tmp2" -q; then
|
|
|
|
cat <<EOF
|
2024-05-03 14:40:06 +00:00
|
|
|
#[test]
|
|
|
|
fn parse_$counter() {
|
|
|
|
let p = Trinitry::new(r##"$name"##).unwrap_or_else(|e| {
|
|
|
|
panic!("{}", e);
|
|
|
|
});
|
|
|
|
assert_eq!(r##"$name"##, &p.to_string());
|
|
|
|
}
|
|
|
|
EOF
|
2024-05-03 14:50:22 +00:00
|
|
|
else
|
|
|
|
cat <<EOF
|
2024-05-03 14:40:06 +00:00
|
|
|
#[test]
|
|
|
|
fn parse_$counter() {
|
|
|
|
let p = Trinitry::new(r##"$name"##);
|
|
|
|
assert!(p.is_err());
|
|
|
|
}
|
|
|
|
EOF
|
2024-05-03 14:50:22 +00:00
|
|
|
fi
|
|
|
|
counter=$((counter + 1))
|
2024-05-03 14:40:06 +00:00
|
|
|
done <"$tmp"
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# vim: ft=sh
|