Commit 584c7d66 authored by Aleksandar Bakic's avatar Aleksandar Bakic

Changes to (un)tabify-*region methods, and corresponding tests.

Initial tests for indent-line.
parent 68b8e728
......@@ -768,6 +768,110 @@ climacs ")
(offset m))))
"Cli Ma Cs climacs" 9)
(deftest binseq-buffer-tabify-buffer-region.test-1
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::tabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest binseq-buffer-tabify-buffer-region.test-2
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::tabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest binseq-buffer-tabify-region.test-1
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 3))
(m2 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 7)))
(tabify-region m2 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest binseq-buffer-tabify-region.test-2
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 3)))
(tabify-region 7 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest binseq-buffer-tabify-region.test-3
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 7)))
(tabify-region 3 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest binseq-buffer-untabify-buffer-region.test-1
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::untabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest binseq-buffer-untabify-buffer-region.test-2
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::untabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest binseq-buffer-untabify-region.test-1
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 3))
(m2 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 5)))
(untabify-region m2 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest binseq-buffer-untabify-region.test-2
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 3)))
(untabify-region 5 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest binseq-buffer-untabify-region.test-3
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 5)))
(untabify-region 3 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest binseq-buffer-indent-line.test-1
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 4 nil)
(buffer-sequence buffer 0 (size buffer))))
" climacs ")
(deftest binseq-buffer-indent-line.test-2
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 5 4)
(buffer-sequence buffer 0 (size buffer))))
" climacs ")
;;; obinseq tests
(deftest obinseq-buffer-previous-line.test-1
......@@ -1514,4 +1618,108 @@ climacs ")
(values
(buffer-sequence buffer 0 (size buffer))
(offset m))))
"Cli Ma Cs" 9)
\ No newline at end of file
"Cli Ma Cs" 9)
(deftest obinseq-buffer-tabify-buffer-region.test-1
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::tabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest obinseq-buffer-tabify-buffer-region.test-2
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::tabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest obinseq-buffer-tabify-region.test-1
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 3))
(m2 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 7)))
(tabify-region m2 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest obinseq-buffer-tabify-region.test-2
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 3)))
(tabify-region 7 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest obinseq-buffer-tabify-region.test-3
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 7)))
(tabify-region 3 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest obinseq-buffer-untabify-buffer-region.test-1
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::untabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest obinseq-buffer-untabify-buffer-region.test-2
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::untabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest obinseq-buffer-untabify-region.test-1
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 3))
(m2 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 5)))
(untabify-region m2 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest obinseq-buffer-untabify-region.test-2
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 3)))
(untabify-region 5 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest obinseq-buffer-untabify-region.test-3
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 5)))
(untabify-region 3 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest obinseq-buffer-indent-line.test-1
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 4 nil)
(buffer-sequence buffer 0 (size buffer))))
" climacs ")
(deftest obinseq-buffer-indent-line.test-2
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 5 4)
(buffer-sequence buffer 0 (size buffer))))
" climacs ")
......@@ -248,11 +248,14 @@
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "climacs")
(let ((m (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 3)))
:buffer buffer :offset 3))
(m2 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 5)))
(insert-sequence m "ClimacS")
(and (= (size buffer) 14)
(eq (buffer m) buffer)
(= (offset m) 3)
(= (offset m2) 12)
(buffer-sequence buffer 0 14))))
"cliClimacSmacs")
......@@ -260,11 +263,14 @@
(let ((buffer (make-instance 'binseq-buffer)))
(insert-buffer-sequence buffer 0 "climacs")
(let ((m (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 3)))
:buffer buffer :offset 3))
(m2 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 5)))
(insert-sequence m "ClimacS")
(and (= (size buffer) 14)
(eq (buffer m) buffer)
(= (offset m) 10)
(= (offset m2) 12)
(buffer-sequence buffer 0 14))))
"cliClimacSmacs")
......@@ -1062,11 +1068,14 @@ climacs")
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "climacs")
(let ((m (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 3)))
:buffer buffer :offset 3))
(m2 (make-instance 'persistent-left-sticky-mark
:buffer buffer :offset 5)))
(insert-sequence m "ClimacS")
(and (= (size buffer) 14)
(eq (buffer m) buffer)
(= (offset m) 3)
(= (offset m2) 12)
(buffer-sequence buffer 0 14))))
"cliClimacSmacs")
......@@ -1074,11 +1083,14 @@ climacs")
(let ((buffer (make-instance 'obinseq-buffer)))
(insert-buffer-sequence buffer 0 "climacs")
(let ((m (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 3)))
:buffer buffer :offset 3))
(m2 (make-instance 'persistent-right-sticky-mark
:buffer buffer :offset 5)))
(insert-sequence m "ClimacS")
(and (= (size buffer) 14)
(eq (buffer m) buffer)
(= (offset m) 10)
(= (offset m2) 12)
(buffer-sequence buffer 0 14))))
"cliClimacSmacs")
......
......@@ -145,15 +145,15 @@ PERSISTENT-BUFFER."))
(setf high-mark (make-instance 'persistent-right-sticky-mark
:buffer buffer))))
(defmethod clone-mark ((mark persistent-left-sticky-mark) &optional type)
(unless type
(setf type 'persistent-left-sticky-mark))
(make-instance type :buffer (buffer mark) :offset (offset mark)))
(defmethod clone-mark ((mark persistent-right-sticky-mark) &optional type)
(unless type
(setf type 'persistent-right-sticky-mark))
(make-instance type :buffer (buffer mark) :offset (offset mark)))
;; (defmethod clone-mark ((mark persistent-left-sticky-mark) &optional type)
;; (unless type
;; (setf type 'persistent-left-sticky-mark))
;; (make-instance type :buffer (buffer mark) :offset (offset mark)))
;; (defmethod clone-mark ((mark persistent-right-sticky-mark) &optional type)
;; (unless type
;; (setf type 'persistent-right-sticky-mark))
;; (make-instance type :buffer (buffer mark) :offset (offset mark)))
(defmethod size ((buffer binseq-buffer))
(binseq-length (slot-value buffer 'contents)))
......
......@@ -770,3 +770,107 @@ climacs ")
(buffer-sequence buffer 0 (size buffer))
(offset m))))
"Cli Ma Cs climacs" 9)
(deftest standard-buffer-tabify-buffer-region.test-1
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::tabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest standard-buffer-tabify-buffer-region.test-2
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::tabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest standard-buffer-tabify-region.test-1
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'standard-left-sticky-mark
:buffer buffer :offset 3))
(m2 (make-instance 'standard-right-sticky-mark
:buffer buffer :offset 7)))
(tabify-region m2 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest standard-buffer-tabify-region.test-2
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'standard-right-sticky-mark
:buffer buffer :offset 3)))
(tabify-region 7 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest standard-buffer-tabify-region.test-3
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'standard-left-sticky-mark
:buffer buffer :offset 7)))
(tabify-region 3 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest standard-buffer-untabify-buffer-region.test-1
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::untabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest standard-buffer-untabify-buffer-region.test-2
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "c l im acs")
(climacs-base::untabify-buffer-region buffer 0 (size buffer) 8)
(buffer-sequence buffer 0 (size buffer)))
"c l im acs")
(deftest standard-buffer-untabify-region.test-1
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'standard-left-sticky-mark
:buffer buffer :offset 3))
(m2 (make-instance 'standard-right-sticky-mark
:buffer buffer :offset 5)))
(untabify-region m2 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest standard-buffer-untabify-region.test-2
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'standard-right-sticky-mark
:buffer buffer :offset 3)))
(untabify-region 5 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest standard-buffer-untabify-region.test-3
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "clim acs")
(let ((m1 (make-instance 'standard-left-sticky-mark
:buffer buffer :offset 5)))
(untabify-region 3 m1 4)
(buffer-sequence buffer 0 (size buffer))))
"clim acs")
(deftest standard-buffer-indent-line.test-1
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'standard-left-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 4 nil)
(buffer-sequence buffer 0 (size buffer))))
" climacs ")
(deftest standard-buffer-indent-line.test-2
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 " climacs ")
(let ((m (make-instance 'standard-right-sticky-mark
:buffer buffer :offset 0)))
(indent-line m 5 4)
(buffer-sequence buffer 0 (size buffer))))
" climacs ")
......@@ -382,14 +382,23 @@ in the region delimited by mark1 and mark2."))
(defmethod tabify-region ((mark1 mark) (mark2 mark) tab-width)
(assert (eq (buffer mark1) (buffer mark2)))
(tabify-buffer-region (buffer mark1) (offset mark1) (offset mark2)
tab-width))
(let ((offset1 (offset mark1))
(offset2 (offset mark2)))
(when (> offset1 offset2)
(rotatef offset1 offset2))
(tabify-buffer-region (buffer mark1) offset1 offset2 tab-width)))
(defmethod tabify-region ((offset integer) (mark mark) tab-width)
(tabify-buffer-region (buffer mark) offset (offset mark) tab-width))
(defmethod tabify-region ((offset1 integer) (mark2 mark) tab-width)
(let ((offset2 (offset mark2)))
(when (> offset1 offset2)
(rotatef offset1 offset2))
(tabify-buffer-region (buffer mark2) offset1 offset2 tab-width)))
(defmethod tabify-region ((mark mark) (offset integer) tab-width)
(tabify-buffer-region (buffer mark) (offset mark) offset tab-width))
(defmethod tabify-region ((mark1 mark) (offset2 integer) tab-width)
(let ((offset1 (offset mark1)))
(when (> offset1 offset2)
(rotatef offset1 offset2))
(tabify-buffer-region (buffer mark1) offset1 offset2 tab-width)))
(defun untabify-buffer-region (buffer offset1 offset2 tab-width)
(loop for offset = offset1 then (1+ offset)
......@@ -411,14 +420,23 @@ delimited by mark1 and mark2."))
(defmethod untabify-region ((mark1 mark) (mark2 mark) tab-width)
(assert (eq (buffer mark1) (buffer mark2)))
(untabify-buffer-region (buffer mark1) (offset mark1) (offset mark2)
tab-width))
(let ((offset1 (offset mark1))
(offset2 (offset mark2)))
(when (> offset1 offset2)
(rotatef offset1 offset2))
(untabify-buffer-region (buffer mark1) offset1 offset2 tab-width)))
(defmethod untabify-region ((offset integer) (mark mark) tab-width)
(untabify-buffer-region (buffer mark) offset (offset mark) tab-width))
(defmethod untabify-region ((offset1 integer) (mark2 mark) tab-width)
(let ((offset2 (offset mark2)))
(when (> offset1 offset2)
(rotatef offset1 offset2))
(untabify-buffer-region (buffer mark2) offset1 offset2 tab-width)))
(defmethod untabify-region ((mark mark) (offset integer) tab-width)
(untabify-buffer-region (buffer mark) (offset mark) offset tab-width))
(defmethod untabify-region ((mark1 mark) (offset2 integer) tab-width)
(let ((offset1 (offset mark1)))
(when (> offset1 offset2)
(rotatef offset1 offset2))
(untabify-buffer-region (buffer mark1) offset1 offset2 tab-width)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
......
......@@ -234,11 +234,14 @@
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "climacs")
(let ((m (make-instance 'standard-left-sticky-mark
:buffer buffer :offset 3)))
:buffer buffer :offset 3))
(m2 (make-instance 'standard-left-sticky-mark
:buffer buffer :offset 5)))
(insert-sequence m "ClimacS")
(and (= (size buffer) 14)
(eq (buffer m) buffer)
(= (offset m) 3)
(= (offset m2) 12)
(buffer-sequence buffer 0 14))))
"cliClimacSmacs")
......@@ -246,11 +249,14 @@
(let ((buffer (make-instance 'standard-buffer)))
(insert-buffer-sequence buffer 0 "climacs")
(let ((m (make-instance 'standard-right-sticky-mark
:buffer buffer :offset 3)))
:buffer buffer :offset 3))
(m2 (make-instance 'standard-right-sticky-mark
:buffer buffer :offset 5)))
(insert-sequence m "ClimacS")
(and (= (size buffer) 14)
(eq (buffer m) buffer)
(= (offset m) 10)
(= (offset m2) 12)
(buffer-sequence buffer 0 14))))
"cliClimacSmacs")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment