1
Fork 0

Compare commits

...

6 Commits
0.1.1 ... main

Author SHA1 Message Date
Bauke 4e92ed4a61
Version 0.1.2! 2024-01-25 13:29:30 +01:00
Bauke 46bdc32daa
Update license year. 2024-01-25 13:26:43 +01:00
Bauke 132d48a024
Fix Clippy issues. 2024-01-25 13:21:29 +01:00
Bauke 32c834a292
Update dependencies. 2024-01-25 13:14:44 +01:00
Bauke ab81ae6591
Add the cargo-make configuration and Development section. 2024-01-25 13:07:15 +01:00
Bauke 0dad193657
Add Nix flake and direnv files. 2024-01-25 13:04:20 +01:00
13 changed files with 241 additions and 75 deletions

3
.envrc Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
use flake

8
.gitignore vendored
View File

@ -1,7 +1,5 @@
# Generated by Cargo .direnv/
Cargo.lock coverage/
debug/ debug/
target/ target/
Cargo.lock
# Code coverage results
coverage/

View File

@ -5,7 +5,7 @@ name = "romantic"
description = "Roman numeral toolkit" description = "Roman numeral toolkit"
repository = "https://git.bauke.xyz/Holllo/romantic" repository = "https://git.bauke.xyz/Holllo/romantic"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
version = "0.1.1" version = "0.1.2"
authors = ["Holllo <helllo@holllo.org>"] authors = ["Holllo <helllo@holllo.org>"]
edition = "2021" edition = "2021"
@ -13,8 +13,8 @@ edition = "2021"
path = "source/lib.rs" path = "source/lib.rs"
[dependencies] [dependencies]
num = "0.4.0" num = "0.4.1"
thiserror = "1.0.36" thiserror = "1.0.56"
[dev-dependencies] [dev-dependencies]
test-case = "2.2.1" test-case = "3.3.1"

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2022 Holllo <helllo@holllo.org> Copyright (c) 2022-2024 Holllo <helllo@holllo.org>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,33 +1,21 @@
[tasks.fmt] # Do a full check of everything.
command = "cargo"
args = ["fmt", "${@}"]
[tasks.check]
command = "cargo"
args = ["check", "${@}"]
[tasks.clippy]
command = "cargo"
args = ["clippy", "${@}"]
[tasks.test]
command = "cargo"
args = ["test", "${@}"]
[tasks.doc]
command = "cargo"
args = ["doc", "${@}"]
[tasks.build]
command = "cargo"
args = ["build", "${@}"]
[tasks.complete-check] [tasks.complete-check]
dependencies = ["fmt", "check", "clippy", "test", "doc", "build"] dependencies = [
"format",
"spellcheck",
"check",
"clippy",
"test",
"code-coverage",
"docs",
"build",
"audit-flow",
"outdated-flow",
]
# Run cargo-tarpaulin and output the test coverage.
[tasks.code-coverage] [tasks.code-coverage]
workspace = false workspace = false
install_crate = "cargo-tarpaulin"
command = "cargo" command = "cargo"
args = [ args = [
"tarpaulin", "tarpaulin",
@ -35,5 +23,10 @@ args = [
"--out=html", "--out=html",
"--output-dir=coverage", "--output-dir=coverage",
"--skip-clean", "--skip-clean",
"--target-dir=target/tarpaulin" "--target-dir=target/tarpaulin",
] ]
# Do a source code spellcheck.
[tasks.spellcheck]
clear = true
command = "typos"

View File

@ -40,6 +40,10 @@ assert_eq!(custom.from_str::<i32>("BA").unwrap(), 6);
assert!(custom.to_string(9).is_err()); assert!(custom.to_string(9).is_err());
``` ```
## Development
With [Nix flakes](https://nixos.wiki/wiki/Flakes) and [direnv](https://direnv.net/) installed and enabled, all the required dependencies are automatically loaded from [`shell.nix`](./shell.nix). Then [cargo-make](https://sagiegurari.github.io/cargo-make/) can be used to build, deploy and lint the code. The available tasks are all described in the [`Makefile.toml`](Makefile.toml) configuration.
## Feedback ## Feedback
Found a problem or want to request a new feature? Email [helllo@holllo.org](mailto:helllo@holllo.org) and I'll see what I can do for you. Found a problem or want to request a new feature? Email [helllo@holllo.org](mailto:helllo@holllo.org) and I'll see what I can do for you.

128
flake.lock Normal file
View File

@ -0,0 +1,128 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1681202837,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1706006310,
"narHash": "sha256-nDPz0fj0IFcDhSTlXBU2aixcnGs2Jm4Zcuoj0QtmiXQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b43bb235efeab5324c5e486882ef46749188eee2",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1681358109,
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1706149103,
"narHash": "sha256-Me28A0tAb1EzZIozfi31+hnsQIaYU0HXaMPWCe+zByc=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "493cc67d5e9f1b298241b8d92aa06883296acc3f",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

17
flake.nix Normal file
View File

@ -0,0 +1,17 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}

3
rustup-toolchain.toml Normal file
View File

@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["cargo", "clippy", "rustfmt", "rust-src"]

18
shell.nix Normal file
View File

@ -0,0 +1,18 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
rustup-toolchain = rust-bin.fromRustupToolchainFile ./rustup-toolchain.toml;
in
mkShell rec {
packages = [
cargo-audit
cargo-edit
cargo-make
cargo-outdated
cargo-tarpaulin
rustup-toolchain
typos
];
}

View File

@ -2,16 +2,16 @@ use romantic::Roman;
use test_case::test_case; use test_case::test_case;
#[test_case(00, ""; "empty")] #[test_case(0, ""; "empty")]
#[test_case(01, "A"; "one")] #[test_case(1, "A"; "one")]
#[test_case(02, "AA"; "two")] #[test_case(2, "AA"; "two")]
#[test_case(03, "AAA"; "three")] #[test_case(3, "AAA"; "three")]
#[test_case(04, "AB"; "four")] #[test_case(4, "AB"; "four")]
#[test_case(05, "B"; "five")] #[test_case(5, "B"; "five")]
#[test_case(06, "BA"; "six")] #[test_case(6, "BA"; "six")]
#[test_case(07, "BAA"; "seven")] #[test_case(7, "BAA"; "seven")]
#[test_case(08, "BAAA"; "eight")] #[test_case(8, "BAAA"; "eight")]
#[test_case(09, "AC"; "nine")] #[test_case(9, "AC"; "nine")]
#[test_case(10, "C"; "ten")] #[test_case(10, "C"; "ten")]
fn test_to_string<T: num::PrimInt + num::Signed + ToString>( fn test_to_string<T: num::PrimInt + num::Signed + ToString>(
input: T, input: T,
@ -21,16 +21,16 @@ fn test_to_string<T: num::PrimInt + num::Signed + ToString>(
assert_eq!(custom.to_string(input).unwrap(), expected); assert_eq!(custom.to_string(input).unwrap(), expected);
} }
#[test_case("", 00; "empty")] #[test_case("", 0; "empty")]
#[test_case("A", 01; "one")] #[test_case("A", 1; "one")]
#[test_case("AA", 02; "two")] #[test_case("AA", 2; "two")]
#[test_case("AAA", 03; "three")] #[test_case("AAA", 3; "three")]
#[test_case("AB", 04; "four")] #[test_case("AB", 4; "four")]
#[test_case("B", 05; "five")] #[test_case("B", 5; "five")]
#[test_case("BA", 06; "six")] #[test_case("BA", 6; "six")]
#[test_case("BAA", 07; "seven")] #[test_case("BAA", 7; "seven")]
#[test_case("BAAA", 08; "eight")] #[test_case("BAAA", 8; "eight")]
#[test_case("AC", 09; "nine")] #[test_case("AC", 9; "nine")]
#[test_case("C", 10; "ten")] #[test_case("C", 10; "ten")]
fn test_from_str(input: &str, expected: i32) { fn test_from_str(input: &str, expected: i32) {
let custom = Roman::new(&['A', 'B', 'C', 'D']); let custom = Roman::new(&['A', 'B', 'C', 'D']);

View File

@ -5,15 +5,15 @@ use test_case::test_case;
#[test_case(0, ""; "empty")] #[test_case(0, ""; "empty")]
#[test_case(3888, "MMMDCCCLXXXVIII"; "all characters")] #[test_case(3888, "MMMDCCCLXXXVIII"; "all characters")]
#[test_case(3999, "MMMCMXCIX"; "maximum")] #[test_case(3999, "MMMCMXCIX"; "maximum")]
#[test_case(01, "I"; "one")] #[test_case(1, "I"; "one")]
#[test_case(02, "II"; "two")] #[test_case(2, "II"; "two")]
#[test_case(03, "III"; "three")] #[test_case(3, "III"; "three")]
#[test_case(04, "IV"; "four")] #[test_case(4, "IV"; "four")]
#[test_case(05, "V"; "five")] #[test_case(5, "V"; "five")]
#[test_case(06, "VI"; "six")] #[test_case(6, "VI"; "six")]
#[test_case(07, "VII"; "seven")] #[test_case(7, "VII"; "seven")]
#[test_case(08, "VIII"; "eight")] #[test_case(8, "VIII"; "eight")]
#[test_case(09, "IX"; "nine")] #[test_case(9, "IX"; "nine")]
#[test_case(10, "X"; "ten")] #[test_case(10, "X"; "ten")]
fn test_to_string<T: num::PrimInt + num::Signed + ToString>( fn test_to_string<T: num::PrimInt + num::Signed + ToString>(
input: T, input: T,
@ -25,15 +25,15 @@ fn test_to_string<T: num::PrimInt + num::Signed + ToString>(
#[test_case("", 0; "empty")] #[test_case("", 0; "empty")]
#[test_case("MMMDCCCLXXXVIII", 3888; "complicated")] #[test_case("MMMDCCCLXXXVIII", 3888; "complicated")]
#[test_case("MMMCMXCIX", 3999; "maximum")] #[test_case("MMMCMXCIX", 3999; "maximum")]
#[test_case("I", 01; "one")] #[test_case("I", 1; "one")]
#[test_case("II", 02; "two")] #[test_case("II", 2; "two")]
#[test_case("III", 03; "three")] #[test_case("III", 3; "three")]
#[test_case("IV", 04; "four")] #[test_case("IV", 4; "four")]
#[test_case("V", 05; "five")] #[test_case("V", 5; "five")]
#[test_case("VI", 06; "six")] #[test_case("VI", 6; "six")]
#[test_case("VII", 07; "seven")] #[test_case("VII", 7; "seven")]
#[test_case("VIII", 08; "eight")] #[test_case("VIII", 8; "eight")]
#[test_case("IX", 09; "nine")] #[test_case("IX", 9; "nine")]
#[test_case("X", 10; "ten")] #[test_case("X", 10; "ten")]
fn test_from_str(input: &str, expected: i32) { fn test_from_str(input: &str, expected: i32) {
assert_eq!(Roman::default().from_str::<i32>(input).unwrap(), expected); assert_eq!(Roman::default().from_str::<i32>(input).unwrap(), expected);

2
typos.toml Normal file
View File

@ -0,0 +1,2 @@
[default.extend-words]
BA = "BA"