From 228613899d6d0562c1cd639e69c796fa65c2636d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 11 Mar 2021 21:05:02 +0800 Subject: stash --- test/basic/init.lua | 89 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 16 deletions(-) (limited to 'test/basic') diff --git a/test/basic/init.lua b/test/basic/init.lua index f809a2f3..5e55c724 100644 --- a/test/basic/init.lua +++ b/test/basic/init.lua @@ -1,15 +1,31 @@ local files = require 'files' +local tm = require 'text-merger' -local text = [[ +local function TEST(source) + return function (expect) + return function (changes) + files.removeAll() + files.setText('', source) + local text = tm('', changes) + assert(text == expect) + end + end +end + +TEST [[ + + +function Test(self) + +end +]][[ function Test(self) end -]] -files.setText('', text) -local changes = { +asser]]{ [1] = { range = { ["end"] = { @@ -97,21 +113,62 @@ local changes = { }, } -for _, change in ipairs(changes) do - if change.range then - local start, finish = files.unrange('', change.range) - text = text:sub(1, start - 1) .. change.text .. text:sub(finish) - else - text = change.text - end - files.setRawText('', text) -end +TEST [[ +local mt = {} -assert(text == [[ +function mt['xxx']() + + +end +]] [[ +local mt = {} -function Test(self) +function mt['xxx']() + +end +]] { + [1] = { + range = { + ["end"] = { + character = 4, + line = 5, + }, + start = { + character = 4, + line = 3, + }, + }, + rangeLength = 8, + text = "", + }, +} +TEST [[ +local mt = {} + +function mt['xxx']() + end +]] [[ +local mt = {} -asser]]) +function mt['xxx']() + p +end +]] { + [1] = { + range = { + ["end"] = { + character = 4, + line = 3, + }, + start = { + character = 4, + line = 3, + }, + }, + rangeLength = 0, + text = "p", + }, +} -- cgit v1.2.3