Skip to content

Commit

Permalink
feat: add utf16 support
Browse files Browse the repository at this point in the history
  • Loading branch information
mitfik committed Mar 21, 2024
1 parent 6c0c59c commit ec6a43d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
9 changes: 9 additions & 0 deletions oca-bundle/src/state/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ pub enum Encoding {
Utf8,
#[serde(rename = "iso-8859-1")]
Iso8859_1,
#[serde(rename = "utf-16")]
Utf16,
#[serde(rename = "utf-16be")]
Utf16Be,
#[serde(rename = "utf-16le")]
Utf16Le,
}

impl FromStr for Encoding {
Expand All @@ -21,6 +27,9 @@ impl FromStr for Encoding {
"base64" => Ok(Encoding::Base64),
"utf-8" => Ok(Encoding::Utf8),
"iso-8859-1" => Ok(Encoding::Iso8859_1),
"utf-16" => Ok(Encoding::Utf16),
"utf-16be" => Ok(Encoding::Utf16Be),
"utf-16le" => Ok(Encoding::Utf16Le),
_ => Err(()),
}
}
Expand Down
58 changes: 42 additions & 16 deletions oca-file/src/ocafile/instructions/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ mod tests {

#[test]
fn test_add_overlay_instructions() {
let instructions = vec![("ADD ENTRY_CODE ATTRS radio=[\"o1\",\"o2\", \"o3\"]", true)];
let instructions = vec![
("ADD ENTRY_CODE ATTRS radio=[\"o1\",\"o2\", \"o3\"]", true),
("ADD FORMAT ATTRS name = \"^\\d+$\"", true),
("ADD CHARACTER_ENCODING ATTRS name=\"utf-16le\"", true),
];

let _ = env_logger::builder().is_test(true).try_init();

Expand All @@ -249,22 +253,44 @@ mod tests {

assert_eq!(instruction.kind, CommandType::Add);
match instruction.object_kind {
ObjectKind::Overlay(overlay_type, content) => {
assert_eq!(overlay_type, OverlayType::EntryCode);
let attr_array = NestedValue::Array(vec![
NestedValue::Value("o1".to_string()),
NestedValue::Value("o2".to_string()),
NestedValue::Value("o3".to_string()),
]);
ObjectKind::Overlay(overlay_type, content) => match overlay_type {
OverlayType::EntryCode => {
assert_eq!(overlay_type, OverlayType::EntryCode);
let attr_array = NestedValue::Array(vec![
NestedValue::Value("o1".to_string()),
NestedValue::Value("o2".to_string()),
NestedValue::Value("o3".to_string()),
]);

assert_eq!(
content.attributes.unwrap().get("radio").unwrap(),
&attr_array
);
}
_ => {
assert!(!is_valid, "Instruction is not valid");
}
assert_eq!(
content.attributes.unwrap().get("radio").unwrap(),
&attr_array
);
}
OverlayType::Format => {
assert_eq!(overlay_type, OverlayType::Format);
let attr_array = NestedValue::Value("^\\d+$".to_string());

assert_eq!(
content.attributes.unwrap().get("name").unwrap(),
&attr_array
);
}
OverlayType::CharacterEncoding => {
assert_eq!(overlay_type, OverlayType::CharacterEncoding);
let attr_array = NestedValue::Value("utf-16le".to_string());

assert_eq!(
content.attributes.unwrap().get("name").unwrap(),
&attr_array
);
}
_ => {
assert!(!is_valid, "Instruction is not valid");
}
},
ObjectKind::CaptureBase(_) => todo!(),
ObjectKind::OCABundle(_) => todo!(),
}
}
None => {
Expand Down

0 comments on commit ec6a43d

Please sign in to comment.