Skip to content

Commit

Permalink
SaiderWrapper removed *_with_* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
daidoji committed Jan 8, 2024
1 parent 05dc093 commit d3ab3d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 44 deletions.
55 changes: 11 additions & 44 deletions wasm/src/primitives/saider.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
use std::ops::Deref;

use crate::{error::*, ValueWrapper, Wrap};
use cesride_core::{data::Value, Matter, Saider};
use js_sys::Array;
use wasm_bindgen::prelude::*;

use crate::{
error::*,
ValueWrapper,
Wrap
};
use cesride_core::{
data::Value,
Matter,
Saider
};

#[wasm_bindgen(js_name = Saider)]
#[derive(Clone)]
pub struct SaiderWrapper(pub(crate) Saider);
Expand Down Expand Up @@ -111,48 +120,6 @@ impl SaiderWrapper {
Ok(ret)
}

pub fn new_with_sad(
sad: ValueWrapper,
label: Option<String>,
kind: Option<String>,
ignore: Option<Array>,
code: Option<String>,
) -> Result<SaiderWrapper> {
let ignore = ignore
.map(|a| a.iter().map(|v| v.as_string().unwrap_or_default()).collect::<Vec<String>>());
let ignore = ignore.as_deref().map(|a| a.iter().map(String::as_str).collect::<Vec<&str>>());
let ignore = ignore.as_deref();
let saider = Saider::new_with_sad(
&Value::from(sad),
label.as_deref(),
kind.as_deref(),
ignore,
code.as_deref(),
)
.as_js()?;
Ok(SaiderWrapper(saider))
}

pub fn new_with_raw(raw: &[u8], code: Option<String>) -> Result<SaiderWrapper> {
let saider = Saider::new_with_raw(raw, code.as_deref()).as_js()?;
Ok(SaiderWrapper(saider))
}

pub fn new_with_qb64b(qb64b: &[u8]) -> Result<SaiderWrapper> {
let saider = Saider::new_with_qb64b(qb64b).as_js()?;
Ok(SaiderWrapper(saider))
}

pub fn new_with_qb64(qb64: &str) -> Result<SaiderWrapper> {
let saider = Saider::new_with_qb64(qb64).as_js()?;
Ok(SaiderWrapper(saider))
}

pub fn new_with_qb2(qb2: &[u8]) -> Result<SaiderWrapper> {
let saider = Saider::new_with_qb2(qb2).as_js()?;
Ok(SaiderWrapper(saider))
}

pub fn code(&self) -> String {
self.0.code()
}
Expand Down
15 changes: 15 additions & 0 deletions wasm/tests/test_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use cesride_wasm::BexterWrapper;
use cesride_wasm::CesrideMatterCodex;
use cesride_wasm::CigarWrapper;
use cesride_wasm::DaterWrapper;
use cesride_wasm::SaiderWrapper;
use cesride_wasm::VerferWrapper;
use cesride_wasm::ValueWrapper;

/*
These dater tests are transcriptions from the first two test_dater tests in
Expand Down Expand Up @@ -88,3 +90,16 @@ fn test_verfer_convenience() {
assert_eq!(verf_wrapper.qb64b(), verf_wrapper_2.qb64b());
assert_eq!(verf_wrapper.qb2(), verf_wrapper_2.qb2());
}

#[wasm_bindgen_test]
fn test_serder_convenience() {
// TODO implement
}

#[wasm_bindgen_test]
fn test_saider_convenience() {
let sad = r#"{"d":""}"#;
let wrapper = SaiderWrapper::new(Some(ValueWrapper::new(&sad)),
None, None, None, None, None, None, None, None).unwrap();
assert_eq!(wrapper.code(), wrapper.code());
}

0 comments on commit d3ab3d2

Please sign in to comment.