diff --git a/examples/acceptance_tests/114/aiken.toml b/examples/acceptance_tests/114/aiken.toml new file mode 100644 index 00000000..58351e3c --- /dev/null +++ b/examples/acceptance_tests/114/aiken.toml @@ -0,0 +1,9 @@ +name = "aiken-lang/acceptance_test_114" +version = "0.0.0" +license = "Apache-2.0" +description = "Aiken contracts for project 'aiken-lang/114'" + +[repository] +user = "aiken-lang" +project = "114" +platform = "github" diff --git a/examples/acceptance_tests/114/lib/foo.ak b/examples/acceptance_tests/114/lib/foo.ak new file mode 100644 index 00000000..484205e8 --- /dev/null +++ b/examples/acceptance_tests/114/lib/foo.ak @@ -0,0 +1,52 @@ +use aiken/builtin + +pub type Decoder = + fn(ByteArray) -> Option<(a, ByteArray)> + +pub fn data() -> Decoder { + fn(bytes) { + when int()(bytes) is { + Some((n, "")) -> Some((builtin.i_data(n), "")) + _ -> + when list(data())(bytes) is { + Some((xs, "")) -> Some((builtin.list_data(xs), "")) + _ -> None + } + } + } +} + +/// Dummy implementation: always decode two elements +pub fn list(decode_one: Decoder) -> Decoder> { + fn(bytes) { + when decode_one(bytes) is { + Some((a0, bytes)) -> + when decode_one(bytes) is { + Some((a1, bytes)) -> Some(([a0, a1], bytes)) + None -> None + } + None -> None + } + } +} + +/// Dummy implementation: consume the next byte and yield 42. +pub fn int() -> Decoder { + fn(bytes) { + Some( + ( + 42, + builtin.slice_bytearray( + 1, + builtin.length_of_bytearray(bytes) - 1, + bytes, + ), + ), + ) + } +} + +test decode_data() { + let d: Data = [42, 42] + data()(#"0000") == Some((d, "")) +}