Skip to content

Commit

Permalink
Merge pull request #957 from googlefonts/fix-948
Browse files Browse the repository at this point in the history
[fea-rs] Fix bug in valuerecord access logic
  • Loading branch information
cmyr authored Sep 11, 2024
2 parents a9b69b2 + f9bee7f commit 195d1ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 15 additions & 0 deletions fea-rs/src/parse/grammar/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ pub(crate) fn expect_name_record(parser: &mut Parser, recovery: TokenSet) {

#[cfg(test)]
mod tests {
use crate::typed::AstNode;

use super::super::debug_parse_output;
use super::*;

Expand Down Expand Up @@ -501,4 +503,17 @@ mod tests {
});
assert!(errstr.contains("expected variation location"), "{errstr}");
}

// https://github.com/googlefonts/fontc/issues/948
#[test]
fn glyphs_value_syntax() {
let fea = "<0 $hi 0 0>";
let (token, _err, _) = debug_parse_output(fea, |parser| {
expect_value_record(parser, TokenSet::EMPTY);
});

let valrecord = crate::typed::ValueRecord::cast(&token).unwrap();
assert!(valrecord.advance().is_none());
assert!(valrecord.placement().is_some());
}
}
7 changes: 1 addition & 6 deletions fea-rs/src/token_tree/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,12 +1086,7 @@ impl ValueRecord {
}

pub(crate) fn placement(&self) -> Option<[Metric; 4]> {
if self
.iter()
.filter(|t| t.kind() == Kind::Number || t.kind() == Kind::VariableMetricNode)
.count()
== 4
{
if self.iter().filter_map(Metric::cast).count() == 4 {
let mut iter = self.iter().filter_map(Metric::cast);
return Some([
iter.next().unwrap(),
Expand Down

0 comments on commit 195d1ca

Please sign in to comment.