Skip to content

Commit

Permalink
Update library to dylan-tool and basic CI (#4)
Browse files Browse the repository at this point in the history
* Add .gitignore

* Add README.md

* Add package description

* Add basic tests

* Add CI tests
  • Loading branch information
fraya authored Apr 2, 2024
1 parent 8611a66 commit 74aad2b
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
35 changes: 35 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: build-and-test

on:
push:
# all branches
pull_request:
# all branches

# This enables the Run Workflow button on the Actions tab.
workflow_dispatch:

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Opendylan
uses: dylan-lang/install-opendylan@v3

- name: Download dependencies
run: dylan update

- name: Build tests
run: dylan build base64-test-suite

- name: Run tests
run: _build/bin/base64-test-suite --progress none --report surefire > _build/TEST-base64.xml

- name: Publish Test Report
if: success() || failure()
uses: mikepenz/action-junit-report@v4
with:
report_paths: '**/_build/TEST-*.xml'
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# backup files
*~
*.bak
.DS_Store

# project file
*.hdp

# documentation build directory
build/

# compiler build directory
_build/

# dylan tool package cache
_packages/

# package registry folder
registry/
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Base64
[![build-and-test](https://github.com/dylan-lang/base64/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/dylan-lang/base64/actions/workflows/build-and-test.yml)

Base64 implementation for Dylan

## Abstract

This library implements the Base64 transfer encoding algorithm as
defined in [RFC 1521](https://datatracker.ietf.org/doc/html/rfc1521)
by Borensten & Freed, September 1993.

# Usage

## Functions exported

This library exports two functions

- `base-64-encode (string) => (string)` and

- `base-64-decode (string) => (string)`

## Types of encoding

The functions have two types of encoding/decoding:

- `#"standard"` (default) and

- `#"http"`

The main difference between them are the padding characters used. You
can choose the type with the key parameter `encoding:` (see example below).

## Example

### Standard encoding/decoding

Here is an example of usage of the standard encoding/decoding:

```dylan
// Example string to encode
let original-string = "Many hands make light work.";
// Encoding the string to base64 standard
let encoded-standard = base64-encode(original-string);
format-out("Encoded string: %=\n", encoded-standard);
// Shows in output
// Encoded string: "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu"
// Decoding the string in base64 standard
let decoded-string = base64-decode(encoded-standard);
format-out("Decoded string: %=\n", decoded-string);
// Shows in output
// Decoded string: "Many hands make light work."
```
### HTTP encoding/decoding

To show the http encoding/decoding we will use a text that forces the
padding (base64 encoding uses padding to ensure that the length of the
encoded string is a multiple of 4 bytes).

```dylan
// Example string to encode, note the missing dot at the end
let original-string = "Many hands make light work";
// Encoding the string to base64 http
let encoded-http = base64-encode(original-string, encoding: #"http");
format-out("Encoded string: %=\n", encoded-http);
// Shows in output (note the padding character '@')
// Encoded string: "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcms@"
// Decoding the string in base64 http
let decoded-string = base64-decode(encoded-http, encoding: #"http");
format-out("Decoded string: %=\n", decoded-string);
// Shows in output
// Decoded string: "Many hands make light work"
```

## Author

Original version written in Common Lisp by Juri Pakaste <[email protected]>.
Converted to Dylan by Carl Gay, July 2002.
13 changes: 13 additions & 0 deletions dylan-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"category": "encoding",
"contact": "[email protected]",
"dependencies": [ ],
"dev-dependencies": [ "testworks" ],
"description": "Base64 encoding",
"name": "base64",
"version": "0.1.1",
"url": "https://github.com/dylan-lang/base64",
"keywords": [ "base64", "binary" ],
"license": "Unlicensed",
"license-url": "http://unlicense.org/"
}
30 changes: 30 additions & 0 deletions tests/base64-test-suite.dylan
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Module: base64-test-suite

define constant $text-samples
= #["Many hands make light work.",
"Many hands make light work"];

define constant $encoded-standard-samples
= #["TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu",
"TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcms="];

define constant $encoded-http-samples
= #["TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu",
"TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcms@"];

define test test-base64-standard ()
for (text in $text-samples, encoded in $encoded-standard-samples)
assert-equal(encoded, base64-encode(text));
assert-equal(text, base64-decode(encoded))
end
end;

define test test-base64-http ()
for (text in $text-samples, encoded in $encoded-http-samples)
assert-equal(encoded, base64-encode(text, encoding: #"http"));
assert-equal(text, base64-decode(encoded, encoding: #"http"))
end
end;

// Use `_build/bin/base64-test-suite --help` to see options.
run-test-application()
4 changes: 4 additions & 0 deletions tests/base64-test-suite.lid
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Library: base64-test-suite
Files: library.dylan
base64-test-suite.dylan
Target-Type: executable
13 changes: 13 additions & 0 deletions tests/library.dylan
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Module: dylan-user

define library base64-test-suite
use common-dylan;
use testworks;
use base64;
end library;

define module base64-test-suite
use common-dylan;
use testworks;
use base64;
end module;

0 comments on commit 74aad2b

Please sign in to comment.