Merge pull request #27 from pchampin/fix_bnode_as_str

fix BlankNode::as_str
pull/28/head
Thomas Tanon 5 years ago committed by GitHub
commit 087f6ca12a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      lib/src/model/blank_node.rs

@ -36,7 +36,8 @@ impl BlankNode {
/// Returns the underlying ID of this blank node /// Returns the underlying ID of this blank node
pub fn as_str(&self) -> &str { pub fn as_str(&self) -> &str {
str::from_utf8(&self.str).unwrap() let len = self.str.iter().position(|x| x == &0).unwrap_or(32);
str::from_utf8(&self.str[..len]).unwrap()
} }
/// Returns the internal ID of this blank node /// Returns the internal ID of this blank node
@ -63,3 +64,20 @@ impl<'a> From<&'a BlankNode> for rio::BlankNode<'a> {
rio::BlankNode { id: node.as_str() } rio::BlankNode { id: node.as_str() }
} }
} }
#[cfg(test)]
mod test {
use super::*;
#[test]
fn as_str_partial() {
let b = BlankNode::new_from_unique_id(0x42);
assert_eq!(b.as_str(), "42");
}
#[test]
fn as_str_full() {
let b = BlankNode::new_from_unique_id(0x77776666555544443333222211110000);
assert_eq!(b.as_str(), "77776666555544443333222211110000");
}
}

Loading…
Cancel
Save