Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand $LINENO to a correct value in prompt string #381

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions yash-env/src/variable/quirk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ impl Expansion<'_> {
}

/// Implementation of [`Variable::expand`].
///
/// For the purpose of line number counting, this function allows
/// `location.range.start` to be greater than the character count of the code,
/// in which case the line number is calculated as if the range were the end of
/// the code.
pub fn expand<'a>(var: &'a Variable, mut location: &Location) -> Expansion<'a> {
match &var.quirk {
None => var.value.as_ref().into(),
Expand Down Expand Up @@ -316,6 +321,19 @@ mod tests {
assert_eq!(result, Expansion::Scalar("44".into()));
}

#[test]
fn expand_line_number_out_of_range() {
let var = Variable {
quirk: Some(Quirk::LineNumber),
..Default::default()
};
let code = stub_code();
let range = 13..13;
let loc = Location { code, range };
let result = var.expand(&loc);
assert_eq!(result, Expansion::Scalar("45".into()));
}

#[test]
fn expand_line_number_in_alias() {
fn to_alias(original: Location) -> Location {
Expand Down
Loading