Convert module funcs to ToString/Parse

This commit is contained in:
2025-01-30 19:22:45 -05:00
parent 5240b78487
commit facc294d66
9 changed files with 498 additions and 465 deletions

View File

@@ -8,28 +8,32 @@ open System
[<Tests>]
let asOfDateDisplayTests =
testList "AsOfDateDisplay" [
test "NoDisplay code is correct" {
Expect.equal (AsOfDateDisplay.toCode NoDisplay) "N" "The code for NoDisplay should have been \"N\""
}
test "ShortDate code is correct" {
Expect.equal (AsOfDateDisplay.toCode ShortDate) "S" "The code for ShortDate should have been \"S\""
}
test "LongDate code is correct" {
Expect.equal (AsOfDateDisplay.toCode LongDate) "L" "The code for LongDate should have been \"N\""
}
test "fromCode N should return NoDisplay" {
Expect.equal (AsOfDateDisplay.fromCode "N") NoDisplay "\"N\" should have been converted to NoDisplay"
}
test "fromCode S should return ShortDate" {
Expect.equal (AsOfDateDisplay.fromCode "S") ShortDate "\"S\" should have been converted to ShortDate"
}
test "fromCode L should return LongDate" {
Expect.equal (AsOfDateDisplay.fromCode "L") LongDate "\"L\" should have been converted to LongDate"
}
test "fromCode X should raise" {
Expect.throws (fun () -> AsOfDateDisplay.fromCode "X" |> ignore)
"An unknown code should have raised an exception"
}
testList "ToString" [
test "NoDisplay code is correct" {
Expect.equal (string NoDisplay) "N" "The code for NoDisplay should have been \"N\""
}
test "ShortDate code is correct" {
Expect.equal (string ShortDate) "S" "The code for ShortDate should have been \"S\""
}
test "LongDate code is correct" {
Expect.equal (string LongDate) "L" "The code for LongDate should have been \"N\""
}
]
testList "Parse" [
test "N should return NoDisplay" {
Expect.equal (AsOfDateDisplay.Parse "N") NoDisplay "\"N\" should have been parsed to NoDisplay"
}
test "S should return ShortDate" {
Expect.equal (AsOfDateDisplay.Parse "S") ShortDate "\"S\" should have been parsed to ShortDate"
}
test "L should return LongDate" {
Expect.equal (AsOfDateDisplay.Parse "L") LongDate "\"L\" should have been parsed to LongDate"
}
test "X should raise" {
Expect.throws (fun () -> AsOfDateDisplay.Parse "X" |> ignore)
"An unknown code should have raised an exception"
}
]
]
[<Tests>]
@@ -49,50 +53,58 @@ let churchTests =
[<Tests>]
let emailFormatTests =
testList "EmailFormat" [
test "HtmlFormat code is correct" {
Expect.equal (EmailFormat.toCode HtmlFormat) "H" "The code for HtmlFormat should have been \"H\""
}
test "PlainTextFormat code is correct" {
Expect.equal (EmailFormat.toCode PlainTextFormat) "P" "The code for PlainTextFormat should have been \"P\""
}
test "fromCode H should return HtmlFormat" {
Expect.equal (EmailFormat.fromCode "H") HtmlFormat "\"H\" should have been converted to HtmlFormat"
}
test "fromCode P should return ShortDate" {
Expect.equal (EmailFormat.fromCode "P") PlainTextFormat
"\"P\" should have been converted to PlainTextFormat"
}
test "fromCode Z should raise" {
Expect.throws (fun () -> EmailFormat.fromCode "Z" |> ignore)
"An unknown code should have raised an exception"
}
testList "ToString" [
test "HtmlFormat code is correct" {
Expect.equal (string HtmlFormat) "H" "The code for HtmlFormat should have been \"H\""
}
test "PlainTextFormat code is correct" {
Expect.equal (string PlainTextFormat) "P" "The code for PlainTextFormat should have been \"P\""
}
]
testList "Parse" [
test "H should return HtmlFormat" {
Expect.equal (EmailFormat.Parse "H") HtmlFormat "\"H\" should have been converted to HtmlFormat"
}
test "P should return ShortDate" {
Expect.equal (EmailFormat.Parse "P") PlainTextFormat
"\"P\" should have been converted to PlainTextFormat"
}
test "Z should raise" {
Expect.throws (fun () -> EmailFormat.Parse "Z" |> ignore)
"An unknown code should have raised an exception"
}
]
]
[<Tests>]
let expirationTests =
testList "Expiration" [
test "Automatic code is correct" {
Expect.equal (Expiration.toCode Automatic) "A" "The code for Automatic should have been \"A\""
}
test "Manual code is correct" {
Expect.equal (Expiration.toCode Manual) "M" "The code for Manual should have been \"M\""
}
test "Forced code is correct" {
Expect.equal (Expiration.toCode Forced) "F" "The code for Forced should have been \"F\""
}
test "fromCode A should return Automatic" {
Expect.equal (Expiration.fromCode "A") Automatic "\"A\" should have been converted to Automatic"
}
test "fromCode M should return Manual" {
Expect.equal (Expiration.fromCode "M") Manual "\"M\" should have been converted to Manual"
}
test "fromCode F should return Forced" {
Expect.equal (Expiration.fromCode "F") Forced "\"F\" should have been converted to Forced"
}
test "fromCode V should raise" {
Expect.throws (fun () -> Expiration.fromCode "V" |> ignore)
"An unknown code should have raised an exception"
}
testList "ToString" [
test "Automatic code is correct" {
Expect.equal (string Automatic) "A" "The code for Automatic should have been \"A\""
}
test "Manual code is correct" {
Expect.equal (string Manual) "M" "The code for Manual should have been \"M\""
}
test "Forced code is correct" {
Expect.equal (string Forced) "F" "The code for Forced should have been \"F\""
}
]
testList "Parse" [
test "A should return Automatic" {
Expect.equal (Expiration.Parse "A") Automatic "\"A\" should have been converted to Automatic"
}
test "M should return Manual" {
Expect.equal (Expiration.Parse "M") Manual "\"M\" should have been converted to Manual"
}
test "F should return Forced" {
Expect.equal (Expiration.Parse "F") Forced "\"F\" should have been converted to Forced"
}
test "fromCode V should raise" {
Expect.throws (fun () -> Expiration.Parse "V" |> ignore)
"An unknown code should have raised an exception"
}
]
]
[<Tests>]
@@ -223,68 +235,74 @@ let prayerRequestTests =
[<Tests>]
let prayerRequestTypeTests =
testList "PrayerRequestType" [
test "CurrentRequest code is correct" {
Expect.equal (PrayerRequestType.toCode CurrentRequest) "C"
"The code for CurrentRequest should have been \"C\""
}
test "LongTermRequest code is correct" {
Expect.equal (PrayerRequestType.toCode LongTermRequest) "L"
"The code for LongTermRequest should have been \"L\""
}
test "PraiseReport code is correct" {
Expect.equal (PrayerRequestType.toCode PraiseReport) "P" "The code for PraiseReport should have been \"P\""
}
test "Expecting code is correct" {
Expect.equal (PrayerRequestType.toCode Expecting) "E" "The code for Expecting should have been \"E\""
}
test "Announcement code is correct" {
Expect.equal (PrayerRequestType.toCode Announcement) "A" "The code for Announcement should have been \"A\""
}
test "fromCode C should return CurrentRequest" {
Expect.equal (PrayerRequestType.fromCode "C") CurrentRequest
"\"C\" should have been converted to CurrentRequest"
}
test "fromCode L should return LongTermRequest" {
Expect.equal (PrayerRequestType.fromCode "L") LongTermRequest
"\"L\" should have been converted to LongTermRequest"
}
test "fromCode P should return PraiseReport" {
Expect.equal (PrayerRequestType.fromCode "P") PraiseReport
"\"P\" should have been converted to PraiseReport"
}
test "fromCode E should return Expecting" {
Expect.equal (PrayerRequestType.fromCode "E") Expecting "\"E\" should have been converted to Expecting"
}
test "fromCode A should return Announcement" {
Expect.equal (PrayerRequestType.fromCode "A") Announcement
"\"A\" should have been converted to Announcement"
}
test "fromCode R should raise" {
Expect.throws (fun () -> PrayerRequestType.fromCode "R" |> ignore)
"An unknown code should have raised an exception"
}
testList "ToString" [
test "CurrentRequest code is correct" {
Expect.equal (string CurrentRequest) "C" "The code for CurrentRequest should have been \"C\""
}
test "LongTermRequest code is correct" {
Expect.equal (string LongTermRequest) "L" "The code for LongTermRequest should have been \"L\""
}
test "PraiseReport code is correct" {
Expect.equal (string PraiseReport) "P" "The code for PraiseReport should have been \"P\""
}
test "Expecting code is correct" {
Expect.equal (string Expecting) "E" "The code for Expecting should have been \"E\""
}
test "Announcement code is correct" {
Expect.equal (string Announcement) "A" "The code for Announcement should have been \"A\""
}
]
testList "Parse" [
test "C should return CurrentRequest" {
Expect.equal (PrayerRequestType.Parse "C") CurrentRequest
"\"C\" should have been converted to CurrentRequest"
}
test "L should return LongTermRequest" {
Expect.equal (PrayerRequestType.Parse "L") LongTermRequest
"\"L\" should have been converted to LongTermRequest"
}
test "P should return PraiseReport" {
Expect.equal (PrayerRequestType.Parse "P") PraiseReport
"\"P\" should have been converted to PraiseReport"
}
test "E should return Expecting" {
Expect.equal (PrayerRequestType.Parse "E") Expecting "\"E\" should have been converted to Expecting"
}
test "A should return Announcement" {
Expect.equal (PrayerRequestType.Parse "A") Announcement
"\"A\" should have been converted to Announcement"
}
test "R should raise" {
Expect.throws (fun () -> PrayerRequestType.Parse "R" |> ignore)
"An unknown code should have raised an exception"
}
]
]
[<Tests>]
let requestSortTests =
testList "RequestSort" [
test "SortByDate code is correct" {
Expect.equal (RequestSort.toCode SortByDate) "D" "The code for SortByDate should have been \"D\""
}
test "SortByRequestor code is correct" {
Expect.equal (RequestSort.toCode SortByRequestor) "R" "The code for SortByRequestor should have been \"R\""
}
test "fromCode D should return SortByDate" {
Expect.equal (RequestSort.fromCode "D") SortByDate "\"D\" should have been converted to SortByDate"
}
test "fromCode R should return SortByRequestor" {
Expect.equal (RequestSort.fromCode "R") SortByRequestor
"\"R\" should have been converted to SortByRequestor"
}
test "fromCode Q should raise" {
Expect.throws (fun () -> RequestSort.fromCode "Q" |> ignore)
"An unknown code should have raised an exception"
}
testList "ToString" [
test "SortByDate code is correct" {
Expect.equal (string SortByDate) "D" "The code for SortByDate should have been \"D\""
}
test "SortByRequestor code is correct" {
Expect.equal (string SortByRequestor) "R" "The code for SortByRequestor should have been \"R\""
}
]
testList "Parse" [
test "D should return SortByDate" {
Expect.equal (RequestSort.Parse "D") SortByDate "\"D\" should have been converted to SortByDate"
}
test "R should return SortByRequestor" {
Expect.equal (RequestSort.Parse "R") SortByRequestor
"\"R\" should have been converted to SortByRequestor"
}
test "Q should raise" {
Expect.throws (fun () -> RequestSort.Parse "Q" |> ignore)
"An unknown code should have raised an exception"
}
]
]
[<Tests>]

