mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Add failing single-tag-union glue test
This commit is contained in:
parent
1a1d1da51a
commit
efa31ae747
4 changed files with 119 additions and 0 deletions
6
crates/glue/tests/fixtures/single-tag-union/app.roc
vendored
Normal file
6
crates/glue/tests/fixtures/single-tag-union/app.roc
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
app "app"
|
||||||
|
packages { pf: "platform.roc" }
|
||||||
|
imports []
|
||||||
|
provides [main] to pf
|
||||||
|
|
||||||
|
main = OneTag
|
11
crates/glue/tests/fixtures/single-tag-union/platform.roc
vendored
Normal file
11
crates/glue/tests/fixtures/single-tag-union/platform.roc
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
platform "test-platform"
|
||||||
|
requires {} { main : _ }
|
||||||
|
exposes []
|
||||||
|
packages {}
|
||||||
|
imports []
|
||||||
|
provides [mainForHost]
|
||||||
|
|
||||||
|
SingleTagUnion : [OneTag]
|
||||||
|
|
||||||
|
mainForHost : SingleTagUnion
|
||||||
|
mainForHost = main
|
99
crates/glue/tests/fixtures/single-tag-union/src/lib.rs
vendored
Normal file
99
crates/glue/tests/fixtures/single-tag-union/src/lib.rs
vendored
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
mod test_glue;
|
||||||
|
|
||||||
|
use indoc::indoc;
|
||||||
|
use test_glue::SingleTagUnion;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#[link_name = "roc__mainForHost_1_exposed_generic"]
|
||||||
|
fn roc_main(_: *mut SingleTagUnion);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn rust_main() -> i32 {
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
use std::collections::hash_set::HashSet;
|
||||||
|
|
||||||
|
let tag_union = unsafe {
|
||||||
|
let mut ret: core::mem::MaybeUninit<SingleTagUnion> = core::mem::MaybeUninit::uninit();
|
||||||
|
|
||||||
|
roc_main(ret.as_mut_ptr());
|
||||||
|
|
||||||
|
ret.assume_init()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Verify that it has all the expected traits.
|
||||||
|
|
||||||
|
assert!(tag_union == SingleTagUnion::OneTag); // PartialEq
|
||||||
|
assert!(tag_union.clone() == tag_union.clone()); // Clone
|
||||||
|
|
||||||
|
assert!(tag_union.partial_cmp(&tag_union) == Some(Ordering::Equal)); // PartialOrd
|
||||||
|
assert!(tag_union.cmp(&tag_union) == Ordering::Equal); // Ord
|
||||||
|
|
||||||
|
print!(
|
||||||
|
indoc!(
|
||||||
|
r#"
|
||||||
|
tag_union was: {:?}
|
||||||
|
"#
|
||||||
|
),
|
||||||
|
tag_union,
|
||||||
|
); // Debug
|
||||||
|
|
||||||
|
let mut set = HashSet::new();
|
||||||
|
|
||||||
|
set.insert(tag_union.clone()); // Eq, Hash
|
||||||
|
set.insert(tag_union);
|
||||||
|
|
||||||
|
assert_eq!(set.len(), 1);
|
||||||
|
|
||||||
|
// Exit code
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Externs required by roc_std and by the Roc app
|
||||||
|
|
||||||
|
use core::ffi::c_void;
|
||||||
|
use std::ffi::CStr;
|
||||||
|
use std::os::raw::c_char;
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn roc_alloc(size: usize, _alignment: u32) -> *mut c_void {
|
||||||
|
return libc::malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn roc_realloc(
|
||||||
|
c_ptr: *mut c_void,
|
||||||
|
new_size: usize,
|
||||||
|
_old_size: usize,
|
||||||
|
_alignment: u32,
|
||||||
|
) -> *mut c_void {
|
||||||
|
return libc::realloc(c_ptr, new_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn roc_dealloc(c_ptr: *mut c_void, _alignment: u32) {
|
||||||
|
return libc::free(c_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn roc_panic(c_ptr: *mut c_void, tag_id: u32) {
|
||||||
|
match tag_id {
|
||||||
|
0 => {
|
||||||
|
let slice = CStr::from_ptr(c_ptr as *const c_char);
|
||||||
|
let string = slice.to_str().unwrap();
|
||||||
|
eprintln!("Roc hit a panic: {}", string);
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
_ => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn roc_memcpy(dst: *mut c_void, src: *mut c_void, n: usize) -> *mut c_void {
|
||||||
|
libc::memcpy(dst, src, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut c_void {
|
||||||
|
libc::memset(dst, c, n)
|
||||||
|
}
|
|
@ -79,6 +79,9 @@ mod glue_cli_run {
|
||||||
`Baz` is: NonRecursive::Baz
|
`Baz` is: NonRecursive::Baz
|
||||||
`Blah 456` is: NonRecursive::Blah(456)
|
`Blah 456` is: NonRecursive::Blah(456)
|
||||||
"#),
|
"#),
|
||||||
|
single_tag_union:"single-tag-union" => indoc!(r#"
|
||||||
|
tag_union was: SingleTagUnion::OneTag
|
||||||
|
"#),
|
||||||
union_without_padding:"union-without-padding" => indoc!(r#"
|
union_without_padding:"union-without-padding" => indoc!(r#"
|
||||||
tag_union was: NonRecursive::Foo("This is a test")
|
tag_union was: NonRecursive::Foo("This is a test")
|
||||||
`Foo "small str"` is: NonRecursive::Foo("small str")
|
`Foo "small str"` is: NonRecursive::Foo("small str")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue