Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/sync/editor/string/test/doc.test.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { StringDocument } from "../doc";67describe("create a String document and call methods on it", () => {8let doc: StringDocument;910it("creates the doc", () => {11doc = new StringDocument("cocalc");12expect(`${doc}`).toBe("[object Object]");13});1415it("convert to string", () => {16expect(doc.to_str()).toBe("cocalc");17});1819it("checks equality", () => {20expect(doc.is_equal()).toBe(false);21expect(doc.is_equal(undefined)).toBe(false);22expect(doc.is_equal(doc)).toBe(true);23expect(doc.is_equal(new StringDocument("cocalc"))).toBe(true);24expect(doc.is_equal(new StringDocument("sagemathcloud"))).toBe(false);25});2627it("make and apply a patch", () => {28const patch = doc.make_patch(new StringDocument("CoCalc"));29expect(doc.apply_patch(patch).to_str()).toBe("CoCalc");30});3132it("set the document (thus making a new one, since immutable!)", () => {33const d2 = doc.set("CoCalc");34expect(doc.to_str()).toBe("cocalc");35expect(d2.to_str()).toBe("CoCalc");3637// also test type checking38expect(() => {39doc.set(0);40}).toThrow("must be a string");41});4243it("tests that the db-like API all throws errors", () => {44expect(() => doc.get()).toThrow("don't have meaning");45expect(() => doc.get_one()).toThrow("don't have meaning");46expect(() => doc.delete()).toThrow("doesn't have meaning");47expect(doc.changes(doc)).toBe(undefined);48});4950it("count gives length", () => {51expect(doc.count()).toBe(doc.to_str().length);52});53});545556