diff --git a/t/caesar.bel b/t/caesar.bel new file mode 100644 index 00000000..d8e008c4 --- /dev/null +++ b/t/caesar.bel @@ -0,0 +1,28 @@ +;; Caesar encoding/decoding +;; Ported from https://github.com/koka-lang/koka/blob/4ef04cd7cfa965c413a985dfaabbfb69a4c64d11/samples/basic/caesar.kk + +(def prlf args + (map pr args) + (pr \lf)) + +(set char->int charn + int->char nchar) + +(mac letdef ((f . fbody) . body) + `(let ,f (fn ,@fbody) + ,@body)) + +(def encode (s|string (o shift|int 3)) + (letdef (encode-char (c) + (if (~<= \a c \z) + c + (withs (base (- (char->int c) (char->int \a)) + rot (mod (+ base shift) 26)) + (int->char (+ rot (char->int \a)))))) + (map encode-char s))) + +(def caesar (s|string) + (encode s 3)) + +(prlf (caesar "hello")) + diff --git a/t/example-caesar.t b/t/example-caesar.t new file mode 100644 index 00000000..a5f5053f --- /dev/null +++ b/t/example-caesar.t @@ -0,0 +1,17 @@ +#!perl -T +use 5.006; + +use strict; +use warnings; + +use Test::More; +use Language::Bel::Test; + +plan tests => 1; + +my $output = output_of_eval_file("t/caesar.bel"); + +is $output, + "khoor\n", + "caesar example works"; +