-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update library to dylan-tool and basic CI (#4)
* Add .gitignore * Add README.md * Add package description * Add basic tests * Add CI tests
- Loading branch information
Showing
8 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |