a gleam implementation of a CS assignment originally written in cpp
1import bible_search
2import gleeunit
3import gleeunit/should
4
5pub fn main() -> Nil {
6 gleeunit.main()
7}
8
9// gleeunit test functions end in `_test`
10pub fn parse_reference_test() {
11 let ref = bible_search.parse_reference("FIRST KINGS 10 10")
12 should.be_ok(ref)
13
14 let expected_ref =
15 Ok(bible_search.Reference(book: "FIRST KINGS", chapter: 10, verse: 10))
16
17 should.be_true(ref == expected_ref)
18}
19
20pub fn parse_reference_single_word_book_test() {
21 let ref = bible_search.parse_reference("GENESIS 1 1")
22 should.be_ok(ref)
23
24 let expected_ref =
25 Ok(bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1))
26
27 should.be_true(ref == expected_ref)
28}
29
30pub fn parse_reference_invalid_chapter_test() {
31 let ref = bible_search.parse_reference("GENESIS abc 1")
32 should.be_error(ref)
33
34 let expected_error = Error("Invalid chapter: abc")
35
36 should.be_true(ref == expected_error)
37}
38
39pub fn parse_reference_invalid_verse_test() {
40 let ref = bible_search.parse_reference("GENESIS 1 xyz")
41 should.be_error(ref)
42 let expected_error = Error("Invalid verse: xyz")
43
44 should.be_true(ref == expected_error)
45}
46
47pub fn parse_reference_too_few_parts_test() {
48 let ref = bible_search.parse_reference("GENESIS 1")
49 should.be_error(ref)
50 let expected_error = Error("invalid parse")
51
52 should.be_true(ref == expected_error)
53}
54
55pub fn parse_reference_too_many_parts_test() {
56 let ref = bible_search.parse_reference("SONG OF SOLOMON 1 1")
57 should.be_error(ref)
58 let expected_error = Error("invalid parse")
59
60 should.be_true(ref == expected_error)
61}
62
63pub fn parse_reference_lowercase_book_test() {
64 let ref = bible_search.parse_reference("genesis 1 1")
65 should.be_ok(ref)
66
67 let expected_ref =
68 Ok(bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1))
69
70 should.be_true(ref == expected_ref)
71}
72
73pub fn bible_scan_found_verse_test() {
74 let bible =
75 "THE BOOK OF GENESIS
76
77CHAPTER 1
78
791 In the beginning God created the heaven and the earth.
802 And the earth was without form, and void; and darkness was upon the face of the deep."
81
82 let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 1)
83 let result = bible_search.bible_scan(reference: ref, bible: bible)
84
85 should.be_true(
86 result.verse == Ok("In the beginning God created the heaven and the earth."),
87 )
88}
89
90pub fn bible_scan_verse_not_found_test() {
91 let bible =
92 "THE BOOK OF GENESIS
93
94CHAPTER 1
95
961 In the beginning God created the heaven and the earth."
97
98 let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 99)
99 let result = bible_search.bible_scan(reference: ref, bible: bible)
100
101 should.be_true(result.verse == Error("Verse not found"))
102}
103
104pub fn bible_scan_book_not_found_test() {
105 let bible =
106 "THE BOOK OF GENESIS
107
108CHAPTER 1
109
1101 In the beginning God created the heaven and the earth."
111
112 let ref = bible_search.Reference(book: "EXODUS", chapter: 1, verse: 1)
113 let result = bible_search.bible_scan(reference: ref, bible: bible)
114
115 should.be_true(result.verse == Error("Verse not found"))
116}
117
118pub fn bible_scan_chapter_not_found_test() {
119 let bible =
120 "THE BOOK OF GENESIS
121
122CHAPTER 1
123
1241 In the beginning God created the heaven and the earth."
125
126 let ref = bible_search.Reference(book: "GENESIS", chapter: 99, verse: 1)
127 let result = bible_search.bible_scan(reference: ref, bible: bible)
128
129 should.be_true(result.verse == Error("Verse not found"))
130}
131
132pub fn bible_scan_multiple_verses_test() {
133 let bible =
134 "THE BOOK OF GENESIS
135
136CHAPTER 1
137
1381 In the beginning God created the heaven and the earth.
1392 And the earth was without form, and void; and darkness was upon the face of the deep.
1403 And God said, Let there be light: and there was light."
141
142 let ref = bible_search.Reference(book: "GENESIS", chapter: 1, verse: 2)
143 let result = bible_search.bible_scan(reference: ref, bible: bible)
144
145 should.be_true(
146 result.verse
147 == Ok(
148 "And the earth was without form, and void; and darkness was upon the face of the deep.",
149 ),
150 )
151}