<commit_before>#!/usr/bin/bash

init_config()
{
    echo Creating $1... > /dev/stderr
    cat << __EOF__ > "$1"
HOST=localhost
SERVER=::1:8088
BASE_PATH=api
CURL_EXTRA=-6
KEY=secret

DEBUG_OUTPUT=/dev/null
__EOF__
}

CONFIG="$(dirname "$0")/config.sh"
[ -f "$CONFIG" ] || init_config "$CONFIG"
echo "Using $CONFIG" > /dev/stderr
. "$CONFIG"

# REST interface

request()
{
    SUB_PATH="$1"
    JSON="$2"
    echo POST $SUB_PATH, json: > $DEBUG_OUTPUT
    echo $JSON > $DEBUG_OUTPUT
    echo . > $DEBUG_OUTPUT
    echo '###' Running curl: curl -X POST http://$SERVER/$BASE_PATH/$SUB_PATH $EXTRA -v \
        -H "Content-Type: application/json" -H "Host: $HOST" \
        -d "$JSON" > $DEBUG_OUTPUT
    curl -X POST http://$SERVER/$BASE_PATH/$SUB_PATH $EXTRA -v \
        -H "Content-Type: application/json" -H "Host: $HOST" \
        -d "$JSON" 2> $DEBUG_OUTPUT
}

get()
{
    SUB_PATH="$1"
    [ "x$2" = "x" ] && { echo Parameters missing; exit 1; }
    PARAMS="$2&host=$HOST&key=$KEY"

    echo GET $SUB_PATH, params: > $DEBUG_OUTPUT
    echo $PARAMS > $DEBUG_OUTPUT
    echo . > $DEBUG_OUTPUT
    curl http://$SERVER/$BASE_PATH/$SUB_PATH\?$PARAMS $EXTRA -v \
        -H "Host: $HOST" 2> $DEBUG_OUTPUT
}

# test framework

COUNT=1

run()
{
    "$@" || { echo Failed to run "$@"; exit 1; }
}

expect()
{
    EXPECT="$1"
    RESULT="`${@:2}`"
    EXIT_VALUE=$?
    if [ $EXIT_VALUE != 0 ];then
        echo "Test #$COUNT ($2) failed.. command exited with $EXIT_VALUE"
        echo "Command: ${@:2}"
        exit 1<commit_msg>tests: Fix using numeric IPv6 addresses<commit_after>#!/usr/bin/bash

init_config()
{
    echo Creating $1... > /dev/stderr
    cat << __EOF__ > "$1"
HOST=localhost
SERVER="[::1]:8088"
BASE_PATH=api
CURL_EXTRA=-6
KEY=secret

DEBUG_OUTPUT=/dev/null
__EOF__
}

CONFIG="$(dirname "$0")/config.sh"
[ -f "$CONFIG" ] || init_config "$CONFIG"
echo "Using $CONFIG" > /dev/stderr
. "$CONFIG"

# REST interface

request()
{
    SUB_PATH="$1"
    JSON="$2"
    echo POST $SUB_PATH, json: > $DEBUG_OUTPUT
    echo $JSON > $DEBUG_OUTPUT
    echo . > $DEBUG_OUTPUT
    echo '###' Running curl: curl -g -X POST "http://$SERVER/$BASE_PATH/$SUB_PATH" \
        $EXTRA -v \
        -H "Content-Type: application/json" -H "Host: $HOST" \
        -d "$JSON" > $DEBUG_OUTPUT
    curl -g -X POST "http://$SERVER/$BASE_PATH/$SUB_PATH" $EXTRA -v \
        -H "Content-Type: application/json" -H "Host: $HOST" \
        -d "$JSON" 2> $DEBUG_OUTPUT
}

get()
{
    SUB_PATH="$1"
    [ "x$2" = "x" ] && { echo Parameters missing; exit 1; }
    PARAMS="$2&host=$HOST&key=$KEY"

    echo GET $SUB_PATH, params: > $DEBUG_OUTPUT
    echo $PARAMS > $DEBUG_OUTPUT
    echo . > $DEBUG_OUTPUT
    echo '###' Running curl: curl -g "http://$SERVER/$BASE_PATH/$SUB_PATH?$PARAMS" \
        $EXTRA -v \
        -H "Host: $HOST" > $DEBUG_OUTPUT
    curl -g "http://$SERVER/$BASE_PATH/$SUB_PATH?$PARAMS" \
        $EXTRA -v \
        -H "Host: $HOST" 2> $DEBUG_OUTPUT
}

# test framework

COUNT=1

run()
{
    "$@" || { echo Failed to run "$@"; exit 1; }
}

expect()
{
    EXPECT="$1"
    RESULT="`${@:2}`"
    EXIT_VALUE=$?
    if [ $EXIT_VALUE != 0 ];then
        echo "Test #$COUNT ($2) failed.. command exited with $EXIT_VALUE"
        echo "Command: ${@:2}"
        exit 1
{'fraction_non_alphanumeric': 0.18999386126457948, 'fraction_numerical': 0.01565377532228361, 'mean_word_length': 2.745977011494253, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6774049', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1226, 'n_words': 293}