diff --git a/Cargo.lock b/Cargo.lock index c8e5ab1..5d9a0fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -127,7 +127,7 @@ dependencies = [ [[package]] name = "folgezettel" -version = "0.3.0" +version = "0.3.1" dependencies = [ "camino", "clap", diff --git a/flake.lock b/flake.lock index 116c022..dc81f36 100644 --- a/flake.lock +++ b/flake.lock @@ -34,34 +34,13 @@ "type": "github" } }, - "gitignore": { - "inputs": { - "nixpkgs": [ - "pre-commit-hooks", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1709087332, - "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", - "owner": "hercules-ci", - "repo": "gitignore.nix", - "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "gitignore.nix", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1781509190, - "narHash": "sha256-uJZs9Di8I6ciTp6jiojj0HzlNpBkud8ax5aT/O5aJkw=", + "lastModified": 1782847189, + "narHash": "sha256-twXPFqFsrrY5r28Zh7Homgcp2gUMBgQ6WDS98Q/3xFI=", "owner": "nixos", "repo": "nixpkgs", - "rev": "d6df3513510aa548c83868fd22bfddd0a8c0a0d4", + "rev": "b6018f87da91d19d0ab4cf979885689b469cdd41", "type": "github" }, "original": { @@ -73,11 +52,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1770073757, - "narHash": "sha256-Vy+G+F+3E/Tl+GMNgiHl9Pah2DgShmIUBJXmbiQPHbI=", + "lastModified": 1782918843, + "narHash": "sha256-ETYnV9U7Sr+A45dohzZdfCZKOss4qrTkO+wgNZNvEc0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "47472570b1e607482890801aeaf29bfb749884f6", + "rev": "e8273b29fe1390ec8d4603f2477357555291432e", "type": "github" }, "original": { @@ -106,15 +85,14 @@ "pre-commit-hooks": { "inputs": { "flake-compat": "flake-compat", - "gitignore": "gitignore", "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1778507602, - "narHash": "sha256-kTwur1wV+01SdqskVMSo6JMEpg71ps3HpbFY2GsflKs=", + "lastModified": 1784288435, + "narHash": "sha256-ReRHaLgr/uVqdD8afFSn+myXIfpHeOhP0yYe0TJqAA8=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "61ab0e80d9c7ab14c256b5b453d8b3fb0189ba0a", + "rev": "43b3c1ab9d40fb1dbb008f451988a91e375825e9", "type": "github" }, "original": { @@ -151,11 +129,11 @@ "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1780220602, - "narHash": "sha256-eynAfOmbmxJnkp7YewvCEbShNnnYJ9gLLqkzsYtBPeM=", + "lastModified": 1784369104, + "narHash": "sha256-47cxbcZODibHv3rELFQ9vZly0vUNkND/atn/U7HLeb0=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "db947814a175b7ca6ded66e21383d938df01c227", + "rev": "df3c0640565d04a0261253cdd89fce78ec50168a", "type": "github" }, "original": { diff --git a/src/id.rs b/src/id.rs index ac3ca99..fff4a77 100644 --- a/src/id.rs +++ b/src/id.rs @@ -87,14 +87,14 @@ impl FolgezettelId { let mut next_kind = Kind::Number; while position < input.len() { - let next = input[position..].chars().next(); - - if let Some(separator) = next.filter(|c| !segments.is_empty() && SEPARATORS.contains(c)) + if let Some(separator) = input[position..] + .chars() + .next() + .filter(|c| !segments.is_empty() && SEPARATORS.contains(c)) { position += separator.len_utf8(); segments.push(Segment::Separator(separator)); next_kind = next_kind.toggle(); - continue; } let rest = &input[position..]; @@ -189,6 +189,23 @@ fn reject_malformed_ids() { ); } +#[test] +fn reject_dangling_separators() { + for (input, expected) in [ + ("1.", ParseIdError::ExpectedNumber { position: 2 }), + ("1...", ParseIdError::ExpectedNumber { position: 2 }), + ("1..2", ParseIdError::ExpectedNumber { position: 2 }), + ("1a.", ParseIdError::ExpectedLetter { position: 3 }), + (".1", ParseIdError::ExpectedNumber { position: 0 }), + ] { + assert_eq!( + FolgezettelId::parse(input).unwrap_err(), + expected, + "parsing {input:?}" + ); + } +} + #[test] fn normalizes_uppercase_letters() { assert_eq!(