From 2dfb88344d3953f77345cfffeb5c46d0d7fdb11d Mon Sep 17 00:00:00 2001 From: Greg Hendershott Date: Mon, 13 Jan 2025 12:10:58 -0500 Subject: [PATCH] Change example into a test --- racket/commands/requires.rkt | 37 ++++++++++++++++++++++++++++++------ test/example/requires.rkt | 14 ++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 test/example/requires.rkt diff --git a/racket/commands/requires.rkt b/racket/commands/requires.rkt index 826fa805..1403ecf2 100644 --- a/racket/commands/requires.rkt +++ b/racket/commands/requires.rkt @@ -10,6 +10,8 @@ cartesian-product remove-duplicates) racket/match + (only-in racket/path + simple-form-path) syntax/parse/pre (only-in syntax/stx stx-map) @@ -39,6 +41,35 @@ #:adds (adds/racket->racket/base a) #:drops (drops a))) +(module+ test + (define p (path->string + (simple-form-path + (build-path 'up 'up "test" "example" "requires.rkt")))) + (check-equal? + (requires/tidy p) + '((delete 174 17) + (replace + 129 + 44 + "(require net/url\n (combine-in net/url\n racket/format))") + (replace 39 42 "(require net/uri-codec\n net/url)"))) + (check-equal? + (requires/trim p) + '((delete 174 17) + (replace + 129 + 44 + "(require net/url\n (combine-in net/url\n racket/format))") + (replace 39 42 "(require net/uri-codec\n net/url)"))) + (check-equal? + (requires/base p) + '((delete 174 17) + (replace + 129 + 44 + "(require (for-syntax racket/base)\n net/url\n (combine-in net/url\n racket/format)\n racket/list\n racket/match)") + (replace 39 42 "(require net/uri-codec\n net/url)")))) + ;;; analysis by macro-debugger/analysis/check-requires (define (error-thunk) @@ -643,12 +674,6 @@ (cons-param (insert pos (format-require new)) current-file-changes))) -(module+ tidy-file-example - (define path-str "/home/greg/src/racket/examples/module.rkt") - (tidy-file path-str) - (requires/trim path-str) - (requires/base path-str)) - ;;; format (define (format-require x) diff --git a/test/example/requires.rkt b/test/example/requires.rkt new file mode 100644 index 00000000..9b1f6a6c --- /dev/null +++ b/test/example/requires.rkt @@ -0,0 +1,14 @@ +#lang racket + +(module m racket/base + (require net/uri-codec + net/url) + get-pure-port) + +(match 1 [v #f]) +first +rest + +(require (combine-in racket/format net/url)) +(require net/url) +~a