#!/bin/bash

# v.0.0.0.1
# 24.4.2024

# tests for qbashlib.sh v.0.0.0.2
. ./qbashlib.sh

test_ok=0
test_fail=0

echo "*** 1. is_number ***"
echo "1.1 is_number a"
value="a"
is_number $value
if [ $? -eq 0 ]; then
    echo "OK"
    ((test_ok++))
else
    echo "FAIL"
    ((test_fail++))
fi


echo "1.2 is_number a"
value="1"
is_number $value
if [ $? -eq 1 ]; then
    echo "OK"
    ((test_ok++))
else
    echo "FAIL"
    ((test_fail++))
fi


echo "*** 2. is_email ***"
echo "2.1 is_email a"
value="a"
is_email $value
if [ $? -eq 0 ]; then
    echo "OK"
    ((test_ok++))
else
    echo "FAIL"
    ((test_fail++))
fi


echo "2.2 is_email a@b"
value="a@b"
is_email $value
if [ $? -eq 0 ]; then
    echo "OK"
    ((test_ok++))
else
    echo "FAIL"
    ((test_fail++))
fi

echo "2.3 is_email a@b.com"
value="a@b.com"
is_email $value
if [ $? -eq 1 ]; then
    echo "OK"
    ((test_ok++))
else
    echo "FAIL"
    ((test_fail++))
fi


echo "*** 3. argument_exists ***"
echo "3.1 argument_exists a"
value="a"
argument_exists $value "test"
if [ $? -eq 1 ]; then
    echo "OK"
    ((test_ok++))
else
    echo "FAIL"
    ((test_fail++))
fi

echo "3.2 argument_exists <empty>"
value=""
argument_exists $value "test"
if [ $? -eq 0 ]; then
    echo "OK"
    ((test_ok++))
else
    echo "FAIL"
    ((test_fail++))
fi


# total evaluation
echo "TOTAL $test_ok SUCC / $test_fail FAILED"
if [ $test_fail -eq 0 ]; then
    echo "TEST RESULT: SUCCEED"
    exit 0
else
    echo "TEST RESULT: FAILED"
    exit 1
fi