Skip to content

Commit

Permalink
patch: update dependencies (#25)
Browse files Browse the repository at this point in the history
- update afrim dependencies
- update other dependencies
  • Loading branch information
pythonbrad authored May 4, 2024
1 parent b512a84 commit 04bebc2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 34 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ strsim = ["afrim-translator/strsim"]
rhai = ["afrim-translator/rhai-wasm"]

[dependencies]
wasm-bindgen = "0.2.88"
afrim-preprocessor = { version = "0.6.0", default-features = false, features = ["serde"], git = "https://github.com/pythonbrad/afrim", rev = "5192a5f" }
serde-wasm-bindgen = "0.6.1"
afrim-translator = { version = "0.1.4", default-features = false, features = ["serde"], git = "https://github.com/pythonbrad/afrim", rev = "5192a5f" }
indexmap = { version = "2.1.0", features = ["serde"] }
toml = "0.8.10"
wasm-bindgen = "0.2.92"
afrim-preprocessor = { version = "0.6.1", default-features = false, features = ["serde"], git = "https://github.com/pythonbrad/afrim", rev = "5f40469" }
serde-wasm-bindgen = "0.6.5"
afrim-translator = { version = "0.2.1", default-features = false, features = ["serde"], git = "https://github.com/pythonbrad/afrim", rev = "5f40469" }
indexmap = { version = "2.2.6", features = ["serde"] }
toml = "0.8.12"

[dev-dependencies]
wasm-bindgen-test = "0.3.42"
Expand Down
18 changes: 16 additions & 2 deletions src/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ impl Translator {
/// "}"
/// );
///
/// translator.translate("hello") == [["hello", "", ["5"], false]];
/// translator.translate("hello") == [
/// {
/// code: "hello",
/// remaining_code: "",
/// texts: ["5"],
/// can_commit: false
/// }
/// ];
/// ```
#[cfg(feature = "rhai")]
pub fn register(&mut self, name: String, source: String) -> Result<(), String> {
Expand Down Expand Up @@ -78,7 +85,14 @@ impl Translator {
/// ```ignore
/// let data = { hi: [ "hello" ] };
/// let translator = new Translator(data, false);
/// translator.translate("hi") == ["hi", "", ["hello"], true];
/// translator.translate("hi") == [
/// {
/// code: "hi",
/// remaining_code: "",
/// texts: ["hello"],
/// can_commit: true
/// }
/// ];
/// ```
pub fn translate(&self, input: &str) -> JsValue {
serde_wasm_bindgen::to_value(&self.engine.translate(input)).unwrap()
Expand Down
54 changes: 28 additions & 26 deletions tests/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn test_process() {
#[wasm_bindgen_test]
fn test_translate() {
use afrim_js::Translator;
use afrim_translator::Predicate;

let mut dictionary = HashMap::new();
dictionary.insert("hello".to_owned(), vec!["hi".to_owned()]);
Expand All @@ -52,36 +53,36 @@ fn test_translate() {

// Translate
let translator = Translator::new(dictionary, false).unwrap();
let translations: Vec<(String, String, Vec<String>, bool)> =
let translations: Vec<Predicate> =
serde_wasm_bindgen::from_value(translator.translate("hello")).unwrap();

#[cfg(not(feature = "strsim"))]
assert_eq!(
translations,
vec![(
"hello".to_owned(),
"".to_owned(),
vec!["hi".to_owned()],
false
)]
vec![Predicate {
code: "hello".to_owned(),
remaining_code: "".to_owned(),
texts: vec!["hi".to_owned()],
can_commit: false
}]
);

#[cfg(feature = "strsim")]
assert_eq!(
translations,
vec![
(
"hello".to_owned(),
"".to_owned(),
vec!["hi".to_owned()],
false
),
(
"hallo".to_owned(),
"".to_owned(),
vec!["hola".to_owned()],
false
)
Predicate {
code: "hello".to_owned(),
remaining_code: "".to_owned(),
texts: vec!["hi".to_owned()],
can_commit: false
},
Predicate {
code: "hallo".to_owned(),
remaining_code: "".to_owned(),
texts: vec!["hola".to_owned()],
can_commit: false
}
]
);
}
Expand All @@ -90,6 +91,7 @@ fn test_translate() {
#[wasm_bindgen_test]
fn test_transaltor() {
use afrim_js::Translator;
use afrim_translator::Predicate;

// Script
let count_script = r#"fn translate(input) { [input, "", input.len().to_string(), false] }"#;
Expand All @@ -100,17 +102,17 @@ fn test_transaltor() {
translator
.register("count".to_owned(), count_script.to_owned())
.unwrap();
let translations: Vec<(String, String, Vec<String>, bool)> =
let translations: Vec<Predicate> =
serde_wasm_bindgen::from_value(translator.translate("hello")).unwrap();

assert_eq!(
translations,
vec![(
"hello".to_owned(),
"".to_owned(),
vec!["5".to_owned()],
false
),]
vec![Predicate {
code: "hello".to_owned(),
remaining_code: "".to_owned(),
texts: vec!["5".to_owned()],
can_commit: false
},]
);

translator.unregister("count");
Expand Down

0 comments on commit 04bebc2

Please sign in to comment.