Skip to content

Commit

Permalink
[rust] add ParseResult::frozen_string_literals
Browse files Browse the repository at this point in the history
  • Loading branch information
froydnj committed Sep 21, 2023
1 parent 0066cda commit 0afff99
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rust/yarp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ impl<'pr> ParseResult<'pr> {
self.source
}

/// Returns whether we found a `frozen_string_literal` magic comment with a true value.
#[must_use]
pub fn frozen_string_literals(&self) -> bool {
unsafe {
(*self.parser.as_ptr()).frozen_string_literal
}
}

/// Returns a slice of the source string that was parsed using the given
/// location range.
#[must_use]
Expand Down Expand Up @@ -391,4 +399,18 @@ end
let closing_loc = call.closing_loc();
assert!(closing_loc.is_none());
}

#[test]
fn frozen_strings_test() {
let source = r#"
# frozen_string_literal: true
"foo"
"#;
let result = parse(source.as_ref());
assert!(result.frozen_string_literals());

let source = "3";
let result = parse(source.as_ref());
assert!(!result.frozen_string_literals());
}
}

0 comments on commit 0afff99

Please sign in to comment.