tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate-text-emphasis-style-property-010-tests.sh (2855B)


      1 #!/usr/bin/env bash
      2 
      3 # This script generates tests text-emphasis-style-property-010* except
      4 # 010Cn. The tests generated cover all characters listed in the unicode
      5 # data file which should not have emphasis mark specified in the spec.
      6 # This script downloads UnicodeData.txt from the website of the Unicode
      7 # Consortium and extract the characters form that file. It requires
      8 # python (either 2.5+ or 3.x), awk, and wget to work. Only test files
      9 # are generated by this script. It also outputs a list of all tests it
     10 # generated in the format of Mozilla reftest.list to the stdout. Other
     11 # information has been redirected to the stderr.
     12 
     13 UNICODE_DATA_FILE='UnicodeData.txt'
     14 UNICODE_DATA_URL="http://www.unicode.org/Public/8.0.0/ucd/$UNICODE_DATA_FILE"
     15 UNICODE_DATA_DIGEST='38b17e1118206489a7e0ab5d29d7932212d38838df7d3ec025ecb58e8798ec20'
     16 
     17 TEST_FILE='text-emphasis-style-property-010%s.html'
     18 REF_FILE='text-emphasis-style-property-010-ref.html'
     19 
     20 digest_file() {
     21    python -c "import hashlib;
     22 print(hashlib.sha256(open('$1', 'rb').read()).hexdigest())"
     23 }
     24 
     25 check_file() {
     26    [[ -f "$UNICODE_DATA_FILE" ]] || return 1
     27    digest=`digest_file "$UNICODE_DATA_FILE"`
     28    [[ "$digest" == "$UNICODE_DATA_DIGEST" ]] || return 2
     29 }
     30 
     31 download_data() {
     32    check_file
     33    if [[ $? -eq 2 ]]; then
     34        echo "Removing incorrect data file..." >&2
     35        rm "$UNICODE_DATA_FILE"
     36    fi
     37    wget -nc -O"$UNICODE_DATA_FILE" "$UNICODE_DATA_URL" >&2
     38 
     39    check_file
     40    if [[ $? -ne 0 ]]; then
     41        echo "Failed to get the correct unicode data file!" >&2
     42        exit 1
     43    fi
     44 }
     45 
     46 list_codepoints() {
     47    awk -F';' "\$3 == \"$1\" { print \"    0x\"\$1\",\" }" "$UNICODE_DATA_FILE"
     48 }
     49 
     50 write_test_file() {
     51    filename=`printf "$TEST_FILE" $1`
     52    echo "== $filename $REF_FILE"
     53    cat <<EOF > $filename
     54 <!DOCTYPE html>
     55 <meta charset="utf-8">
     56 <!-- This file was generated automatically by the script
     57     ./support/generate-text-emphasis-style-property-010-tests.sh -->
     58 <title>CSS Test: text-emphasis, $1</title>
     59 <link rel="author" title="Xidorn Quan" href="https://www.upsuper.org">
     60 <link rel="author" title="Mozilla" href="https://www.mozilla.org">
     61 <link rel="help" href="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-style-property">
     62 <meta name="assert" content="Emphasis marks should not be rendered for characters in general category $1">
     63 <link rel="match" href="text-emphasis-style-property-010-ref.html">
     64 <p>Pass if there is nothing rendered below:</p>
     65 <div style="color: white; white-space: pre-wrap; text-emphasis: filled circle red">
     66 <script>
     67  var codepoints = [
     68 `list_codepoints "$1"`
     69  ];
     70  document.write(codepoints.map(function (code) {
     71    return String.fromCodePoint(code);
     72  }).join(' '));
     73 </script>
     74 </div>
     75 EOF
     76 }
     77 
     78 download_data
     79 echo "# START tests from $0"
     80 for c in Zs Zl Zp Cc Cf; do
     81    write_test_file "$c"
     82 done
     83 echo "# END tests from $0"