From 2eb45381d101db865763647b47c902d4e8ce0c11 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 25 Mar 2023 22:32:40 +0200 Subject: [PATCH] - Added unit tests - Updated `.gitignore` --- .gitignore | 1 + source/bformat/marshall.d | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/.gitignore b/.gitignore index 7814e3a..5668084 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ docs/ # Code coverage *.lst dub.selections.json +bformat-test-library diff --git a/source/bformat/marshall.d b/source/bformat/marshall.d index 59c510b..fa0515b 100644 --- a/source/bformat/marshall.d +++ b/source/bformat/marshall.d @@ -88,4 +88,20 @@ public byte[] encodeBformat(byte[] message) messageBuffer ~= cast(byte[])message; return messageBuffer; +} + +version(unittest) +{ + import std.string : cmp; +} + +unittest +{ + string message = "This is my message"; + byte[] bformatEncoded = encodeBformat(cast(byte[])message); + + byte[] decodedMessageBytes = decodeMessage(bformatEncoded); + string decodedMessage = cast(string)decodedMessageBytes; + + assert(cmp(message, decodedMessage) == 0); } \ No newline at end of file