Skip to content

Commit ea0e22a

Browse files
Milan RougemontMilan Rougemont
authored andcommitted
Adding CI, making the library available to older elixir versions
1 parent fd8647a commit ea0e22a

File tree

8 files changed

+110
-14
lines changed

8 files changed

+110
-14
lines changed

.formatter.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# .formatter.exs
2+
[
3+
import_deps: [:credo, :ex_doc],
4+
inputs: [
5+
"{mix,.formatter}.exs",
6+
"{config,lib,test}/**/*.{ex,exs}"
7+
],
8+
line_length: 100
9+
]

.github/workflows/ci.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# .github/workflows/ci.yml
2+
name: CI
3+
4+
on:
5+
push:
6+
pull_request:
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lint:
15+
name: Lint & Docs (latest)
16+
runs-on: ubuntu-latest
17+
env:
18+
MIX_ENV: dev
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: erlef/setup-beam@v1
22+
with:
23+
elixir-version: "1.18.4"
24+
otp-version: "27.0"
25+
install-hex: true
26+
install-rebar: true
27+
- run: mix deps.get
28+
- run: mix format --check-formatted
29+
- run: mix credo --strict
30+
- run: mix docs
31+
- run: mix hex.build
32+
33+
test:
34+
name: Test (Elixir 1.12, 1.15, 1.18)
35+
needs: lint
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
include:
40+
# Elixir 1.12: use ubuntu-22.04 + OTP 24.3 (non-legacy on 22.04)
41+
- elixir: "1.12.3"
42+
otp: "24.3"
43+
runner: ubuntu-22.04
44+
# Modern combos on ubuntu-latest
45+
- elixir: "1.15.8"
46+
otp: "26.2"
47+
runner: ubuntu-latest
48+
- elixir: "1.18.4"
49+
otp: "27.0"
50+
runner: ubuntu-latest
51+
runs-on: ${{ matrix.runner }}
52+
env:
53+
MIX_ENV: test
54+
steps:
55+
- uses: actions/checkout@v4
56+
- uses: erlef/setup-beam@v1
57+
with:
58+
elixir-version: ${{ matrix.elixir }}
59+
otp-version: ${{ matrix.otp }}
60+
install-hex: true
61+
install-rebar: true
62+
- run: mix deps.get --only $MIX_ENV
63+
- run: mix compile --warnings-as-errors
64+
- run: mix test --color --trace
65+

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,3 @@ calque-*.tar
2121

2222
# Temporary files, for example, from tests.
2323
/tmp/
24-
25-
.DS_Store
26-
.formatter.exs
27-
mix.lock

lib/calque.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defmodule Calque do
2828
---
2929
"""
3030

31-
alias Calque.{Snapshot, Diff, Error, Levenshtein}
31+
alias Calque.{Diff, Error, Levenshtein, Snapshot}
3232

3333
@type snapshot :: Snapshot.t()
3434

@@ -195,7 +195,7 @@ defmodule Calque do
195195
end
196196

197197
# -------------------------
198-
# FILE OPERATIONS
198+
# FILE OPERATIONS
199199
# -------------------------
200200

201201
@doc false
@@ -297,7 +297,7 @@ defmodule Calque do
297297
defp to_accepted_path(path), do: String.replace_suffix(path, ".snap", ".accepted.snap")
298298

299299
# -------------------------
300-
# SNAPSHOT DE/SERIALIZATION
300+
# SNAPSHOT DE/SERIALIZATION
301301
# -------------------------
302302

303303
@doc false
@@ -351,7 +351,7 @@ defmodule Calque do
351351
end
352352

353353
# -------------------------
354-
# SNAPSHOT DIFFING
354+
# SNAPSHOT DIFFING
355355
# -------------------------
356356

357357
@doc false
@@ -376,7 +376,7 @@ defmodule Calque do
376376
end
377377

378378
# -------------------------
379-
# PRETTY PRINTING
379+
# PRETTY PRINTING
380380
# -------------------------
381381

382382
@doc false

lib/levenshtein.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ defmodule Calque.Levenshtein do
4040
up_left0 = hd(prev_row)
4141

4242
{row_rev, _last_up} =
43-
Enum.reduce(Enum.with_index(t, 1), {[first_cell], up_left0}, fn {tc, j},
44-
{row_rev, up_left} ->
43+
Enum.reduce(Enum.with_index(t, 1), {[first_cell], up_left0}, fn {tc, j}, {row_rev, up_left} ->
4544
left = hd(row_rev)
4645
up = Enum.at(prev_row, j)
4746
cost = if sc == tc, do: 0, else: 1

lib/snapshot.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
defmodule Calque.Snapshot do
2+
@moduledoc """
3+
Represents a **snapshot** — a saved version of output data used by Calque’s
4+
snapshot testing system.
5+
6+
A snapshot encapsulates:
7+
- `:title` — A human-readable identifier, often matching the test name.
8+
- `:content` — The stringified output captured during the test run.
9+
- `:status` — Either `:new` (freshly generated and unreviewed) or `:accepted`
10+
(already validated and stored).
11+
12+
This module provides simple constructors to ensure consistent initialization:
13+
- `new/2` — Creates a new, unaccepted snapshot.
14+
- `accepted/2` — Builds an accepted snapshot loaded from disk.
15+
16+
Snapshots are immutable data structures; their lifecycle and comparison logic
17+
are handled by higher-level modules such as `Calque` and `Calque.Diff`.
18+
"""
19+
220
@enforce_keys [:title, :content, :status]
321
defstruct [:title, :content, :status]
422

mix.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ defmodule Calque.MixProject do
55
[
66
app: :calque,
77
version: "1.3.0",
8-
elixir: "~> 1.15",
9-
description:
10-
"A simple snapshot testing library inspired by Birdie (Gleam) and Insta (Rust).",
8+
elixir: "~> 1.12",
9+
description: "A simple snapshot testing library inspired by Birdie (Gleam) and Insta (Rust).",
1110
package: package(),
1211
deps: deps(),
1312
source_url: "https://github.com/milaneuh/calque",

mix.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
%{
2+
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
3+
"credo": {:hex, :credo, "1.7.13", "126a0697df6b7b71cd18c81bc92335297839a806b6f62b61d417500d1070ff4e", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "47641e6d2bbff1e241e87695b29f617f1a8f912adea34296fb10ecc3d7e9e84f"},
4+
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
5+
"ex_doc": {:hex, :ex_doc, "0.38.4", "ab48dff7a8af84226bf23baddcdda329f467255d924380a0cf0cee97bb9a9ede", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "f7b62346408a83911c2580154e35613eb314e0278aeea72ed7fedef9c1f165b2"},
26
"exdiff": {:hex, :exdiff, "0.1.5", "3e55bd840214508fd478d91fb07f1671d90d2f0d6f5266296e3b596e07d92305", [:mix], [], "hexpm", "b1ccef642edc28ed3acf1b08c8dbc6e42852d18dfe51b453529588e53c733eba"},
7+
"file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"},
8+
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
9+
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
10+
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
11+
"makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"},
12+
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
313
}

0 commit comments

Comments
 (0)