waynexia commented on code in PR #16856:
URL: https://github.com/apache/datafusion/pull/16856#discussion_r2226369893


##########
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:
   👍 Added two cases for `0x10FFFF` ([the largest code 
point](https://en.wikipedia.org/wiki/UTF-8#Description)) and `0x10FFFF + 1` 
(invalid)



-- 
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

Reply via email to