plt/location-test.ss
;;;
;;; Time-stamp: <06/03/11 12:16:54 noel>
;;;
;;; Copyright (C) 2005 by Noel Welsh.
;;;

;;; This library is free software; you can redistribute it
;;; and/or modify it under the terms of the GNU Lesser
;;; General Public License as published by the Free Software
;;; Foundation; either version 2.1 of the License, or (at
;;; your option) any later version.

;;; This library is distributed in the hope that it will be
;;; useful, but WITHOUT ANY WARRANTY; without even the
;;; implied warranty of MERCHANTABILITY or FITNESS FOR A
;;; PARTICULAR PURPOSE.  See the GNU Lesser General Public
;;; License for more details.

;;; You should have received a copy of the GNU Lesser
;;; General Public License along with this library; if not,
;;; write to the Free Software Foundation, Inc., 59 Temple
;;; Place, Suite 330, Boston, MA 02111-1307 USA

;;; Author: Noel Welsh <noelwelsh@yahoo.com>
;;
;;
;; Commentary:

(module location-test mzscheme

  (require "test.ss"
           "location.ss")

  (provide location-tests)

  (define location-tests
    (test-suite
     "All tests for location"

     (test-case
      "syntax->location ok"
      (let* ((stx (read-syntax (string->path "#f")
                               (open-input-string "here")))
             (rep (syntax->location stx)))
        (check-equal? (location-source rep)
                       (path->string (syntax-source stx)))
        (check-equal? (location-position rep)
                       (number->string (syntax-position stx)))
        (check-equal? (location-span rep)
                       (number->string (syntax-span stx)))
        (write (compile stx) (open-output-string))))

     (test-case
      "Emacs compatible location strings"
      (check string=?
              (location->string
               (syntax->location
                (datum->syntax-object
                 #f #f
                 (list "file.ss" 42 38 1240 2))))
              "file.ss:42:38")
      (check string=?
              (location->string
               (syntax->location
                (datum->syntax-object
                 #f #f
                 (list (string->path "file.ss") 42 38 1240 2))))
              "file.ss:42:38")
      (check string=?
              (location->string
               (syntax->location
                (datum->syntax-object
                 #f #f
                 (list #f 42 38 1240 2))))
              "unknown:42:38")
      (check string=?
              (location->string
               (syntax->location
                (datum->syntax-object
                 #f #f
                 (list 'foo.ss 42 38 1240 2))))
              "foo.ss:42:38")
      (check string=?
              (location->string
               (syntax->location
                (datum->syntax-object
                 #f #f
                 (list "foo.ss" #f #f #f #f))))
              "foo.ss:?:?"))
     ))
  )