Skip to content

Commit

Permalink
Add Cldr.Json.decode!/1to wrap OTP27 :json.decode/1
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed Jun 23, 2024
1 parent ff62031 commit 572cfb5
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 25 deletions.
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Changelog

**Cldr Utils from version 2.18.0 requires Elixir 1.11 or later**
**Cldr Utils from version 2.26.0 requires Elixir 1.12 or later**

## Cldr Utils version 2.26.0

This is the changelog for Cldr Utils v2.26.0 released on June 23rd, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_utils/tags)

### Minimu Elixir version

* `cldr_utils` requires Elixir 1.12 or later.

### Enhancements

* Adds `Cldr.Json.decode!/1` that delegates to `:json.decode/1`. This allows `Cldr.Json` to be configured as a `json_library` in `ex_cldr` for OTP versions 27 and later. For example:

```elixir
config :ex_cldr,
json_library: Cldr.Json
```

* Refactor some tests so they work on older Elixir versions without `sigil_c`.

## Cldr Utils version 2.26.0

Expand Down Expand Up @@ -28,7 +47,7 @@ This is the changelog for Cldr Utils v2.24.2 released on November 2nd, 2023. Fo

### Bug Fixes

* Fix depracation warnings for Elixir 1.16.
* Fix deprecation warnings for Elixir 1.16.

## Cldr Utils version 2.24.1