View File

@@ -22,12 +22,9 @@ module ReferenceListTests =
test "has all three options listed" {
let asOf = ReferenceList.asOfDateList _s
Expect.hasCountOf asOf 3u countAll "There should have been 3 as-of choices returned"
Expect.exists asOf (fun (x, _) -> x = AsOfDateDisplay.toCode NoDisplay)
"The option for no display was not found"
Expect.exists asOf (fun (x, _) -> x = AsOfDateDisplay.toCode ShortDate)
"The option for a short date was not found"
Expect.exists asOf (fun (x, _) -> x = AsOfDateDisplay.toCode LongDate)
"The option for a full date was not found"
Expect.exists asOf (fun (x, _) -> x = string NoDisplay) "The option for no display was not found"
Expect.exists asOf (fun (x, _) -> x = string ShortDate) "The option for a short date was not found"
Expect.exists asOf (fun (x, _) -> x = string LongDate) "The option for a full date was not found"
}
]
@@ -41,9 +38,9 @@ module ReferenceListTests =
Expect.equal (fst top) "" "The default option should have been blank"
Expect.equal (snd top).Value "Group Default (HTML Format)" "The default option label was incorrect"
let nxt = typs |> Seq.skip 1 |> Seq.head
Expect.equal (fst nxt) (EmailFormat.toCode HtmlFormat) "The 2nd option should have been HTML"
Expect.equal (fst nxt) (string HtmlFormat) "The 2nd option should have been HTML"
let lst = typs |> Seq.last
Expect.equal (fst lst) (EmailFormat.toCode PlainTextFormat) "The 3rd option should have been plain text"
Expect.equal (fst lst) (string PlainTextFormat) "The 3rd option should have been plain text"
}
]
@@ -53,19 +50,19 @@ module ReferenceListTests =
test "excludes immediate expiration if not required" {
let exps = ReferenceList.expirationList _s false
Expect.hasCountOf exps 2u countAll "There should have been 2 expiration types returned"
Expect.exists exps (fun (exp, _) -> exp = Expiration.toCode Automatic)
Expect.exists exps (fun (exp, _) -> exp = string Automatic)
"The option for automatic expiration was not found"
Expect.exists exps (fun (exp, _) -> exp = Expiration.toCode Manual)
Expect.exists exps (fun (exp, _) -> exp = string Manual)
"The option for manual expiration was not found"
}
test "includes immediate expiration if required" {
let exps = ReferenceList.expirationList _s true
Expect.hasCountOf exps 3u countAll "There should have been 3 expiration types returned"
Expect.exists exps (fun (exp, _) -> exp = Expiration.toCode Automatic)
Expect.exists exps (fun (exp, _) -> exp = string Automatic)
"The option for automatic expiration was not found"
Expect.exists exps (fun (exp, _) -> exp = Expiration.toCode Manual)
Expect.exists exps (fun (exp, _) -> exp = string Manual)
"The option for manual expiration was not found"
Expect.exists exps (fun (exp, _) -> exp = Expiration.toCode Forced)
Expect.exists exps (fun (exp, _) -> exp = string Forced)
"The option for immediate expiration was not found"
}
]
@@ -240,7 +237,7 @@ let editMemberTests =
}
test "fromMember populates with specific format" {
let edit = EditMember.fromMember { Member.empty with Format = Some HtmlFormat }
Expect.equal edit.Format (EmailFormat.toCode HtmlFormat) "The e-mail format was not filled correctly"
Expect.equal edit.Format (string HtmlFormat) "The e-mail format was not filled correctly"
}
test "empty is as expected" {
let edit = EditMember.empty
@@ -268,11 +265,10 @@ let editPreferencesTests =
Expect.equal edit.DaysToKeepNew prefs.DaysToKeepNew "The days to keep new were not filled correctly"
Expect.equal edit.LongTermUpdateWeeks prefs.LongTermUpdateWeeks
"The weeks for update were not filled correctly"
Expect.equal edit.RequestSort (RequestSort.toCode prefs.RequestSort)
"The request sort was not filled correctly"
Expect.equal edit.RequestSort (string prefs.RequestSort) "The request sort was not filled correctly"
Expect.equal edit.EmailFromName prefs.EmailFromName "The e-mail from name was not filled correctly"
Expect.equal edit.EmailFromAddress prefs.EmailFromAddress "The e-mail from address was not filled correctly"
Expect.equal edit.DefaultEmailType (EmailFormat.toCode prefs.DefaultEmailType)
Expect.equal edit.DefaultEmailType (string prefs.DefaultEmailType)
"The default e-mail type was not filled correctly"
Expect.equal edit.LineColorType "Name" "The heading line color type was not derived correctly"
Expect.equal edit.LineColor prefs.LineColor "The heading line color was not filled correctly"
@@ -288,8 +284,7 @@ let editPreferencesTests =
Expect.equal edit.Visibility GroupVisibility.PrivateList
"The list visibility was not derived correctly"
Expect.equal edit.PageSize prefs.PageSize "The page size was not filled correctly"
Expect.equal edit.AsOfDate (AsOfDateDisplay.toCode prefs.AsOfDateDisplay)
"The as-of date display was not filled correctly"
Expect.equal edit.AsOfDate (string prefs.AsOfDateDisplay) "The as-of date display was not filled correctly"
}
test "fromPreferences succeeds for RGB line color and password-protected list" {
let prefs = { ListPreferences.empty with LineColor = "#ff0000"; GroupPassword = "pw" }
@@ -326,13 +321,11 @@ let editRequestTests =
test "empty is as expected" {
let mt = EditRequest.empty
Expect.equal mt.RequestId emptyGuid "The request ID should be an empty GUID"
Expect.equal mt.RequestType (PrayerRequestType.toCode CurrentRequest)
"The request type should have been \"Current\""
Expect.equal mt.RequestType (string CurrentRequest) "The request type should have been \"Current\""
Expect.isNone mt.EnteredDate "The entered date should have been None"
Expect.isNone mt.SkipDateUpdate """The "skip date update" flag should have been None"""
Expect.isNone mt.Requestor "The requestor should have been None"
Expect.equal mt.Expiration (Expiration.toCode Automatic)
"""The expiration should have been "A" (Automatic)"""
Expect.equal mt.Expiration (string Automatic) """The expiration should have been "A" (Automatic)"""
Expect.equal mt.Text "" "The text should have been blank"
}
test "fromRequest succeeds" {
@@ -346,10 +339,9 @@ let editRequestTests =
}
let edit = EditRequest.fromRequest req
Expect.equal edit.RequestId (shortGuid req.Id.Value) "The request ID was not filled correctly"
Expect.equal edit.RequestType (PrayerRequestType.toCode req.RequestType)
"The request type was not filled correctly"
Expect.equal edit.RequestType (string req.RequestType) "The request type was not filled correctly"
Expect.equal edit.Requestor req.Requestor "The requestor was not filled correctly"
Expect.equal edit.Expiration (Expiration.toCode Manual) "The expiration was not filled correctly"
Expect.equal edit.Expiration (string Manual) "The expiration was not filled correctly"
Expect.equal edit.Text req.Text "The text was not filled correctly"
}
test "isNew works for a new request" {