From f9eb20cfe903ff7421a7956fd06c94e25d334d53 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 14 Sep 2020 16:01:08 +0800 Subject: [PATCH] [feat] update --- Cargo.toml | 3 ++- __test__/index.spec.js | 35 +++++++++++++++++++++++------------ package.json | 2 +- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 816e6ab..27a816e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "node-rs-diff" +name = "rsdiff" version = "0.1.0" authors = ["Jay "] edition = "2018" @@ -7,6 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] +name = "rsdiff" crate-type = ["cdylib"] [dependencies] diff --git a/__test__/index.spec.js b/__test__/index.spec.js index 3fc875d..3957fb2 100644 --- a/__test__/index.spec.js +++ b/__test__/index.spec.js @@ -1,14 +1,25 @@ -const test = require('ava') +const test = require("ava"); -const { diffChars } = require('../index') +const { diffChars, diffLines } = require("../index"); -test('diff chars', (t) => { - const left = 'asd' - const right = 'asd' - const result = diffChars(left, right) - t.is(result.length, 1) - t.is(result[0].count, 3) - t.is(result[0].value, 'asd') - t.is(result[0].added, false) - t.is(result[0].removed, false) -}) +test("diff chars", (t) => { + const left = "asd"; + const right = "asd"; + const result = diffChars(left, right); + t.is(result.length, 1); + t.is(result[0].count, 3); + t.is(result[0].value, "asd"); + t.is(result[0].added, false); + t.is(result[0].removed, false); +}); + +test("diff lines", (t) => { + const left = "asd\ndsa"; + const right = "asd\nddd\nvvv\n\na"; + const result = diffLines(left, right); + + t.is(result.length, 3); + t.is(result[0].count, 1); + t.is(result[1].count, 1); + t.is(result[2].count, 4); +}); diff --git a/package.json b/package.json index 9accb6d..5893b12 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "node": ">= 8.9" }, "scripts": { - "build": "cargo build --release && napi build --platform --release .", + "build": "cargo build --release && napi build --platform --release", "build:debug": "cargo build && napi build --platform .", "test": "ava", "publish:linux": "cross-env PLATFORM=linux node scripts/publish.js",