Skip to content

Commit

Permalink
fix: descending ordered keys to prevent greedy matching of shorter va…
Browse files Browse the repository at this point in the history
…riants
  • Loading branch information
lavafroth committed Oct 15, 2024
1 parent a91d1ab commit c1f516d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sweet"
description = "simple wayland event encoding text"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
build = "build.rs"

Expand Down
35 changes: 20 additions & 15 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@

inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells.default = pkgs.mkShell rec {
packages = with pkgs;
[
stdenv.cc.cc.lib
];
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell rec {
packages = with pkgs; [
stdenv.cc.cc.lib
];

LD_LIBRARY_PATH = "${nixpkgs.lib.makeLibraryPath packages}";
LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
};
}
);
LD_LIBRARY_PATH = "${nixpkgs.lib.makeLibraryPath packages}";
};
}
);
}
18 changes: 9 additions & 9 deletions template.pest
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,6 @@ key_base = {
| ^"next"
| ^"pagedown"
| ^"pageup"
| ^"f1"
| ^"f2"
| ^"f3"
| ^"f4"
| ^"f5"
| ^"f6"
| ^"f7"
| ^"f8"
| ^"f9"
| ^"f10"
| ^"f11"
| ^"f12"
Expand All @@ -126,6 +117,15 @@ key_base = {
| ^"f22"
| ^"f23"
| ^"f24"
| ^"f1"
| ^"f2"
| ^"f3"
| ^"f4"
| ^"f5"
| ^"f6"
| ^"f7"
| ^"f8"
| ^"f9"
| ASCII_ALPHANUMERIC
}

Expand Down
21 changes: 21 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@ w
Ok(())
}

#[test]
fn test_greedy_ordering() -> Result<(), ParseError> {
let contents = "
f9
librewolf
f12
kitty
";
let parsed = SwhkdParser::from(ParserInput::Raw(&contents))?;

let known = vec![
Binding::running("librewolf").on(Definition::new(evdev::Key::KEY_F9)),
Binding::running("kitty").on(Definition::new(evdev::Key::KEY_F12)),
];

assert_eq!(parsed.bindings, known);

Ok(())
}

#[test]
// this test is stricter than the previous parser
// gimp is not a valid key or a modifier
Expand Down

0 comments on commit c1f516d

Please sign in to comment.