package filter

import "testing"

func TestEvaluateClassicAndVFaceFields(t *testing.T) {
	article := Article{
		From: "Alice <alice@example.net>", Subject: "Important announcement", Newsgroups: "comp.test",
		Headers: map[string]string{"Identity-Hash": "abc123"},
	}
	result, err := Evaluate(article, []Rule{
		{ID: "subject", Enabled: true, Field: FieldSubject, Operator: OperatorContains, Pattern: "important", Action: ActionHighlight},
		{ID: "identity", Enabled: true, Field: FieldVFaceHash, Operator: OperatorExact, Pattern: "abc123", Action: ActionTag, Tag: "trusted"},
	})
	if err != nil || !result.Highlight || len(result.Tags) != 1 || result.Tags[0] != "trusted" {
		t.Fatalf("unexpected result: %#v, %v", result, err)
	}
}

func TestEvaluateRejectsInvalidRegexp(t *testing.T) {
	_, err := Evaluate(Article{Subject: "x"}, []Rule{{ID: "bad", Enabled: true, Field: FieldSubject, Operator: OperatorRegexp, Pattern: "[", Action: ActionHide}})
	if err == nil {
		t.Fatal("expected invalid regexp error")
	}
}
