#lang scheme/base
(require "test.ss"
"location.ss")
(provide location-tests)
(define (read-syntax/lang name port)
(parameterize ([read-accept-reader #t])
(read-syntax name port)))
(define location-tests
(test-suite
"All tests for location"
(test-case
"syntax->location ok"
(around
(with-output-to-file "test-file.ss"
(lambda () (display "#lang scheme\n'foo\n")))
(let* ([stx (read-syntax/lang (string->path "test-file.ss")
(open-input-file "test-file.ss"))]
[rep (syntax->location stx)])
(check-equal? (location-source rep)
(syntax-source stx))
(check-equal? (location-position rep)
(syntax-position stx))
(check-equal? (location-span rep)
(syntax-span stx)))
(delete-file "test-file.ss")))
(test-case
"Emacs compatible location strings"
(check string=?
(location->string
(syntax->location
(datum->syntax
#f #f
(list "file.ss" 42 38 1240 2))))
"file.ss:42:38")
(check string=?
(location->string
(syntax->location
(datum->syntax
#f #f
(list (string->path "file.ss") 42 38 1240 2))))
"file.ss:42:38")
(check string=?
(location->string
(syntax->location
(datum->syntax
#f #f
(list #f 42 38 1240 2))))
"unknown:42:38")
(check string=?
(location->string
(syntax->location
(datum->syntax
#f #f
(list 'foo.ss 42 38 1240 2))))
"foo.ss:42:38")
(check string=?
(location->string
(syntax->location
(datum->syntax
#f #f
(list "foo.ss" #f #f #f #f))))
"foo.ss:?:?"))
))