(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) (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 "insert-newlines") (parameterize ((add-buffer-length 10)) (define table (make-piece-table "HOLA\nADIOS")) (piece-table-insert! table 4 "\nHABLAMOS" 'normal) (test-equal "HOLA\nHABLAMOS\nADIOS" (piece-table->string table)) (test-equal (piece-table-line table 1) "HABLAMOS")) ;; TODO: test line iteration functions (test-end "insert-newlines") (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")