<commit_before>#!/bin/sh

assert()
{
    local name=$1
    local sub=$2

    if [[ -z "$sub" ]]
    then
        return 1
    fi

    local OK="\\033[1;32m"
    local NOK="\\033[1;31m"
    local RAZ="\\033[0;39m"
    cols=15

    if [[ "$PS1" == *$sub* ]]
    then
        printf "\e${OK}%-${cols}s %-${cols}s\n${RAZ}" "$name" "OK"
    else
        printf "\e${NOK}%-${cols}s %-${cols}s\n${RAZ}" "$name" "$sub"
    fi
}


#####################
# REDEFINE COMMANDS #
#####################

command()
{
    echo "fake command $@" 1>&2
    echo "/bin/fake"
}

uname()
{
    echo "fake uname $@" 1>&2
    echo Linux
}

nproc()
{
    echo "fake nproc $@" 1>&2
    echo 2
}

# battery
acpi()
{
    echo "fake acpi $@" 1>&2
    echo 'Battery 0: Discharging, 55%, 01:39:34 remaining'
}


git()
{
    echo "fake git $@" 1>&2
    case $1 in
        "rev-parse" )
            echo ".git";;
        "branch" )
            echo "* fake_test";;
        "diff" )
            echo "";;
        "status" )
            echo "# Untracked";;
        "rev-list" )
            echo "111";;
    esac
}

# global variables
export http_proxy="fake"


##########################
# Call the liquid prompt #
##########################

# As if we were in an interactive shell
export PS1="fake prompt \$"
# load functions
source ./liquidprompt

# Force liquid prompt function redefinition
_lp_cpu_load()
{
    echo "fake _lp_cpu_load $@" 1>&2
    echo "0.64"
}


################
# ADHOC CONFIG #
################

export LP_BATTERY_THRESHOLD=60
export LP_LOAD_THRESHOLD=1
export LP_MARK_PROXY="proxy"
export LP_MARK_BATTERY="BATT"
export LP_MARK_LOAD="LOAD"
export LP_MARK_UNTRACKED="untracked"
export LP_MARK_GIT="gitmark"


# Force erroneous command
fake_error

# Force set prompt
_lp_set_prompt


#########
# TESTS #
#########

echo -e "$PS1"

assert "Battery Mark" BATT
assert "Battery Level" 55%
assert "Load Mark" LOAD
assert "Load Level" 32%
assert User "[\\\u"
assert Perms :
assert Path $(pwd | sed -e "s|$HOME|~|")
assert Proxy proxy
assert Error 127
# echo GIT
assert "GIT Branch" fake_test
assert "GIT Commits" 111
assert "GIT Untrack" untracked
assert "GIT Mark" gitmark<commit_msg>fix fake git diff for testing changes<commit_after>#!/bin/sh

assert()
{
    local name=$1
    local sub=$2

    if [[ -z "$sub" ]]
    then
        return 1
    fi

    local OK="\\033[1;32m"
    local NOK="\\033[1;31m"
    local RAZ="\\033[0;39m"
    cols=15

    if [[ "$PS1" == *$sub* ]]
    then
        printf "\e${OK}%-${cols}s %-${cols}s\n${RAZ}" "$name" "OK"
    else
        printf "\e${NOK}%-${cols}s %-${cols}s\n${RAZ}" "$name" "$sub"
    fi
}


#####################
# REDEFINE COMMANDS #
#####################

command()
{
    echo "fake command $@" 1>&2
    echo "/bin/fake"
}

uname()
{
    echo "fake uname $@" 1>&2
    echo Linux
}

nproc()
{
    echo "fake nproc $@" 1>&2
    echo 2
}

# battery
acpi()
{
    echo "fake acpi $@" 1>&2
    echo 'Battery 0: Discharging, 55%, 01:39:34 remaining'
}


git()
{
    echo "fake git $@" 1>&2
    case $1 in
        "rev-parse" )
            echo ".git";;
        "branch" )
            echo "* fake_test";;
        "diff" )
            echo "2       1       fake_file"
            return 1;;
        "status" )
            echo "# Untracked";;
        "rev-list" )
            echo 111;;
    esac
}

# global variables
export http_proxy="fake"


##########################
# Call the liquid prompt #
##########################

# As if we were in an interactive shell
export PS1="fake prompt \$"
# load functions
source ./liquidprompt

# Force liquid prompt function redefinition
_lp_cpu_load()
{
    echo "fake _lp_cpu_load $@" 1>&2
    echo "0.64"
}


################
# ADHOC CONFIG #
################

export LP_BATTERY_THRESHOLD=60
export LP_LOAD_THRESHOLD=1
export LP_MARK_PROXY="proxy"
export LP_MARK_BATTERY="BATT"
export LP_MARK_LOAD="LOAD"
export LP_MARK_UNTRACKED="untracked"
export LP_MARK_GIT="gitmark"


# Force erroneous command
fake_error

# Force set prompt
_lp_set_prompt


#########
# TESTS #
#########

echo -e "$PS1"

assert "Battery Mark" BATT
assert "Battery Level" 55%
assert "Load Mark" LOAD
assert "Load Level" 32%
assert User "[\\\u"
assert Perms :
assert Path $(pwd | sed -e "s|$HOME|~|")
assert Proxy proxy
assert Error 127
# echo GIT
assert "GIT Branch" fake_test
assert "GIT Changes" "+2/-1"
assert "GIT Commits" 111
assert "GIT Untrack" untracked
assert "GIT Mark" gitmark
{'fraction_non_alphanumeric': 0.2051455653351388, 'fraction_numerical': 0.03182125930941097, 'mean_word_length': 2.857267188859878, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4448911', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1612, 'n_words': 432}