mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
even string-cursor->index/index->cursor are polymorphic
This commit is contained in:
parent
89a5b97e3c
commit
e3fddebb26
2 changed files with 22 additions and 3 deletions
|
@ -42,6 +42,8 @@
|
|||
(import (scheme base)
|
||||
(scheme char) (scheme write)
|
||||
(rename (chibi string)
|
||||
(string-index->cursor %string-index->cursor)
|
||||
(string-cursor->index %string-cursor->index)
|
||||
(string-cursor-next %string-cursor-next)
|
||||
(string-cursor-prev %string-cursor-prev)
|
||||
(string-fold %string-fold)
|
||||
|
@ -58,5 +60,13 @@
|
|||
(define (string-cursor-prev str cursor)
|
||||
(if (string-cursor? cursor)
|
||||
(%string-cursor-prev str cursor)
|
||||
(- cursor 1))))
|
||||
(- cursor 1)))
|
||||
(define (string-index->cursor str i)
|
||||
(if (string-cursor? i)
|
||||
i
|
||||
(%string-index->cursor str i)))
|
||||
(define (string-cursor->index str cursor)
|
||||
(if (string-cursor? cursor)
|
||||
(%string-cursor->index str cursor)
|
||||
cursor)))
|
||||
(include "130.scm"))
|
||||
|
|
|
@ -160,9 +160,9 @@
|
|||
(test-assert "string-contains"
|
||||
(string-contains s "mer" 1 8))
|
||||
(test-not "string-contains"
|
||||
(string-contains s "mer" 4 8))
|
||||
(string-contains s "mer" 4 8))
|
||||
(test-not "string-contains"
|
||||
(string-contains s "mer" 1 5)))
|
||||
(string-contains s "mer" 1 5)))
|
||||
(let ((s "eek -- it's a geek."))
|
||||
(test 15 (string-cursor->index s (string-contains-right s "ee")))
|
||||
(test 15 (string-cursor->index s (string-contains-right s "ee" 12 18)))
|
||||
|
@ -385,4 +385,13 @@
|
|||
(test "string-contains" 0
|
||||
(string-cursor->index "ab" (string-contains "ab" "ab")))
|
||||
|
||||
;; even string-cursor->index/index->cursor are polymorphic :(
|
||||
(let* ((s "abc")
|
||||
(i 1)
|
||||
(sc (string-index->cursor s i)))
|
||||
(test i (string-cursor->index s sc))
|
||||
(test i (string-cursor->index s i))
|
||||
(test sc (string-index->cursor s sc))
|
||||
(test sc (string-index->cursor s i)))
|
||||
|
||||
(test-end))))
|
||||
|
|
Loading…
Add table
Reference in a new issue