Expressions: inch and foot marks (#1502) (#1578)

Thanks @DuBearte.
This commit is contained in:
DuBearte authored and GitHub committed 2026-10-16 00:27:40 -04:00
1 parent 3fe929e91c
commit d624e0a171
1 file changed
+21
+21
View File
@@ -281,6 +281,13 @@ fn lex_spans(s: &str) -> Result<Vec<(Tok, usize, usize)>, DocError> {
} else if c == '°' {
out.push((Tok::Id("deg".into()), at(i), at(i + 1)));
i += 1;
} else if c == '"' || c == '″' {
// Inch and foot marks (`1"`, `2'`, #1502), straight or as primes.
out.push((Tok::Id("in".into()), at(i), at(i + 1)));
i += 1;
} else if c == '\'' || c == '′' {
out.push((Tok::Id("ft".into()), at(i), at(i + 1)));
i += 1;
} else if c == '×' || c == '·' {
out.push((Tok::Op('*'), at(i), at(i + 1)));
i += 1;
@@ -856,6 +863,20 @@ mod tests {
}
}
#[test]
fn inch_and_foot_marks() {
// #1502: `1"` in a millimetre design is an inch, `2'` two feet, straight or as primes.
assert_eq!(ev("1\"", Kind::Length).unwrap(), 25.4);
assert_eq!(ev("1″", Kind::Length).unwrap(), 25.4);
assert_eq!(ev("2'", Kind::Length).unwrap(), 609.6);
assert_eq!(ev("2′", Kind::Length).unwrap(), 609.6);
assert_eq!(ev("1/2\"", Kind::Length).unwrap(), 12.7);
assert_eq!(ev("width + 1\"", Kind::Length).unwrap(), 65.4);
assert_eq!(ev("2' + 3\"", Kind::Length).unwrap(), 685.8);
// A mark alone is its unit alone, as `in` is.
assert_eq!(ev("\"", Kind::Length).ok(), ev("in", Kind::Length).ok());
}
#[test]
fn arithmetic_and_units() {
assert_eq!(ev("10", Kind::Length).unwrap(), 10.0);