Fix conversion from Pair to Pairs
@@ -155,7 +155,7 @@ impl<'i, R: RuleType> Pair<'i, R> {
pub fn into_inner(self) -> Pairs<'i, R> {
let pair = self.pair();
- pairs::new(self.queue, self.input, self.start + 1, pair - 1)
+ pairs::new(self.queue, self.input, self.start + 1, pair)
}
/// Converts the `Pair` into a `TokenIterator`.
@@ -254,3 +254,18 @@ impl<'i, R: Hash> Hash for Pair<'i, R> {
self.start.hash(state);
}
}
+
+#[cfg(test)]
+mod tests {
+ use parser::Parser;
+ use macros::tests::*;
+
+ #[test]
+ fn pair_into_inner() {
+ let pair = AbcParser::parse(Rule::a, "abcde").unwrap().next().unwrap(); // the tokens a(b())
+
+ let pairs = pair.into_inner(); // the tokens b()
+
+ assert_eq!(2, pairs.tokens().count());
+ }
+}
