Skip to content

Commit

Permalink
Add test for utf8
Browse files Browse the repository at this point in the history
Signed-off-by: FedericoBruzzone <[email protected]>
  • Loading branch information
FedericoBruzzone committed Dec 11, 2023
1 parent d44ef8c commit 81e10b0
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/test_utf8.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use encdec::prelude::*;

#[test]
fn test_utf8_encode_in_utf8_1() {
let v: Vec<u32> = vec![0x10001];
let enc: Vec<u8> = utf8::encode_in_utf8(&v);
assert_eq!(enc, vec![0xf0, 0x90, 0x80, 0x81]);
}

#[test]
fn test_utf8_decode_from_utf8_1() {
let enc: Vec<u8> = vec![0xf0, 0x90, 0x80, 0x81];
let v: Vec<u32> = utf8::decode_from_utf8(&enc);
assert_eq!(v, vec![0x10001]);
}

#[test]
fn test_utf8_encode_in_utf8_2() {
let v: Vec<u32> = vec![0x10001, 0x10001];
let enc: Vec<u8> = utf8::encode_in_utf8(&v);
assert_eq!(enc, vec![0xf0, 0x90, 0x80, 0x81, 0xf0, 0x90, 0x80, 0x81]);
}

#[test]
fn test_utf8_decode_from_utf8_2() {
let enc: Vec<u8> = vec![0xf0, 0x90, 0x80, 0x81, 0xf0, 0x90, 0x80, 0x81];
let v: Vec<u32> = utf8::decode_from_utf8(&enc);
assert_eq!(v, vec![0x10001, 0x10001]);
}

#[test]
fn test_utf8_encode_in_utf8_3() {
let v: Vec<u32> = vec![0x10001, 0x10001, 0x10001];
let enc: Vec<u8> = utf8::encode_in_utf8(&v);
assert_eq!(
enc,
vec![0xf0, 0x90, 0x80, 0x81, 0xf0, 0x90, 0x80, 0x81, 0xf0, 0x90, 0x80, 0x81]
);
}

#[test]
fn test_utf8_decode_from_utf8_3() {
let enc: Vec<u8> = vec![
0xf0, 0x90, 0x80, 0x81, 0xf0, 0x90, 0x80, 0x81, 0xf0, 0x90, 0x80, 0x81,
];
let v: Vec<u32> = utf8::decode_from_utf8(&enc);
assert_eq!(v, vec![0x10001, 0x10001, 0x10001]);
}

#[test]
fn test_utf8_encode_in_utf8_4() {
let v: Vec<u32> = vec![0x10001, 0x23456];
let enc: Vec<u8> = utf8::encode_in_utf8(&v);
assert_eq!(enc, vec![0xf0, 0x90, 0x80, 0x81, 0xf0, 0xa3, 0x91, 0x96]);
}

#[test]
fn test_utf8_decode_from_utf8_4() {
let enc: Vec<u8> = vec![0xf0, 0x90, 0x80, 0x81, 0xf0, 0xa3, 0x91, 0x96];
let v: Vec<u32> = utf8::decode_from_utf8(&enc);
assert_eq!(v, vec![0x10001, 0x23456]);
}

0 comments on commit 81e10b0

Please sign in to comment.