Improve public API & add docs #4
2 changed files with 1 additions and 25 deletions
Remove function
commit
c1aa8fe463
|
|
@ -99,17 +99,6 @@ pub fn is_binary(data: &[u8]) -> bool {
|
||||||
std::str::from_utf8(data).is_err()
|
std::str::from_utf8(data).is_err()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// We don't want to support merging structured data like JSON, YAML, etc.
|
|
||||||
#[wasm_bindgen(js_name = isFileTypeMergable)]
|
|
||||||
#[must_use]
|
|
||||||
pub fn is_file_type_mergable(path_or_file_name: &str) -> bool {
|
|
||||||
set_panic_hook();
|
|
||||||
|
|
||||||
let file_extension = path_or_file_name.split('.').next_back().unwrap_or_default();
|
|
||||||
|
|
||||||
matches!(file_extension.to_lowercase().as_str(), "md" | "txt")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_panic_hook() {
|
fn set_panic_hook() {
|
||||||
// https://github.com/rustwasm/console_error_panic_hook#readme
|
// https://github.com/rustwasm/console_error_panic_hook#readme
|
||||||
#[cfg(feature = "console_error_panic_hook")]
|
#[cfg(feature = "console_error_panic_hook")]
|
||||||
|
|
|
||||||
67
tests/wasm.rs
Normal file
67
tests/wasm.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#![cfg(feature = "wasm")]
|
||||||
|
|
||||||
|
use reconcile::wasm::{
|
||||||
|
lib::{is_binary, merge, merge_text, merge_text_with_cursors},
|
||||||
|
types::{JsCursorPosition, JsTextWithCursors},
|
||||||
|
};
|
||||||
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen_test(unsupported = test)]
|
||||||
|
fn test_merge() {
|
||||||
|
let left = b"hello ";
|
||||||
|
let right = b"world";
|
||||||
|
let result = merge(b"", left, right);
|
||||||
|
assert_eq!(result, b"hello world");
|
||||||
|
|
||||||
|
let left = b"\0binary";
|
||||||
|
let right = b"other";
|
||||||
|
let result = merge(b"", left, right);
|
||||||
|
assert_eq!(result, right);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test(unsupported = test)]
|
||||||
|
fn test_merge_text() {
|
||||||
|
let left = "hello ";
|
||||||
|
let right = "world";
|
||||||
|
let result = merge_text("", left, right);
|
||||||
|
assert_eq!(result, "hello world");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test(unsupported = test)]
|
||||||
|
fn test_merge_text_with_cursors() {
|
||||||
|
let result = merge_text_with_cursors(
|
||||||
|
"hi",
|
||||||
|
JsTextWithCursors::new("hi world".to_owned(), vec![]),
|
||||||
|
JsTextWithCursors::new(
|
||||||
|
"hi".to_owned(),
|
||||||
|
vec![JsCursorPosition::new(0, 1), JsCursorPosition::new(1, 2)],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
result,
|
||||||
|
JsTextWithCursors::new(
|
||||||
|
"hi world".to_owned(),
|
||||||
|
vec![JsCursorPosition::new(0, 1), JsCursorPosition::new(1, 2)]
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test(unsupported = test)]
|
||||||
|
fn merge_binary() {
|
||||||
|
let left = [0, 1, 2];
|
||||||
|
let right = [3, 4, 5];
|
||||||
|
assert_eq!(merge(b"", &left, &right), right);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test(unsupported = test)]
|
||||||
|
fn test_is_binary() {
|
||||||
|
assert!(is_binary(&[0, 159, 146, 150]));
|
||||||
|
assert!(is_binary(&[0, 12]));
|
||||||
|
assert!(!is_binary(b"hello"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test(unsupported = test)]
|
||||||
|
fn test_is_binary_empty() {
|
||||||
|
assert!(!is_binary(b""));
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue