Debian Codegraph @

debian/rust-vendor/crc-catalog/generate_tests.sh

raw
1 #!/bin/sh
2
3 echo "#![allow(non_snake_case)]"
4 echo "use crate::Algorithm;"
5
6 curl -s https://reveng.sourceforge.io/crc-catalogue/all.htm | grep -o 'width.*name.*"' | while read -r line; do
7 # echo $(echo $line | \
8 # sed 's/ /, /g' | \
9 # sed 's/[-\/]/_/g' | \
10 # sed 's/width=\([0-9]*\), \(.*\), name="\(.*\)"/pub const \3: Algorithm<u\1> = Algorithm { \2 };/')
11
12 width=$(echo $line | sed 's/width=\([0-9]*\) \(.*\) name="\(.*\)"/\1/')
13 params=$(echo $line | sed 's/width=\([0-9]*\) \(.*\) name="\(.*\)"/\2/' | sed 's/ /, /g' | sed 's/=/: /g')
14 name=$(echo $line | sed 's/width=\([0-9]*\) \(.*\) name="\(.*\)"/\3/' | sed 's/[-\/]/_/g')
15
16 echo "#[test]"
17 echo "fn test_$name() {"
18 echo -n " "
19 if [ $width -le 8 ]; then
20 echo "pub const $name: Algorithm<u8> = Algorithm { width: $width, $params };"
21 elif [ $width -le 16 ]; then
22 echo "pub const $name: Algorithm<u16> = Algorithm { width: $width, $params };"
23 elif [ $width -le 32 ]; then
24 echo "pub const $name: Algorithm<u32> = Algorithm { width: $width, $params };"
25 elif [ $width -le 64 ]; then
26 echo "pub const $name: Algorithm<u64> = Algorithm { width: $width, $params };"
27 elif [ $width -le 128 ]; then
28 echo "pub const $name: Algorithm<u128> = Algorithm { width: $width, $params };"
29 fi
30 echo " assert_eq!($name, crate::algorithm::$name);"
31 echo "}"
32 done