Pārlūkot izejas kodu

Fix build and add another test

Eric Zhang 4 gadi atpakaļ
vecāks
revīzija
67cec1ec4b
3 mainītis faili ar 18 papildinājumiem un 2 dzēšanām
  1. 5 0
      rustpad-core/src/lib.rs
  2. 10 0
      rustpad-core/tests/web.rs
  3. 3 2
      src/App.tsx

+ 5 - 0
rustpad-core/src/lib.rs

@@ -21,6 +21,11 @@ pub struct OpSeqPair(OpSeq, OpSeq);
 
 #[wasm_bindgen]
 impl OpSeq {
+    /// Creates a default empty `OpSeq`.
+    pub fn new() -> Self {
+        Self::default()
+    }
+
     /// Creates a store for operatations which does not need to allocate  until
     /// `capacity` operations have been stored inside.
     pub fn with_capacity(capacity: usize) -> Self {

+ 10 - 0
rustpad-core/tests/web.rs

@@ -40,3 +40,13 @@ fn transform_operations() {
     assert_eq!(ab_prime, ba_prime);
     assert_eq!(after_ab_prime, after_ba_prime);
 }
+
+#[wasm_bindgen_test]
+fn invert_operations() {
+    let s = "abc";
+    let mut o = OpSeq::default();
+    o.retain(3);
+    o.insert("def");
+    let p = o.invert(s);
+    assert_eq!(p.apply(&o.apply(s).unwrap()).unwrap(), s);
+}

+ 3 - 2
src/App.tsx

@@ -1,5 +1,5 @@
 import { useEffect, useState } from "react";
-import { duplicate } from "rustpad-core";
+import { set_panic_hook } from "rustpad-core";
 
 function App() {
   const [input, setInput] = useState("");
@@ -7,7 +7,8 @@ function App() {
   const [messages, setMessages] = useState<[number, string][]>([]);
 
   useEffect(() => {
-    console.log(duplicate("Hello"));
+    set_panic_hook();
+
     const uri =
       (window.location.origin.startsWith("https") ? "wss://" : "ws://") +
       window.location.host +