aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2022-04-22 16:55:47 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2022-04-22 16:55:47 +0200
commite799476f90537ca173205a64da1fbf87b894b42e (patch)
treee8234bbba2c4e3d9e0608079a57a9112a1054dcf /tests
parentb4f8efcbe6cbf2d9b17dce0758ecbb29f4bd6451 (diff)
[compress/shoco] Add short string compressor.
Diffstat (limited to 'tests')
-rw-r--r--tests/core/assets/Shoco/LICENSE26
-rw-r--r--tests/core/assets/Shoco/LICENSE.shocobin0 -> 1269 bytes
-rw-r--r--tests/core/assets/Shoco/README.md95
-rw-r--r--tests/core/assets/Shoco/README.md.shocobin0 -> 2227 bytes
-rw-r--r--tests/core/compress/test_core_compress.odin57
5 files changed, 177 insertions, 1 deletions
diff --git a/tests/core/assets/Shoco/LICENSE b/tests/core/assets/Shoco/LICENSE
new file mode 100644
index 000000000..9ca94bcdf
--- /dev/null
+++ b/tests/core/assets/Shoco/LICENSE
@@ -0,0 +1,26 @@
+Copyright (c) 2016-2021 Ginger Bill. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+3. Neither the name of the copyright holder nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/tests/core/assets/Shoco/LICENSE.shoco b/tests/core/assets/Shoco/LICENSE.shoco
new file mode 100644
index 000000000..5d5e4d623
--- /dev/null
+++ b/tests/core/assets/Shoco/LICENSE.shoco
Binary files differ
diff --git a/tests/core/assets/Shoco/README.md b/tests/core/assets/Shoco/README.md
new file mode 100644
index 000000000..9e46f80d0
--- /dev/null
+++ b/tests/core/assets/Shoco/README.md
@@ -0,0 +1,95 @@
+<p align="center">
+ <img src="misc/logo-slim.png" alt="Odin logo" style="width:65%">
+ <br/>
+ The Data-Oriented Language for Sane Software Development.
+ <br/>
+ <br/>
+ <a href="https://github.com/odin-lang/odin/releases/latest">
+ <img src="https://img.shields.io/github/release/odin-lang/odin.svg">
+ </a>
+ <a href="https://github.com/odin-lang/odin/releases/latest">
+ <img src="https://img.shields.io/badge/platforms-Windows%20|%20Linux%20|%20macOS-green.svg">
+ </a>
+ <br>
+ <a href="https://discord.gg/odinlang">
+ <img src="https://img.shields.io/discord/568138951836172421?logo=discord">
+ </a>
+ <a href="https://github.com/odin-lang/odin/actions">
+ <img src="https://github.com/odin-lang/odin/workflows/CI/badge.svg?branch=master&event=push">
+ </a>
+</p>
+
+# The Odin Programming Language
+
+
+Odin is a general-purpose programming language with distinct typing, built for high performance, modern systems, and built-in data-oriented data types. The Odin Programming Language, the C alternative for the joy of programming.
+
+Website: [https://odin-lang.org/](https://odin-lang.org/)
+
+```odin
+package main
+
+import "core:fmt"
+
+main :: proc() {
+ program := "+ + * 😃 - /"
+ accumulator := 0
+
+ for token in program {
+ switch token {
+ case '+': accumulator += 1
+ case '-': accumulator -= 1
+ case '*': accumulator *= 2
+ case '/': accumulator /= 2
+ case '😃': accumulator *= accumulator
+ case: // Ignore everything else
+ }
+ }
+
+ fmt.printf("The program \"%s\" calculates the value %d\n",
+ program, accumulator)
+}
+
+```
+
+## Documentation
+
+#### [Getting Started](https://odin-lang.org/docs/install)
+
+Instructions for downloading and installing the Odin compiler and libraries.
+
+#### [Nightly Builds](https://odin-lang.org/docs/nightly/)
+
+Get the latest nightly builds of Odin.
+
+### Learning Odin
+
+#### [Overview of Odin](https://odin-lang.org/docs/overview)
+
+An overview of the Odin programming language.
+
+#### [Frequently Asked Questions (FAQ)](https://odin-lang.org/docs/faq)
+
+Answers to common questions about Odin.
+
+#### [Packages](https://pkg.odin-lang.org/)
+
+Documentation for all the official packages part of the [core](https://pkg.odin-lang.org/core/) and [vendor](https://pkg.odin-lang.org/vendor/) library collections.
+
+#### [The Odin Wiki](https://github.com/odin-lang/Odin/wiki)
+
+A wiki maintained by the Odin community.
+
+#### [Odin Discord](https://discord.gg/sVBPHEv)
+
+Get live support and talk with other odiners on the Odin Discord.
+
+### Articles
+
+#### [The Odin Blog](https://odin-lang.org/news/)
+
+The official blog of the Odin programming language, featuring announcements, news, and in-depth articles by the Odin team and guests.
+
+## Warnings
+
+* The Odin compiler is still in development.
diff --git a/tests/core/assets/Shoco/README.md.shoco b/tests/core/assets/Shoco/README.md.shoco
new file mode 100644
index 000000000..013f4f469
--- /dev/null
+++ b/tests/core/assets/Shoco/README.md.shoco
Binary files differ
diff --git a/tests/core/compress/test_core_compress.odin b/tests/core/compress/test_core_compress.odin
index 51952a568..ee7233e52 100644
--- a/tests/core/compress/test_core_compress.odin
+++ b/tests/core/compress/test_core_compress.odin
@@ -7,13 +7,14 @@ package test_core_compress
List of contributors:
Jeroen van Rijn: Initial implementation.
- A test suite for ZLIB, GZIP.
+ A test suite for ZLIB, GZIP and Shoco.
*/
import "core:testing"
import "core:compress/zlib"
import "core:compress/gzip"
+import "core:compress/shoco"
import "core:bytes"
import "core:fmt"
@@ -48,6 +49,7 @@ main :: proc() {
t := testing.T{w=w}
zlib_test(&t)
gzip_test(&t)
+ shoco_test(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
if TEST_fail > 0 {
@@ -134,3 +136,56 @@ gzip_test :: proc(t: ^testing.T) {
expect(t, false, error)
}
}
+
+@test
+shoco_test :: proc(t: ^testing.T) {
+
+ Shoco_Tests :: []struct{
+ compressed: []u8,
+ raw: []u8,
+ short_pack: int,
+ short_sentinel: int,
+ }{
+ { #load("../assets/Shoco/README.md.shoco"), #load("../assets/Shoco/README.md"), 10, 1006 },
+ { #load("../assets/Shoco/LICENSE.shoco"), #load("../assets/Shoco/LICENSE"), 25, 68 },
+ }
+
+ for v in Shoco_Tests {
+ expected_raw := len(v.raw)
+ expected_compressed := len(v.compressed)
+
+ biggest_unpacked := shoco.decompress_bound(expected_compressed)
+ biggest_packed := shoco.compress_bound(expected_raw)
+
+ buffer := make([]u8, max(biggest_packed, biggest_unpacked))
+ defer delete(buffer)
+
+ size, err := shoco.decompress(v.compressed, buffer[:])
+ msg := fmt.tprintf("Expected `decompress` to return `nil`, got %v", err)
+ expect(t, err == nil, msg)
+
+ msg = fmt.tprintf("Decompressed %v bytes into %v. Expected to decompress into %v bytes.", len(v.compressed), size, expected_raw)
+ expect(t, size == expected_raw, msg)
+ expect(t, string(buffer[:size]) == string(v.raw), "Decompressed contents don't match.")
+
+ size, err = shoco.compress(string(v.raw), buffer[:])
+ expect(t, err == nil, "Expected `compress` to return `nil`.")
+
+ msg = fmt.tprintf("Compressed %v bytes into %v. Expected to compress into %v bytes.", expected_raw, size, expected_compressed)
+ expect(t, size == expected_compressed, msg)
+
+ size, err = shoco.decompress(v.compressed, buffer[:expected_raw - 10])
+ msg = fmt.tprintf("Decompressing into too small a buffer returned %v, expected `.Output_Too_Short`", err)
+ expect(t, err == .Output_Too_Short, msg)
+
+ size, err = shoco.compress(string(v.raw), buffer[:expected_compressed - 10])
+ msg = fmt.tprintf("Compressing into too small a buffer returned %v, expected `.Output_Too_Short`", err)
+ expect(t, err == .Output_Too_Short, msg)
+
+ size, err = shoco.decompress(v.compressed[:v.short_pack], buffer[:])
+ expect(t, err == .Stream_Too_Short, "Expected `decompress` to return `Stream_Too_Short` because there was no more data after selecting a pack.")
+
+ size, err = shoco.decompress(v.compressed[:v.short_sentinel], buffer[:])
+ expect(t, err == .Stream_Too_Short, "Expected `decompress` to return `Stream_Too_Short` because there was no more data after non-ASCII sentinel.")
+ }
+} \ No newline at end of file