From 257b92fc9c68578ac927aec512163bd56e4dc6ed Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Thu, 11 Jan 2024 23:52:07 +0100 Subject: [PATCH] more parametrize tests to separated file --- tests/core.scm | 42 ------------------------------------------ tests/parametrize.scm | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 42 deletions(-) create mode 100644 tests/parametrize.scm diff --git a/tests/core.scm b/tests/core.scm index c28f8e1e3..e78136c5b 100644 --- a/tests/core.scm +++ b/tests/core.scm @@ -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")))) diff --git a/tests/parametrize.scm b/tests/parametrize.scm new file mode 100644 index 000000000..cec10b58d --- /dev/null +++ b/tests/parametrize.scm @@ -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"))))