#!/bin/sh
# Test pwgen options

set -e

# -0 / --no-numerals: no digits
output=$(pwgen -1 -0 20)
if printf '%s' "$output" | grep -q '[0-9]'; then
    echo "no-numerals option failed" >&2
    exit 1
fi

# -A / --no-capitalize: no uppercase letters
output=$(pwgen -1 -A 20)
if printf '%s' "$output" | grep -q '[A-Z]'; then
    echo "no-capitalize option failed" >&2
    exit 1
fi

# -c / --capitalize: at least one uppercase letter
output=$(pwgen -1 -c -n 20)
if ! printf '%s' "$output" | grep -q '[A-Z]'; then
    echo "capitalize option failed" >&2
    exit 1
fi

# -n / --numerals: at least one digit
output=$(pwgen -1 -n 20)
if ! printf '%s' "$output" | grep -q '[0-9]'; then
    echo "numerals option failed" >&2
    exit 1
fi

# -y / --symbols: at least one symbol
output=$(pwgen -1 -y 20)
if ! printf '%s' "$output" | grep -q '[^A-Za-z0-9]'; then
    echo "symbols option failed" >&2
    exit 1
fi

# -B / --ambiguous: no ambiguous characters
output=$(pwgen -1 -B 20)
if printf '%s' "$output" | grep -q '[0O1lI]'; then
    echo "ambiguous option failed" >&2
    exit 1
fi

# -v / --no-vowels: no vowels
output=$(pwgen -1 -v 20)
if printf '%s' "$output" | grep -q '[aeiouAEIOU]'; then
    echo "no-vowels option failed" >&2
    exit 1
fi

# -r / --remove-chars: removed characters should not appear
output=$(pwgen -1 -r abc 20)
if printf '%s' "$output" | grep -q '[abc]'; then
    echo "remove-chars option failed" >&2
    exit 1
fi

# -s / --secure: completely random passwords
output=$(pwgen -1 -s 20)
test "${#output}" -eq 20

echo "options tests passed"
