require "vnd.dovecot.testsuite";
require "spamtest";
require "relational";
require "comparator-i;ascii-numeric";
require "variables";

/*
 * Value
 */

/* Value 3.6 */

test_set "message" text:
X-Spam-Scan-Score: 3.6

Test!
.
;

test_config :set "sieve_spamtest_status_type" "score";
test_config :set "sieve_spamtest_status_header" "X-Spam-Scan-Score: (-?[[:digit:]]+\.[[:digit:]])";
test_config :set "sieve_spamtest_max_value" "10";
test_config :reload "spamtest";

test "Value: 3.6" {
	if spamtest :is "0" {
		test_fail "spamtest not configured or test failed";
	}

	if anyof (spamtest :value "ge" :comparator "i;ascii-numeric" "6")
	{
		if spamtest :matches "*" { }
		test_fail "wrong spam value produced: ${1}";
	}
}

/* Value: 3.8 */

test_set "message" text:
X-Spam-Scan-Score: 3.8

Test!
.
;

test "Value: 3.8" {
	if spamtest :is "0" {
		test_fail "spamtest not configured or test failed";
	}

	if anyof (spamtest :value "ge" :comparator "i;ascii-numeric" "6")
	{
		if spamtest :matches "*" { }
		test_fail "wrong spam value produced: ${1}";
	}
}

/* Value: 5.9 */

test_set "message" text:
X-Spam-Scan-Score: 5.9

Test!
.
;

test "Value: 5.9" {
	if spamtest :is "0" {
		test_fail "spamtest not configured or test failed";
	}

	if not anyof (spamtest :value "ge" :comparator "i;ascii-numeric" "6")
	{
		if spamtest :matches "*" { }
		test_fail "wrong spam value produced: ${1}";
	}
}

/* Value: 6.0 */

test_set "message" text:
X-Spam-Scan-Score: 6.0

Test!
.
;

test "Value: 6.0" {
	if spamtest :is "0" {
		test_fail "spamtest not configured or test failed";
	}

	if not anyof (spamtest :value "ge" :comparator "i;ascii-numeric" "6")
	{
		if spamtest :matches "*" { }
		test_fail "wrong spam value produced: ${1}";
	}
}

/* Value: 6.9 */

test_set "message" text:
X-Spam-Scan-Score: 6.9

Test!
.
;

test "Value: 6.9" {
	if spamtest :is "0" {
		test_fail "spamtest not configured or test failed";
	}

	if not anyof (spamtest :value "ge" :comparator "i;ascii-numeric" "6")
	{
		if spamtest :matches "*" { }
		test_fail "wrong spam value produced: ${1}";
	}
}

/* Value: 7.3 */

test_set "message" text:
X-Spam-Scan-Score: 7.3

Test!
.
;

test "Value: 7.3" {
	if spamtest :is "0" {
		test_fail "spamtest not configured or test failed";
	}

	if not anyof (spamtest :value "ge" :comparator "i;ascii-numeric" "6")
	{
		if spamtest :matches "*" { }
		test_fail "wrong spam value produced: ${1}";
	}
}
