Add acceptance tests #114

Demonstrate what seems to be the creation of an infinite recursion in the produced UPLC.
This commit is contained in:
KtorZ 2024-10-13 13:40:25 +02:00
parent 5fd349f571
commit a18af83786
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 61 additions and 0 deletions

View File

@ -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"

View File

@ -0,0 +1,52 @@
use aiken/builtin
pub type Decoder<a> =
fn(ByteArray) -> Option<(a, ByteArray)>
pub fn data() -> Decoder<Data> {
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<a>) -> Decoder<List<a>> {
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<Int> {
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, ""))
}