mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-19 11:05:24 +00:00

Some checks are pending
CI / Fuzz the parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz (push) Blocked by required conditions
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
use ruff_python_parser::{parse_module, ParseError};
|
|
use ruff_python_trivia::has_trailing_content;
|
|
use ruff_text_size::Ranged;
|
|
|
|
#[test]
|
|
fn trailing_content() -> Result<(), ParseError> {
|
|
let contents = "x = 1";
|
|
let suite = parse_module(contents)?.into_suite();
|
|
let stmt = suite.first().unwrap();
|
|
assert!(!has_trailing_content(stmt.end(), contents));
|
|
|
|
let contents = "x = 1; y = 2";
|
|
let suite = parse_module(contents)?.into_suite();
|
|
let stmt = suite.first().unwrap();
|
|
assert!(has_trailing_content(stmt.end(), contents));
|
|
|
|
let contents = "x = 1 ";
|
|
let suite = parse_module(contents)?.into_suite();
|
|
let stmt = suite.first().unwrap();
|
|
assert!(!has_trailing_content(stmt.end(), contents));
|
|
|
|
let contents = "x = 1 # Comment";
|
|
let suite = parse_module(contents)?.into_suite();
|
|
let stmt = suite.first().unwrap();
|
|
assert!(!has_trailing_content(stmt.end(), contents));
|
|
|
|
let contents = r"
|
|
x = 1
|
|
y = 2
|
|
"
|
|
.trim();
|
|
let suite = parse_module(contents)?.into_suite();
|
|
let stmt = suite.first().unwrap();
|
|
assert!(!has_trailing_content(stmt.end(), contents));
|
|
|
|
Ok(())
|
|
}
|