Skip to content

Commit

Permalink
Format code, recreate generated files and enforce format in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pyfisch committed Aug 13, 2023
1 parent 61f09ea commit 7be7932
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 28 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- run: cargo test

clippy:
name: Clippy
clippy-fmt:
name: Run Clippy and format code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
components: clippy, rustfmt
- run: cargo clippy --all-targets -- -D warnings
- run: cargo fmt --check
2 changes: 2 additions & 0 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def add_alternative_for(display, key, alternative):
def convert_key(text, file):
print("""
// AUTO GENERATED CODE - DO NOT EDIT
#![cfg_attr(rustfmt, rustfmt_skip)]
use std::fmt::{self, Display};
use std::str::FromStr;
Expand Down Expand Up @@ -141,6 +142,7 @@ def convert_key(text, file):
def convert_code(text, file):
print("""
// AUTO GENERATED CODE - DO NOT EDIT
#![cfg_attr(rustfmt, rustfmt_skip)]
use std::fmt::{self, Display};
use std::str::FromStr;
Expand Down
3 changes: 2 additions & 1 deletion src/code.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// AUTO GENERATED CODE - DO NOT EDIT
#![cfg_attr(rustfmt, rustfmt_skip)]

use std::fmt::{self, Display};
use std::str::FromStr;
Expand Down Expand Up @@ -180,7 +181,7 @@ pub enum Code {
/// Note that on Apple keyboards, the key labelled <code class="keycap">Delete</code> on the main part of
/// the keyboard should be encoded as <code class="code">"Backspace"</code>.
Delete,
/// <code class="keycap">Page Down</code>, <code class="keycap">End</code> or <code class="keycap">↘</code>
/// <code class="keycap">End</code> or <code class="keycap">↘</code>
End,
/// <code class="keycap">Help</code>. Not present on standard PC keyboards.
Help,
Expand Down
1 change: 1 addition & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// AUTO GENERATED CODE - DO NOT EDIT
#![cfg_attr(rustfmt, rustfmt_skip)]

use std::fmt::{self, Display};
use std::str::FromStr;
Expand Down
81 changes: 57 additions & 24 deletions src/webdriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,41 @@ fn code(raw_key: char) -> Code {
}

fn is_shifted_character(raw_key: char) -> bool {
matches!(raw_key,
'~' | '|' | '{' | '}' | '<' | ')' | '!' | '@' | '#' | '$' | '%' | '^' | '&' | '*' | '('
| '+' | '>' | '_' | '\"' | ':' | '?' | '\u{E00D}' | '\u{E05C}' | '\u{E056}'
| '\u{E05B}' | '\u{E055}' | '\u{E058}' | '\u{E05A}' | '\u{E057}' | '\u{E059}'
| '\u{E054}' | '\u{E05D}' | 'A'..='Z'
)
matches!(
raw_key,
'~' | '|'
| '{'
| '}'
| '<'
| ')'
| '!'
| '@'
| '#'
| '$'
| '%'
| '^'
| '&'
| '*'
| '('
| '+'
| '>'
| '_'
| '\"'
| ':'
| '?'
| '\u{E00D}'
| '\u{E05C}'
| '\u{E056}'
| '\u{E05B}'
| '\u{E055}'
| '\u{E058}'
| '\u{E05A}'
| '\u{E057}'
| '\u{E059}'
| '\u{E054}'
| '\u{E05D}'
| 'A'..='Z'
)
}

fn key_location(raw_key: char) -> Location {
Expand Down Expand Up @@ -400,22 +429,23 @@ pub fn send_keys(text: &str) -> Vec<Event> {
return false;
}
// values from <https://www.w3.org/TR/uievents-key/#keys-modifier>
matches!(normalised_key_value(first_char(text)),
matches!(
normalised_key_value(first_char(text)),
Key::Alt
| Key::AltGraph
| Key::CapsLock
| Key::Control
| Key::Fn
| Key::FnLock
| Key::Meta
| Key::NumLock
| Key::ScrollLock
| Key::Shift
| Key::Symbol
| Key::SymbolLock
| Key::Hyper
| Key::Super
)
| Key::AltGraph
| Key::CapsLock
| Key::Control
| Key::Fn
| Key::FnLock
| Key::Meta
| Key::NumLock
| Key::ScrollLock
| Key::Shift
| Key::Symbol
| Key::SymbolLock
| Key::Hyper
| Key::Super
)
}

/// Spec: <https://w3c.github.io/webdriver/#dfn-typeable>
Expand Down Expand Up @@ -447,19 +477,22 @@ pub fn send_keys(text: &str) -> Vec<Event> {
CompositionEvent {
state: CompositionState::Start,
data: String::new(),
}.into(),
}
.into(),
);
result.push(
CompositionEvent {
state: CompositionState::Update,
data: s.to_owned(),
}.into(),
}
.into(),
);
result.push(
CompositionEvent {
state: CompositionState::End,
data: s.to_owned(),
}.into(),
}
.into(),
);
}
}
Expand Down

0 comments on commit 7be7932

Please sign in to comment.