Skip to content

Commit

Permalink
Change example into a test
Browse files Browse the repository at this point in the history
  • Loading branch information
greghendershott committed Jan 13, 2025
1 parent f6d0e41 commit 2dfb883
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
37 changes: 31 additions & 6 deletions racket/commands/requires.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions test/example/requires.rkt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2dfb883

Please sign in to comment.