#![allow(clippy::unwrap_used, clippy::expect_used)]
use chronix_core::types::MAX_STRING_FIELD_LENGTH;
use chronix_encoding::{ColumnDecoder, ColumnEncoder, DecodedColumn, DictionaryEncoder};
#[test]
fn ingest_limit_equals_the_encoder_limit() {
assert_eq!(
MAX_STRING_FIELD_LENGTH,
usize::from(u16::MAX),
"chronix-core accepts strings the encoders cannot store"
);
}
#[test]
fn a_string_at_the_ingest_limit_encodes_and_one_past_it_does_not() {
let at_limit = "x".repeat(MAX_STRING_FIELD_LENGTH);
let block = ColumnEncoder::encode_string(&[at_limit.as_str(), "y"]).unwrap();
match ColumnDecoder::decode(&block).unwrap() {
DecodedColumn::String(back) => assert_eq!(back, vec![at_limit.clone(), "y".to_string()]),
other => panic!("decoded to {other:?}"),
}
assert!(DictionaryEncoder::encode(&[at_limit.as_str()]).is_ok());
let past_limit = "x".repeat(MAX_STRING_FIELD_LENGTH + 1);
assert!(
ColumnEncoder::encode_string(&[past_limit.as_str()]).is_err(),
"a string one byte past the limit must be rejected, not truncated"
);
}