<commit_before>#!/usr/bin/env bash

set -e
set -o pipefail

t() {
	echo -e "test: \033[1;32m$1\033[0m"
}

t "exits 1 when run without arguments"
(! git pair >/dev/null)

t "prints help when run without arguments"
output=$(! git pair)
echo $output | grep Usage >/dev/null

t "'help' prints something helpful"
git pair help | grep Usage >/dev/null

t "'add' creates ~/.gitpairables with one entry"
expect /tests/expect_add_test.exp >/dev/null
[ -e ~/.gitpairables ]
cat ~/.gitpairables | wc -l >/dev/null 2>&1

t "'add' stores the original name and email if run the first time"
[ -e ~/.gitpairables ] && rm ~/.gitpairables
git config --global user.name '<NAME>'
git config --global user.email '<EMAIL>'
expect /tests/expect_add_test.exp >/dev/null
git pair list | grep __original__ >/dev/null

t "'add' does not re-add if the nickname already exists"
expect /tests/expect_add_test.exp >/dev/null
expect /tests/expect_add_test_different_case.exp >/dev/null
[ $(git pair list | grep test | wc -l | tr -d ' ') = 1 ]

t "'list' prints details of pairs"
expect /tests/expect_add_test.exp >/dev/null
git pair list | grep test >/dev/null

t "'set' changes global config to provided pairs"
expect /tests/expect_add_one.exp >/dev/null
expect /tests/expect_add_two.exp >/dev/null
git pair set one two >/dev/null
[ "$(git config --global --get user.name)" = 'One and Two' ]
[ "$(git config --global --get user.email)" = '<EMAIL>' ]

t "'set' does nothing if the provided nicknames don't exist"
original_name=$(git config --global --get user.name)
original_email=$(git config --global --get user.email)
! git pair set blah bleh
[ "$original_name" = "$(git config --global --get user.name)" ]
[ "$original_email" = "$(git config --global --get user.email)" ]

t "'reset' sets name and email back to the original settings"
[ -e ~/.gitpairables ] && rm ~/.gitpairables
git config --global user.name '<NAME>'
git config --global user.email '<EMAIL>'
expect /tests/expect_add_one.exp >/dev/null
git pair set one >/dev/null
git pair reset >/dev/null
[ "$(git config --get --global user.name)" = '<NAME>' ]
[ "$(git config --get --global user.email)" = '<EMAIL>' ]

t "'reset' exits 1 if there is no original name set"
[ -e ~/.gitpairables ] && rm ~/.gitpairables
git config --global --unset user.name
git config --global --unset user.email
expect /tests/expect_add_one.exp >/dev/null
git pair set one >/dev/null
(! git pair reset)<commit_msg>Remove gitpairables file as part of test setup<commit_after>#!/usr/bin/env bash

set -e
set -o pipefail

t() {
	[ -e ~/.gitpairables ] && rm ~/.gitpairables
	echo -e "test: \033[1;32m$1\033[0m"
}

t "exits 1 when run without arguments"
(! git pair >/dev/null)

t "prints help when run without arguments"
output=$(! git pair)
echo $output | grep Usage >/dev/null

t "'help' prints something helpful"
git pair help | grep Usage >/dev/null

t "'add' creates ~/.gitpairables with one entry"
expect /tests/expect_add_test.exp >/dev/null
[ -e ~/.gitpairables ]
cat ~/.gitpairables | wc -l >/dev/null 2>&1

t "'add' stores the original name and email if run the first time"
git config --global user.name '<NAME>'
git config --global user.email '<EMAIL>'
expect /tests/expect_add_test.exp >/dev/null
git pair list | grep __original__ >/dev/null

t "'add' does not re-add if the nickname already exists"
expect /tests/expect_add_test.exp >/dev/null
expect /tests/expect_add_test_different_case.exp >/dev/null
[ $(git pair list | grep test | wc -l | tr -d ' ') = 1 ]

t "'list' prints details of pairs"
expect /tests/expect_add_test.exp >/dev/null
git pair list | grep test >/dev/null

t "'set' changes global config to provided pairs"
expect /tests/expect_add_one.exp >/dev/null
expect /tests/expect_add_two.exp >/dev/null
git pair set one two >/dev/null
[ "$(git config --global --get user.name)" = '<NAME>' ]
[ "$(git config --global --get user.email)" = '<EMAIL>' ]

t "'set' does nothing if the provided nicknames don't exist"
original_name=$(git config --global --get user.name)
original_email=$(git config --global --get user.email)
! git pair set blah bleh
[ "$original_name" = "$(git config --global --get user.name)" ]
[ "$original_email" = "$(git config --global --get user.email)" ]

t "'reset' sets name and email back to the original settings"
git config --global user.name '<NAME>'
git config --global user.email '<EMAIL>'
expect /tests/expect_add_one.exp >/dev/null
git pair set one >/dev/null
git pair reset >/dev/null
[ "$(git config --get --global user.name)" = '<NAME>' ]
[ "$(git config --get --global user.email)" = '<EMAIL>' ]

t "'reset' exits 1 if there is no original name set"
git config --global --unset user.name
git config --global --unset user.email
expect /tests/expect_add_one.exp >/dev/null
git pair set one >/dev/null
(! git pair reset)
{'fraction_non_alphanumeric': 0.15596905707714823, 'fraction_numerical': 0.00669036169767928, 'mean_word_length': 3.67644183773216, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 58, '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': '1593202', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1593, 'n_words': 594}