-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 35b7344
Showing
7 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: "26.0.2" | ||
gleam-version: "1.0.0" | ||
rebar3-version: "3" | ||
# elixir-version: "1.15.4" | ||
- run: gleam deps download | ||
- run: gleam test | ||
- run: gleam format --check src test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# sprinkle | ||
|
||
[![Package Version](https://img.shields.io/hexpm/v/sprinkle)](https://hex.pm/packages/sprinkle) | ||
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/sprinkle/) | ||
|
||
```sh | ||
gleam add sprinkle | ||
``` | ||
```gleam | ||
import sprinkle.{format} | ||
pub fn main() { | ||
let output = format("My name is {name} and I like to do {activity}!", [ | ||
#("name", "Lily"), | ||
#("activity", "programming") | ||
]) | ||
} | ||
``` | ||
|
||
Further documentation can be found at <https://hexdocs.pm/sprinkle>. | ||
|
||
## Development | ||
|
||
```sh | ||
gleam run # Run the project | ||
gleam test # Run the tests | ||
gleam shell # Run an Erlang shell | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name = "sprinkle" | ||
version = "1.0.0" | ||
|
||
description = "A simple to use string formatting library" | ||
licences = ["AGPL-3.0-only"] | ||
repository = { type = "github", user = "LilyRose2798", repo = "sprinkle" } | ||
|
||
[dependencies] | ||
gleam_stdlib = "~> 0.34 or ~> 1.0" | ||
|
||
[dev-dependencies] | ||
gleeunit = "~> 1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This file was generated by Gleam | ||
# You typically do not need to edit this file | ||
|
||
packages = [ | ||
{ name = "gleam_stdlib", version = "0.36.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "C0D14D807FEC6F8A08A7C9EF8DFDE6AE5C10E40E21325B2B29365965D82EB3D4" }, | ||
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" }, | ||
] | ||
|
||
[requirements] | ||
gleam_stdlib = { version = "~> 0.34 or ~> 1.0" } | ||
gleeunit = { version = "~> 1.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import gleam/string | ||
import gleam/list | ||
|
||
pub fn format(format_string: String, data: List(#(String, String))) -> String { | ||
list.fold(data, format_string, fn(acc, cur) { | ||
string.replace(acc, each: "{" <> cur.0 <> "}", with: cur.1) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import gleeunit | ||
import gleeunit/should | ||
import sprinkle.{format} | ||
|
||
pub fn main() { | ||
gleeunit.main() | ||
} | ||
|
||
pub fn format_single_test() { | ||
format("My name is {name}!", [#("name", "Lily")]) | ||
|> should.equal("My name is Lily!") | ||
} | ||
|
||
pub fn format_mutiple_test() { | ||
format("My name is {name} and I like to do {activity}!", [ | ||
#("name", "Lily"), | ||
#("activity", "programming"), | ||
]) | ||
|> should.equal("My name is Lily and I like to do programming!") | ||
} | ||
|
||
pub fn format_repeated_test() { | ||
format("My name is {name}! Yep, it's definitely {name}.", [#("name", "Lily")]) | ||
|> should.equal("My name is Lily! Yep, it's definitely Lily.") | ||
} |