Add some basic tests

This commit is contained in:
Payas Relekar 2024-03-24 01:22:32 +05:30
parent 0890726ab9
commit c663a66aa0
3 changed files with 77 additions and 5 deletions

51
test/gleambox_test.gleam Normal file
View file

@ -0,0 +1,51 @@
import gleeunit
import gleeunit/should
import gleambox
import simplifile
import gleam/result
import gleam/dict
import gleam/list
pub fn main() {
gleeunit.main()
}
pub fn get_from_test() {
"./test/mboxtest"
|> simplifile.read
|> result.unwrap(or: "")
|> gleambox.parse
|> gleambox.get_from
|> result.unwrap(or: "ERROR")
|> should.equal("Anonymous Courage <from@gmail.com>")
}
pub fn get_to_test() {
"./test/mboxtest"
|> simplifile.read
|> result.unwrap(or: "")
|> gleambox.parse
|> gleambox.get_to
|> result.unwrap(or: "ERROR")
|> should.equal("Anonymous Coward <to@gmail.com>")
}
pub fn get_headers_test() {
"./test/mboxtest"
|> simplifile.read
|> result.unwrap(or: "")
|> gleambox.parse
|> gleambox.get_headers
|> dict.size
|> should.equal(13)
}
pub fn get_references_test() {
"./test/mboxtest"
|> simplifile.read
|> result.unwrap(or: "")
|> gleambox.parse
|> gleambox.get_references
|> list.fold(0, fn(count, _) { count + 1 })
|> should.equal(2)
}

View file

@ -1,5 +0,0 @@
import gleeunit
pub fn main() {
gleeunit.main()
}

26
test/mboxtest Normal file
View file

@ -0,0 +1,26 @@
MIME-Version: 1.0
Received: by 10.182.57.228 with HTTP; Mon, 21 Nov 2011 05:30:40 -0800 (PST)
In-Reply-To: <CAG-foo_bar=baz@mail.gmail.com>
References: <REF_1@mail.gmail.com>
<REF_1@mail.gmail.com>
Date: Mon, 21 Nov 2011 08:30:40 -0500
Delivered-To: rec@gmail.com
Message-ID: <ID_0@mail.gmail.com>
Subject: Re: need another book
From: Anonymous Courage <from@gmail.com>
To: Anonymous Coward <to@gmail.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-TUID: hohoho
Some random text here
..
On 19/11/2011, Anonymous Coward <to@gmail.com> wrote:
> This is the referenced block.
> Here, the thing Gmail promotes is prefix reply notation.
>
>
> -REGARDS
>
>