Skip to content

Commit

Permalink
string-split-lens: add tests where inputs would violate the lens laws
Browse files Browse the repository at this point in the history
fixes #261
  • Loading branch information
AlexKnauth committed Sep 15, 2016
1 parent 6af441c commit 11ecc2f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lens-data/lens/private/string/string-split.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

(module+ test
(define ws-lens (string-split-lens #px"\\s+"))
(check-equal? (lens-view ws-lens "a b c") '("a" "b" "c"))
(check-equal? (lens-set ws-lens "a b c" '("d" "e" "f")) "d e f")
(check-equal? (lens-view ws-lens " foo bar baz \r\n\t")
'("" "foo" "bar" "baz" ""))
(check-equal? (lens-set ws-lens " foo bar baz \r\n\t" '("a" "b" "c" "d" "e"))
Expand All @@ -43,14 +45,28 @@
'("a" "b" "c" "d" "e"))
(check-equal? (lens-set ws-lens "a b c d \r\n\te" '("" "foo" "bar" "baz" ""))
" foo bar baz \r\n\t")
;; this input would violate the lens laws
(check-exn (regexp (regexp-quote "expected a string not matching #px\"\\\\s+\", given: \"e f\""))
(λ ()
(lens-set ws-lens "a b c" '("d" "e f" "g"))))

(define newline-lens (string-split-lens "\n"))
(check-equal? (lens-view newline-lens "a,b\nc,d\ne,f,g")
'("a,b" "c,d" "e,f,g"))
(check-equal? (lens-set newline-lens "a,b\nc,d\ne,f,g" '("1" "2" "3"))
"1\n2\n3")
;; this input would violate the lens laws
(check-exn (regexp (regexp-quote "expected a string not matching \"\\n\", given: \"2\\n2.5\""))
(λ ()
(lens-set newline-lens "a,b\nc,d\ne,f,g" '("1" "2\n2.5" "3"))))

(define comma-lens (string-split-lens #\,))
(check-equal? (lens-view comma-lens "a,b,c")
'("a" "b" "c"))
(check-equal? (lens-set comma-lens "a,b,c" '("1" "2" "3"))
"1,2,3")
;; this input would violate the lens laws
(check-exn (regexp (regexp-quote "expected a string not matching #\\,, given: \"2,2.5\""))
(λ ()
(lens-set comma-lens "a,b,c" '("1" "2,2.5" "3"))))
)

0 comments on commit 11ecc2f

Please sign in to comment.