test(gift): 연락처 입력 계약을 검증한다

This commit is contained in:
Yu Sung
2026-10-08 12:32:59 +09:00
parent 984eea6835
commit 6c9d4e8d2a
2 changed files with 247 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
import Foundation
@main
enum GiftContactInputCheck {
static var assertions = 0
static func check(_ condition: Bool, _ message: String) {
guard condition else {
print("FAIL gift-contact-input: \(message)")
exit(1)
}
assertions += 1
}
static func main() {
let names = GiftContactInputRule.name
check(names.acceptsEditing(""), "empty name is editable")
check(!names.acceptsSubmission(""), "empty name is not submittable")
for value in ["가", "가나다라마바사아자차카타", "A", "AAAAAAAAAAAA", "가나다", "ㅎㅏㄴ", "Soda", "소다Soda"] {
check(names.acceptsEditing(value), "name accepts \(value)")
check(names.acceptsSubmission(value), "name submits \(value)")
}
for value in ["가나다라마바사아자차카타파", "AAAAAAAAAAAAA", " ", "123", "!", "🙂", "日本"] {
check(!names.acceptsEditing(value), "name rejects \(value)")
check(!names.acceptsSubmission(value), "name does not submit \(value)")
}
let phones = GiftContactInputRule.phoneNumber
check(phones.acceptsEditing(""), "empty phone is editable")
check(!phones.acceptsSubmission(""), "empty phone is not submittable")
for length in 1...11 {
let value = String(repeating: "1", count: length)
check(phones.acceptsEditing(value), "phone accepts length \(length)")
check(!phones.acceptsSubmission(value), "phone does not submit length \(length)")
}
check(phones.acceptsEditing("01012345678"), "valid phone is editable")
check(phones.acceptsSubmission("01012345678"), "valid phone submits")
for value in [String(repeating: "1", count: 12), "1 2", "+123", "abc", "🙂", "123", "010-1234-5678", "010 12345678"] {
check(!phones.acceptsEditing(value), "phone rejects \(value)")
check(!phones.acceptsSubmission(value), "phone does not submit \(value)")
}
for value in ["01112345678", "11012345678", "12345678901"] {
check(phones.acceptsEditing(value), "phone accepts wrong-prefix editing \(value)")
check(!phones.acceptsSubmission(value), "phone rejects wrong-prefix submission \(value)")
}
print("PASS gift-contact-input: \(assertions) assertions")
}
}