58 lines
2.2 KiB
Go
58 lines
2.2 KiB
Go
package insight
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGeneratedInsightTextMustBeOnePlainParagraph(t *testing.T) {
|
|
for _, value := range []string{"# عنوان", "**مهم**", "متن _تأکیدی_", "خط اول\nخط دوم", "- مورد اول"} {
|
|
if isPlainParagraph(value) {
|
|
t.Fatalf("isPlainParagraph(%q) = true, want false", value)
|
|
}
|
|
}
|
|
if !isPlainParagraph("فروش این بازه بهتر شده و بهتر است روند آن را حفظ کنید.") {
|
|
t.Fatal("simple Persian paragraph was rejected")
|
|
}
|
|
}
|
|
|
|
func TestInsightInstructionsRequireExactPersianPeriodNames(t *testing.T) {
|
|
instructions := insightInstructions(ModuleOverview)
|
|
for _, required := range []string{
|
|
"selectedPeriod.jalaliLabelFa",
|
|
"precedingPeriod.jalaliLabelFa",
|
|
"در بازه انتخابشده",
|
|
"بازه بلافاصله قبل",
|
|
} {
|
|
if !strings.Contains(instructions, required) {
|
|
t.Fatalf("instructions do not contain %q", required)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGeneratedInsightAllowsOnlyDigitsInsideExactPeriodLabels(t *testing.T) {
|
|
labels := []string{"مرداد ۱۴۰۵", "تیر ۱۴۰۵"}
|
|
if containsUnexpectedDigit("در مرداد ۱۴۰۵ وضعیت پرداخت بهتر از تیر ۱۴۰۵ بود.", labels) {
|
|
t.Fatal("digits inside exact allowlisted period labels were rejected")
|
|
}
|
|
if !containsUnexpectedDigit("در مرداد ۱۴۰۶ وضعیت پرداخت بهتر بود.", labels) {
|
|
t.Fatal("a number outside the exact period labels was accepted")
|
|
}
|
|
}
|
|
|
|
func TestGeneratedInsightMustNameSelectedAndPrecedingPeriods(t *testing.T) {
|
|
labels := []string{"مرداد ۱۴۰۵", "تیر ۱۴۰۵"}
|
|
if !hasExactPeriodReferences(generatedInsight{
|
|
LatestObservedBody: "در مرداد ۱۴۰۵ وضعیت پرداخت بهتر بود.",
|
|
PastBody: "در تیر ۱۴۰۵ پرداخت موفق کمتری ثبت شده بود.",
|
|
}, labels) {
|
|
t.Fatal("exact selected and preceding period labels were rejected")
|
|
}
|
|
if hasExactPeriodReferences(generatedInsight{
|
|
LatestObservedBody: "در بازه انتخابشده وضعیت پرداخت بهتر بود.",
|
|
PastBody: "نسبت به بازه بلافاصله قبل پرداخت موفق بیشتر شد.",
|
|
}, labels) {
|
|
t.Fatal("generic period wording was accepted")
|
|
}
|
|
}
|