import Testing @testable import SstData struct EntryWarningsTests { let knowledge = FakeKnowledge() func check(_ kind: DictionaryEntry.Kind, others: [DictionaryEntry] = []) -> [EntryWarning] { EntryWarnings.check(kind, among: others, knowledge: knowledge) } @Test func singleCommonWordIsAWarning() { let w = check(.correction(heard: "cloud", wrote: "Claude")) #expect(w.contains { $0.level == .warning && $0.message.contains("cloud") }) } @Test func veryShortSourceIsAWarning() { #expect(check(.correction(heard: "ab", wrote: "AB")).contains { $0.level == .warning }) } @Test func functionWordInsideAPhraseIsAWarning() { #expect(check(.correction(heard: "in de", wrote: "indeed")).contains { $0.level == .warning }) } @Test func gluedFormThatIsARealWordIsAWarning() { let w = check(.correction(heard: "some thing", wrote: "Something")) #expect(w.contains { $0.level == .warning && $0.message.contains("something") }) } @Test func phraseOfCommonWordsOnlyGetsANote() { let w = check(.correction(heard: "cloud code", wrote: "Claude Code")) #expect(w.count == 1) #expect(w[0].level == .note) } @Test func distinctiveEntriesGetNoWarnings() { #expect(check(.correction(heard: "versel", wrote: "Vercel")).isEmpty) #expect(check(.term("Supabase")).isEmpty) } @Test func duplicateSourceIsAnErrorEvenWithDifferentSpelling() { let others = [pair("cloud code", "Claude Code")] let w = check(.correction(heard: "Cloud-Code", wrote: "X"), others: others) #expect(w.first?.level == .error) } @Test func termThatIsARealWordGetsANoteAboutBiasOnly() { let w = check(.term("Reef")) #expect(w.count == 1) #expect(w[0].level == .note) } @Test func emptySourceIsAnError() { #expect(check(.term(" ")).first?.level == .error) } @Test func warningsAreSortedMostSevereFirst() { let w = check(.correction(heard: "cloud", wrote: "Claude"), others: [pair("cloud", "x")]) #expect(w.map(\.level) == w.map(\.level).sorted(by: >)) } }