зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-07 16:05:50 +03:00
add tests for serde support
Этот коммит содержится в:
9
.github/workflows/ci.yml
поставляемый
9
.github/workflows/ci.yml
поставляемый
@@ -18,12 +18,12 @@ jobs:
|
|||||||
uses: taiki-e/install-action@cargo-llvm-cov
|
uses: taiki-e/install-action@cargo-llvm-cov
|
||||||
- name: Run tests on Linux or macOS
|
- name: Run tests on Linux or macOS
|
||||||
run: |
|
run: |
|
||||||
cargo llvm-cov --color always --lcov --output-path lcov.info --features=search,termwiz,termion,arbitrary
|
cargo llvm-cov --color always --lcov --output-path lcov.info --features=search,termwiz,termion,serde,arbitrary
|
||||||
cargo llvm-cov --color always --no-run
|
cargo llvm-cov --color always --no-run
|
||||||
if: ${{ matrix.os != 'windows-latest' }}
|
if: ${{ matrix.os != 'windows-latest' }}
|
||||||
- name: Run tests on Windows
|
- name: Run tests on Windows
|
||||||
run: |
|
run: |
|
||||||
cargo llvm-cov --color always --lcov --output-path lcov.info --features=search,termwiz,arbitrary
|
cargo llvm-cov --color always --lcov --output-path lcov.info --features=search,termwiz,serde,arbitrary
|
||||||
cargo llvm-cov --color always --no-run
|
cargo llvm-cov --color always --no-run
|
||||||
if: ${{ matrix.os == 'windows-latest' }}
|
if: ${{ matrix.os == 'windows-latest' }}
|
||||||
- run: cargo test --no-default-features --features=tuirs-crossterm,search -- --skip .rs
|
- run: cargo test --no-default-features --features=tuirs-crossterm,search -- --skip .rs
|
||||||
@@ -44,8 +44,7 @@ jobs:
|
|||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: cargo fmt -- --check
|
- run: cargo fmt -- --check
|
||||||
- run: cargo clippy --examples --tests -- -D warnings
|
- run: cargo clippy --examples --tests -- -D warnings
|
||||||
- run: cargo clippy --examples --tests --features search -- -D warnings
|
- run: cargo clippy --examples --tests --features search,serde -- -D warnings
|
||||||
- run: cargo clippy --examples --tests --features serde -- -D warnings
|
|
||||||
- run: cargo clippy --examples --tests --no-default-features --features termion -- -D warnings
|
- run: cargo clippy --examples --tests --no-default-features --features termion -- -D warnings
|
||||||
- run: cargo clippy --examples --tests --no-default-features --features termion,search -- -D warnings
|
- run: cargo clippy --examples --tests --no-default-features --features termion,search -- -D warnings
|
||||||
- run: cargo clippy --examples --tests --no-default-features --features termwiz -- -D warnings
|
- run: cargo clippy --examples --tests --no-default-features --features termwiz -- -D warnings
|
||||||
@@ -58,7 +57,7 @@ jobs:
|
|||||||
- run: cargo clippy --examples --tests --no-default-features --features tuirs-termion,search -- -D warnings
|
- run: cargo clippy --examples --tests --no-default-features --features tuirs-termion,search -- -D warnings
|
||||||
- run: cargo clippy --examples --tests --no-default-features --features tuirs-no-backend -- -D warnings
|
- run: cargo clippy --examples --tests --no-default-features --features tuirs-no-backend -- -D warnings
|
||||||
- run: cargo clippy --examples --tests --no-default-features --features tuirs-no-backend,search -- -D warnings
|
- run: cargo clippy --examples --tests --no-default-features --features tuirs-no-backend,search -- -D warnings
|
||||||
- run: cargo rustdoc --features=search,termwiz,termion -p tui-textarea -- -D warnings
|
- run: cargo rustdoc --features=search,termwiz,termion,serde -p tui-textarea -- -D warnings
|
||||||
cargo-doc:
|
cargo-doc:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -103,7 +103,10 @@ members = ["bench"]
|
|||||||
[profile.bench]
|
[profile.bench]
|
||||||
lto = "thin"
|
lto = "thin"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
serde_json = "1.0.120"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
features = ["search", "crossterm", "termwiz", "termion"]
|
features = ["search", "crossterm", "termwiz", "termion", "serde"]
|
||||||
rustdoc-args = ["--cfg", "docsrs"]
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|||||||
47
tests/serde.rs
Обычный файл
47
tests/serde.rs
Обычный файл
@@ -0,0 +1,47 @@
|
|||||||
|
#![cfg(feature = "serde")]
|
||||||
|
|
||||||
|
use tui_textarea::{CursorMove, Input, Key, Scrolling};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serde_key() {
|
||||||
|
let k = Key::Char('a');
|
||||||
|
let s = serde_json::to_string(&k).unwrap();
|
||||||
|
assert_eq!(s, r#"{"Char":"a"}"#);
|
||||||
|
let d: Key = serde_json::from_str(&s).unwrap();
|
||||||
|
assert_eq!(d, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serde_input() {
|
||||||
|
let i = Input {
|
||||||
|
key: Key::Char('a'),
|
||||||
|
ctrl: true,
|
||||||
|
alt: false,
|
||||||
|
shift: true,
|
||||||
|
};
|
||||||
|
let s = serde_json::to_string(&i).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
s,
|
||||||
|
r#"{"key":{"Char":"a"},"ctrl":true,"alt":false,"shift":true}"#,
|
||||||
|
);
|
||||||
|
let d: Input = serde_json::from_str(&s).unwrap();
|
||||||
|
assert_eq!(d, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serde_scrolling() {
|
||||||
|
let scroll = Scrolling::Delta { rows: 1, cols: 2 };
|
||||||
|
let s = serde_json::to_string(&scroll).unwrap();
|
||||||
|
assert_eq!(s, r#"{"Delta":{"rows":1,"cols":2}}"#);
|
||||||
|
let d: Scrolling = serde_json::from_str(&s).unwrap();
|
||||||
|
assert_eq!(d, scroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serde_cursor_move() {
|
||||||
|
let c = CursorMove::Forward;
|
||||||
|
let s = serde_json::to_string(&c).unwrap();
|
||||||
|
assert_eq!(s, r#""Forward""#);
|
||||||
|
let d: CursorMove = serde_json::from_str(&s).unwrap();
|
||||||
|
assert_eq!(d, c);
|
||||||
|
}
|
||||||
Ссылка в новой задаче
Block a user