use crate::core::analysis::token_attributes::char_term_attribute::CharTermAttribute;
use crate::core::analysis::token_attributes::flags_attribute::FlagsAttribute;
use crate::core::analysis::token_attributes::offset_attribute::OffsetAttribute;
use crate::core::analysis::token_attributes::payload_attribute::PayloadAttribute;
use crate::core::analysis::token_attributes::position_increment_attribute::PositionIncrementAttribute;
use crate::core::analysis::token_attributes::position_length_attribute::PositionLengthAttribute;
use crate::core::analysis::token_attributes::type_attribute::TypeAttribute;
use crate::core::index::BytesRef;
use crate::core::util::attribute_impl::AttributeImpl;
use crate::core::util::error::lucene_error::Result;
use crate::test_framework::core::analysis::token;
#[allow(dead_code)] pub struct TestToken;
#[test]
fn test_ctor() -> Result<()> {
let t = token::with_range(Some("hello"), 0, 0)?;
assert_eq!(0, t.sub.start_offset());
assert_eq!(0, t.sub.end_offset());
assert_eq!(1, t.sub.get_position_increment());
assert_eq!(1, t.sub.get_position_length());
assert_eq!("hello", t.to_string());
assert_eq!("word", t.sub.type_());
assert_eq!(0, t.sub.token.get_flags());
assert!(t.sub.token.get_payload().is_none());
Ok(())
}
#[test]
fn test_clone() -> Result<()> {
let mut t = token::new()?;
t.sub.set_offset(0, 5)?;
let content = ['h', 'e', 'l', 'l', 'o'];
t.copy_buffer(&content, 0, 5)?;
let copy = t.clone();
assert_eq!(t.to_string(), copy.to_string());
let pl = BytesRef::from_bytes(vec![1, 2, 3, 4]);
t.sub.token.set_payload(Some(pl.clone()));
let copy = t.clone();
assert_eq!(&pl, copy.sub.token.get_payload().unwrap(),);
Ok(())
}
#[test]
fn test_copy_to() -> Result<()> {
let mut t = token::new()?;
let mut copy = token::new()?;
t.copy_to(&mut copy)?;
assert_eq!("", t.to_string());
assert_eq!("", copy.to_string());
t = token::new()?;
t.sub.set_offset(0, 5)?;
let content = ['h', 'e', 'l', 'l', 'o'];
t.copy_buffer(&content, 0, 5)?;
copy = token::new()?;
t.copy_to(&mut copy)?;
assert_eq!(t.to_string(), copy.to_string());
let pl = BytesRef::from_bytes(vec![1, 2, 3, 4]);
t.sub.token.set_payload(Some(pl.clone()));
copy = token::new()?;
t.copy_to(&mut copy)?;
assert_eq!(&pl, copy.sub.token.get_payload().unwrap());
Ok(())
}
#[test]
#[ignore = "Java-only: Rust token attributes use static composition instead of runtime AttributeFactory interface lookup"]
fn test_token_attribute_factory() -> Result<()> {
test_not_required_in_rust_lucene!();
}
#[test]
#[ignore = "Java-only: Rust token attributes do not expose Java AttributeReflector class-name reflection"]
fn test_attribute_reflection() -> Result<()> {
test_not_required_in_rust_lucene!();
}