blob: 620b50c6d9d05157923a0c90433855ac8d4826dd (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
(import (srfi 64)
(scheme small)
(par %piece-table-all))
;; https://srfi.schemers.org/srfi-64/srfi-64.html
(test-begin "index")
(define table (make-piece-table "HOLA"))
(split-piece! (piece-next (piece-table-sentinel table)) 2) ;;Spice up the test
(test-equal #\H (piece-table-index table 0))
(test-equal #\O (piece-table-index table 1))
(test-equal #\L (piece-table-index table 2))
(test-equal #\A (piece-table-index table 3))
(test-equal #\O (piece-table-index table 1))
(test-end "index")
(test-begin "length")
(define table (make-piece-table "HOLA"))
(test-equal 4 (piece-table-length table))
(test-end "length")
;(test-begin "insert")
; (define table (make-piece-table "HOLA"))
; (piece-table-insert! table 4 "9" 'normal)
; (test-equal #\9 (piece-table-index table 4))
; (piece-table-insert! table 5 "0" 'normal)
; (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")
;
;(test-begin "for-each")
; (define table (make-piece-table "12346890"))
; (piece-table-insert! table 4 "5" 'normal)
; (test-equal "123456890" (piece-table->string table))
; (piece-table-insert! table 6 "7" 'normal)
; (test-equal "1234567890" (piece-table->string table))
; (piece-table-for-each table
; (lambda (c i p)
; (test-equal c (string-ref "1234567890" i)))
; 0
; 10)
;(test-end "for-each")
;
;(test-begin "find")
; (define table (make-piece-table "1234567890"))
; (test-equal 8 (piece-table-find table #\9 0))
;(test-end "find")
|