Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / format / src / tests / external_fn.rs
1.6 kB 95 lines
1// SPDX-License-Identifier: Apache-2.0 2// SPDX-FileCopyrightText: 2023 The Gleam contributors 3 4use crate::assert_format; 5 6#[test] 7fn no_body_erlang() { 8 assert_format!( 9 r#"@external(erlang, "one", "one") 10fn one(x: Int) -> Int 11"# 12 ); 13} 14 15#[test] 16fn no_body_javascript() { 17 assert_format!( 18 r#"@external(javascript, "one", "one") 19fn one(x: Int) -> Int 20"# 21 ); 22} 23 24#[test] 25fn no_body_body() { 26 assert_format!( 27 r#"@external(erlang, "two", "two") 28@external(javascript, "one", "one") 29fn one(x: Int) -> Int 30"# 31 ); 32} 33 34#[test] 35fn erlang() { 36 assert_format!( 37 r#"@external(erlang, "one", "one") 38fn one(x: Int) -> Int { 39 todo 40} 41"# 42 ); 43} 44 45#[test] 46fn javascript() { 47 assert_format!( 48 r#"@external(javascript, "one", "one") 49fn one(x: Int) -> Int { 50 todo 51} 52"# 53 ); 54} 55 56#[test] 57fn body() { 58 assert_format!( 59 r#"@external(erlang, "two", "two") 60@external(javascript, "one", "one") 61fn one(x: Int) -> Int { 62 todo 63} 64"# 65 ); 66} 67 68// https://github.com/gleam-lang/gleam/issues/2259 69#[test] 70fn break_external_fn_arguments() { 71 assert_format!( 72 r#"@external(erlang, "ffi", "improper_list_append") 73fn improper_list_append( 74 a: item_a, 75 b: item_b, 76 c: improper_tail, 77) -> List(anything) 78"# 79 ); 80} 81 82// Bug found by Hayleigh 83#[test] 84fn long_long_external() { 85 assert_format!( 86 r#"@external(javascript, "./client-component.ffi.mjs", "register") 87pub fn register( 88 _app: App(WebComponent, Nil, model, msg), 89 _name: String, 90) -> Result(Nil, Error) { 91 Error(NotABrowser) 92} 93"# 94 ); 95}