Expand Down
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Utility functions extracted from [Cldr](https://github.com/elixir-cldr/cldr).
* Math functions including `mod/2` that works on floored division
* Number functions for working with the number of digits, the fraction as an integer, ...
* String function for underscoring (converting CamelCase to snake case)
* Cldr.Json.decode!/1 to wrap OTP 27's `:json` module
* Various macros

## Installation
Expand All @@ -26,17 +27,9 @@ def deps do
end
```

## Benchmark

To run the benchmark:

```bash
$ mix run benchee/decimal.exs
```

## Copyright and License

Copyright (c) 2017 Kip Cole
Copyright (c) 2017-2024 Kip Cole

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
24 changes: 24 additions & 0 deletions lib/cldr/utils/json.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if Code.ensure_loaded?(:json) do
defmodule Cldr.Json do
@moduledoc """
A wrapper for the OTP 27 :json module.
It implements a `decode!/1` function that wraps
`:json.decode/1` with `decode!/1` so that its
compatible with the calling conventions of
Elixir - which is used by `ex_cldr`.
This allows configuration such as:
```elixir
config :ex_cldr,
json_library: Cldr.Json
```
"""

def decode!(string) do
:json.decode(string)
end

end
end
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
defmodule Cldr.Utils.MixProject do
use Mix.Project

@version "2.26.0"
@version "2.27.0"
@source_url "https://github.com/elixir-cldr/cldr_utils"

def project do
[
app: :cldr_utils,
version: @version,
elixir: "~> 1.11",
elixir: "~> 1.12",
description: description(),
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down Expand Up @@ -43,7 +43,7 @@ defmodule Cldr.Utils.MixProject do
{:castore, "~> 0.1 or ~> 1.0", optional: true},
{:certifi, "~> 2.5", optional: true},
{:ex_doc, ">= 0.0.0", optional: true, only: [:dev, :release], runtime: false},
{:stream_data, "~> 0.5", optional: true, only: :test},
{:stream_data, "~> 1.0", optional: true, only: :test},
{:dialyxir, "~> 1.0", optional: true, only: [:dev, :test], runtime: false},
{:benchee, "~> 1.0", optional: true, only: [:dev], runtime: false}
]
Expand Down
14 changes: 7 additions & 7 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
%{
"benchee": {:hex, :benchee, "1.3.0", "f64e3b64ad3563fa9838146ddefb2d2f94cf5b473bdfd63f5ca4d0657bf96694", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "34f4294068c11b2bd2ebf2c59aac9c7da26ffa0068afdf3419f1b176e16c5f81"},
"castore": {:hex, :castore, "1.0.6", "ffc42f110ebfdafab0ea159cd43d31365fa0af0ce4a02ecebf1707ae619ee727", [:mix], [], "hexpm", "374c6e7ca752296be3d6780a6d5b922854ffcc74123da90f2f328996b962d33a"},
"benchee": {:hex, :benchee, "1.3.1", "c786e6a76321121a44229dde3988fc772bca73ea75170a73fd5f4ddf1af95ccf", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "76224c58ea1d0391c8309a8ecbfe27d71062878f59bd41a390266bf4ac1cc56d"},
"castore": {:hex, :castore, "1.0.7", "b651241514e5f6956028147fe6637f7ac13802537e895a724f90bf3e36ddd1dd", [:mix], [], "hexpm", "da7785a4b0d2a021cd1292a60875a784b6caef71e76bf4917bdee1f390455cf5"},
"certifi": {:hex, :certifi, "2.13.0", "e52be248590050b2dd33b0bb274b56678f9068e67805dca8aa8b1ccdb016bbf6", [:rebar3], [], "hexpm", "8f3d9533a0f06070afdfd5d596b32e21c6580667a492891851b0e2737bc507a1"},
"cldr_utils": {:hex, :cldr_utils, "2.13.1", "e066dfb426b638751f1b6f39dd3398f10d5f16e049317bf435193ce8f77e5b2a", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "19092aa029e518af24463af1798d6efac1b85126501f32b3b5a8de0fcd2d2249"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
"earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.31.2", "8b06d0a5ac69e1a54df35519c951f1f44a7b7ca9a5bb7a260cd8a174d6322ece", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "317346c14febaba9ca40fd97b5b5919f7751fb85d399cc8e7e8872049f37e0af"},
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
"ex_doc": {:hex, :ex_doc, "0.34.1", "9751a0419bc15bc7580c73fde506b17b07f6402a1e5243be9e0f05a68c723368", [:mix], [{:earmark_parser, "~> 1.4.39", [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", "d441f1a86a235f59088978eff870de2e815e290e44a8bd976fe5d64470a4c9d2"},
"makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [: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", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
"stream_data": {:hex, :stream_data, "0.6.0", "e87a9a79d7ec23d10ff83eb025141ef4915eeb09d4491f79e52f2562b73e5f47", [:mix], [], "hexpm", "b92b5031b650ca480ced047578f1d57ea6dd563f5b57464ad274718c9c29501c"},
"stream_data": {:hex, :stream_data, "1.1.1", "fd515ca95619cca83ba08b20f5e814aaf1e5ebff114659dc9731f966c9226246", [:mix], [], "hexpm", "45d0cd46bd06738463fd53f22b70042dbb58c384bb99ef4e7576e7bb7d3b8c8c"},
}
6 changes: 6 additions & 0 deletions test/cldr_utils_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ defmodule CldrUtilsTest do
doctest Cldr.Helpers
doctest Cldr.Map
doctest Cldr.String

if Code.ensure_loaded?(:json) do
test "Cldr.Json proxy" do
assert Cldr.Json.decode!("{}") == %{}
end
end
end
9 changes: 5 additions & 4 deletions test/http_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ defmodule Cldr.Http.Test do

test "Downloading an unknown url" do
capture_log(fn ->
assert {:error, :nxdomain} = Cldr.Http.get("https://zzzzzzzzzzzzzzzz.com")
end) =~ "Failed to connect to 'zzzzzzzzzzzzzzzz.com'"
assert {:error, :nxdomain} = Cldr.Http.get("https://xzzzzzzzzzzzzzzzz.com")
end) =~ "Failed to connect to 'xzzzzzzzzzzzzzzzz.com'"
end

test "Request with headers" do
Expand All @@ -33,12 +33,13 @@ defmodule Cldr.Http.Test do

if Version.compare(System.version(), "1.14.9") == :gt do
test "Request with connection timeout" do

options = [connection_timeout: 2]

assert capture_log(fn ->
assert {:error, :connection_timeout} =
Cldr.Http.get_with_headers({"https://google.com", [{@accept_language, @any}]}, options)
end) =~ "Timeout connecting to ~c\"google.com\""
end) =~ "Timeout connecting to"
end

test "Request with timeout" do
Expand All @@ -47,7 +48,7 @@ defmodule Cldr.Http.Test do
assert capture_log(fn ->
assert {:error, :timeout} =
Cldr.Http.get_with_headers({"https://google.com", [{@accept_language, @any}]}, options)
end) =~ "Timeout downloading from ~c\"https://google.com\". Request exceeded #{inspect options[:timeout]}ms."
end) =~ "Timeout downloading from"
end
end
end

0 comments on commit 572cfb5

Please sign in to comment.