blob: 317286c2e3efdefebcb34e279c03ccc90462d869 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
(import (srfi 64)
(scheme base)
(par piece-table))
;; https://srfi.schemers.org/srfi-64/srfi-64.html
(test-begin "index")
(define table (make-piece-table "HOLA"))
(test-equal #\L (piece-table-index table 2))
(test-end "index")
(test-begin "insert")
(define table (make-piece-table "HOLA"))
(piece-table-insert! table 4 "9" 'normal)
(piece-table-insert! table 5 "0" 'normal)
(test-equal #\9 (piece-table-index table 4))
(test-equal #\0 (piece-table-index table 5))
(test-equal "HOLA90" (piece-table->string table))
(piece-table-insert! table 5 "1" 'normal)
(test-equal "HOLA910" (piece-table->string table))
(test-end "insert")
(test-begin "substring")
(parameterize ((add-buffer-length 10))
(define table (make-piece-table "1234567890"))
(test-equal "1234567890" (piece-table-substring table 0 10))
(test-equal "67890" (piece-table-substring table 5 10))
(piece-table-insert! table 6 "X" 'normal)
(test-equal "6X78" (piece-table-substring table 5 9)))
(test-end "substring")
(test-begin "delete")
(define table (make-piece-table "HOLA SOY EKAITZ"))
(piece-table-delete! table 4 1)
(test-equal "HOLASOY EKAITZ" (piece-table->string table))
(piece-table-delete! table 0 1)
(test-equal "OLASOY EKAITZ" (piece-table->string table))
(piece-table-delete! table 12 1)
(test-equal "OLASOY EKAIT" (piece-table->string table))
(test-end "delete")
|