Skip to content

Commit

Permalink
more parametrize tests to separated file
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 11, 2024
1 parent 51dabe2 commit 257b92f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
42 changes: 0 additions & 42 deletions tests/core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -447,45 +447,3 @@
(test "core: should not evaluate promise of data"
(lambda (t)
(t.is (to.throw ((Promise.resolve 'list) 1 2 3)) true)))

;; parametrize tests taken on https://docs.racket-lang.org/guide/parameterize.html
(test "std: parameterize lexical"
(lambda (t)
(define location (make-parameter "here"))
(t.is (location) "here")
(t.is (parameterize ([location "there"]) (location))
"there")
(t.is (parameterize ([location "in a house"])
(list (location)
(parameterize ([location "with a mouse"])
(location))
(location)))
'("in a house" "with a mouse" "in a house"))))

(test "std: parametrize closures"
(lambda (t)
(define location (make-parameter "here"))

(let ([get (parameterize ([location "with a fox"])
(lambda () (location)))])
(t.is (get) "here"))))

(test "std: parametrize change value"
(lambda (t)
(define location (make-parameter "here"))
(t.is (list (location) (begin (location "there")
(location)))
'("here" "there"))))

(test "std: parametrize change value + lexical"
(lambda (t)
(define location (make-parameter "here"))

(define (try-again! where)
(location where))

(t.is (parameterize ([location "on a train"])
(list (location)
(begin (try-again! "in a boat")
(location))))
'("on a train" "in a boat"))))
41 changes: 41 additions & 0 deletions tests/parametrize.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
;; parametrize tests taken on https://docs.racket-lang.org/guide/parameterize.html
(test "parameterize: lexical"
(lambda (t)
(define location (make-parameter "here"))
(t.is (location) "here")
(t.is (parameterize ([location "there"]) (location))
"there")
(t.is (parameterize ([location "in a house"])
(list (location)
(parameterize ([location "with a mouse"])
(location))
(location)))
'("in a house" "with a mouse" "in a house"))))

(test "parametrize: closures"
(lambda (t)
(define location (make-parameter "here"))

(let ([get (parameterize ([location "with a fox"])
(lambda () (location)))])
(t.is (get) "here"))))

(test "parametrize: change value"
(lambda (t)
(define location (make-parameter "here"))
(t.is (list (location) (begin (location "there")
(location)))
'("here" "there"))))

(test "parametrize: change value + lexical"
(lambda (t)
(define location (make-parameter "here"))

(define (try-again! where)
(location where))

(t.is (parameterize ([location "on a train"])
(list (location)
(begin (try-again! "in a boat")
(location))))
'("on a train" "in a boat"))))

0 comments on commit 257b92f

Please sign in to comment.