Skip to content

Commit a17dcc1

Browse files
GearsDatapackslpil
authored andcommitted
Add codepoint tests
1 parent dcdde33 commit a17dcc1

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

test/language/test/ffi.gleam

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ pub fn halt(a: Int) -> Nil
2323
@external(erlang, "ffi_erlang", "to_dynamic")
2424
@external(javascript, "./ffi_javascript.mjs", "toDynamic")
2525
pub fn to_dynamic(a: x) -> Dynamic
26+
27+
@external(erlang, "ffi_erlang", "to_codepoint")
28+
@external(javascript, "./ffi_javascript.mjs", "toCodepoint")
29+
pub fn utf_codepoint(a: Int) -> UtfCodepoint

test/language/test/ffi_erlang.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
-module(ffi_erlang).
22

33
-export([
4-
to_string/1, append/2, print/1, file_exists/1, halt/1, to_dynamic/1
4+
to_string/1, append/2, print/1, file_exists/1, halt/1, to_dynamic/1, to_codepoint/1
55
]).
66

77
append(A, B) ->
88
<<A/binary, B/binary>>.
99

1010
print(S) ->
11-
io:format("~s", [S]),
11+
io:format("~s", [S]),
1212
nil.
1313

1414
to_string(Term) ->
@@ -23,3 +23,5 @@ halt(Code) ->
2323

2424
to_dynamic(X) ->
2525
X.
26+
27+
to_codepoint(X) -> X.

test/language/test/ffi_javascript.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { UtfCodepoint } from "./gleam.mjs";
2+
13
let fs;
24

35
if (!globalThis.Deno) {
@@ -50,3 +52,7 @@ export function halt(code) {
5052
export function toDynamic(a) {
5153
return a;
5254
}
55+
56+
export function toCodepoint(x) {
57+
return new UtfCodepoint(x);
58+
}

test/language/test/language_test.gleam

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,22 @@ fn non_utf8_string_bit_array_tests() -> List(Test) {
16981698
message
16991699
})
17001700
}),
1701+
"UTF-16 codepoint"
1702+
|> example(fn() {
1703+
assert_equal(<<216, 60, 223, 13>>, {
1704+
// 🌍
1705+
let codepoint = ffi.utf_codepoint(127_757)
1706+
<<codepoint:utf16_codepoint>>
1707+
})
1708+
}),
1709+
"UTF-32 codepoint"
1710+
|> example(fn() {
1711+
assert_equal(<<0, 1, 243, 13>>, {
1712+
// 🌍
1713+
let codepoint = ffi.utf_codepoint(127_757)
1714+
<<codepoint:utf32_codepoint>>
1715+
})
1716+
}),
17011717
]
17021718
}
17031719

0 commit comments

Comments
 (0)