<commit_before>#!/usr/bin/env sh
# Unit tests for the octokit.sh script.

abs_path=$(dirname $0)
SCRIPT="${abs_path}/../octokit.sh"

_main() {
    local cmd ret

    cmd="$1" && shift
    "$cmd" "$@"
    ret=$?

    [ $ret -eq 0 ] || printf 'Fail: %s\n' "$cmd" 1>&2
    exit $ret
}

_main "$@"<commit_msg>Added unit test for _format_json()<commit_after>#!/usr/bin/env sh
# Unit tests for the octokit.sh script.

abs_path=$(dirname $0)
SCRIPT="${abs_path}/../octokit.sh"

_main() {
    local cmd ret

    cmd="$1" && shift
    "$cmd" "$@"
    ret=$?

    [ $ret -eq 0 ] || printf 'Fail: %s\n' "$cmd" 1>&2
    exit $ret
}

test_format_json() {
    # Test output without filtering through jq.

    local output expected_out

    $SCRIPT -j _format_json foo=Foo bar=123 baz=true qux=Qux=Qux quux='Multi-line
string' | {
        read -r output

        expected_out='{"baz": true, "quux": "Multi-line\nstring", "foo": "Foo", "qux": "Qux=Qux", "bar": 123}'

        if [ "$expected_out" = "$output" ] ; then
            return 0
        else
            printf 'Expected output does not match output: `%s` != `%s`\n' \
                "$expected_out" "$output"
            return 1
        fi
    }
}

_main "$@"
{'fraction_non_alphanumeric': 0.18325041459369817, 'fraction_numerical': 0.014925373134328358, 'mean_word_length': 2.458452722063037, 'pattern_counts': {'":': 5, '<': 3, '<?xml version=': 0, '>': 5, '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': '2430042', 'n_tokens_mistral': 475, 'n_tokens_neox': 444, 'n_words': 117}