findepi commented on code in PR #16856: URL: https://github.com/apache/datafusion/pull/16856#discussion_r2226894105
########## datafusion/functions/src/string/chr.rs: ########## @@ -132,3 +134,79 @@ impl ScalarUDFImpl for ChrFunc { self.doc() } } + +#[cfg(test)] +mod tests { + use super::*; + use arrow::array::{Array, Int64Array, StringArray}; + use datafusion_common::assert_contains; + + #[test] + fn test_chr_normal() { + let input = Arc::new(Int64Array::from(vec![ + Some(65), // A + Some(66), // B + Some(67), // C + Some(128640), // 🚀 + Some(8364), // € + Some(945), // α + None, // NULL + Some(32), // space + Some(10), // newline + Some(9), // tab + ])); + let result = chr(&[input]).unwrap(); + let string_array = result.as_any().downcast_ref::<StringArray>().unwrap(); + let expected = ["A", "B", "C", "🚀", "€", "α", "", " ", "\n", "\t"]; + + assert_eq!(string_array.len(), 10); + for (i, e) in expected.iter().enumerate() { + assert_eq!(string_array.value(i), *e); + } + } + + #[test] + fn test_chr_error() { + // chr(0) returns an error + let input = Arc::new(Int64Array::from(vec![0])); + let result = chr(&[input]); + assert!(result.is_err()); + assert_contains!( + result.err().unwrap().to_string(), + "null character not permitted" + ); + + // invalid Unicode code points (too large) Review Comment: surrogate codepoints are these: > The first (high) surrogate is a 16-bit code value in the range U+D800 to U+DBFF. The second (low) surrogate is a 16-bit code value in the range U+DC00 to U+DFFF. (https://learn.microsoft.com/en-us/globalization/encoding/unicode-standard#:~:text=The%20first%20(high)%20surrogate%20is,%2BDC00%20to%20U%2BDFFF.) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org