Skip to content

Commit 545ad9a

Browse files
authored
Merge pull request #9 from vlemann/master
Use `defmacro/2` to define a guard
2 parents 28c5e21 + ea4c4f8 commit 545ad9a

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

.github/workflows/elixir.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
name: Elixir CI
7+
8+
on:
9+
push:
10+
branches: [ "master" ]
11+
pull_request:
12+
branches: [ "master" ]
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
20+
runs-on: ubuntu-latest
21+
22+
name: OTP ${{matrix.pair.otp}} / Elixir ${{matrix.pair.elixir}}
23+
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- pair:
29+
otp: 25
30+
elixir: 1.14
31+
- pair:
32+
otp: 27
33+
elixir: 1.18
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: erlef/setup-elixir@v1
37+
with:
38+
otp-version: ${{matrix.pair.otp}}
39+
elixir-version: ${{matrix.pair.elixir}}
40+
- name: Dependencies Cache
41+
uses: actions/cache@v3
42+
with:
43+
path: deps
44+
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
45+
restore-keys: ${{ runner.os }}-mix-
46+
- name: Install Dependencies
47+
run: mix deps.get
48+
- name: Test
49+
run: mix test

lib/unicode_guards.ex

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,11 @@ defmodule Unicode.Guards do
155155

156156
@doc false
157157
# Replaced by `is_graph/1`.
158-
defguard is_visible(codepoint)
159-
when is_integer(codepoint) and match?(codepoint, "[[:visible:]]")
158+
defmacro is_visible(codepoint) do
159+
quote generated: true, location: :keep do
160+
is_integer(unquote(codepoint)) and match?(unquote(codepoint), "[[:visible:]]")
161+
end
162+
end
160163

161164
@doc """
162165
Guards whether a UTF8 codepoint is a graphic character.
@@ -166,8 +169,11 @@ defmodule Unicode.Guards do
166169
non-space, non-control and non-surrogate.
167170
168171
"""
169-
defguard is_graph(codepoint)
170-
when is_integer(codepoint) and match?(codepoint, "[[:graph:]]")
172+
defmacro is_graph(codepoint) do
173+
quote generated: true, location: :keep do
174+
is_integer(unquote(codepoint)) and match?(unquote(codepoint), "[[:graph:]]")
175+
end
176+
end
171177

172178
@doc """
173179
Guards whether a UTF8 codepoint is a space character.
@@ -187,6 +193,9 @@ defmodule Unicode.Guards do
187193
`[:graph:]` set and the `[:blank:]` set.
188194
189195
"""
190-
defguard is_print(codepoint)
191-
when is_integer(codepoint) and match?(codepoint, "[[:print:]]")
196+
defmacro is_print(codepoint) do
197+
quote generated: true, location: :keep do
198+
is_integer(unquote(codepoint)) and match?(unquote(codepoint), "[[:print:]]")
199+
end
200+
end
192201
end

0 commit comments

Comments
 (0)