(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 "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")) (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")