private/lw-test.ss
#|

     DO NOT TABIFY THIS FILE

|#


;                                           
;                                           
;  ;;;;                                     
;   ;  ;                                ;   
;   ;   ;   ;;;         ;; ;;    ;;;   ;;;;;
;   ;   ;  ;   ;         ;;  ;  ;   ;   ;   
;   ;   ;  ;   ;         ;   ;  ;   ;   ;   
;   ;   ;  ;   ;         ;   ;  ;   ;   ;   
;   ;  ;   ;   ;         ;   ;  ;   ;   ;   ;
;  ;;;;     ;;;         ;;; ;;;  ;;;     ;;;
;                                           
;                                           
;                                           
;                                           
;                                           
;                                           
;                ;;        ;      ;;;       
;    ;            ;              ;          
;   ;;;;;   ;;;   ; ;;   ;;;    ;;;;; ;;; ;;;
;    ;     ;   ;  ;;  ;    ;     ;     ;   ;
;    ;      ;;;;  ;   ;    ;     ;      ;  ;
;    ;     ;   ;  ;   ;    ;     ;      ; ; 
;    ;   ; ;   ;  ;   ;    ;     ;       ;; 
;     ;;;   ;;;;;;;;;;   ;;;;;  ;;;;;    ;  
;                                        ;  
;                                      ;;;; 
;                                           
;                                           
;                                                                
;                                                                
;         ;;        ;                    ;;;    ;     ;;         
;    ;     ;                            ;              ;         
;   ;;;;;  ; ;;   ;;;     ;;;;         ;;;;;  ;;;      ;     ;;; 
;    ;     ;;  ;    ;    ;   ;          ;       ;      ;    ;   ;
;    ;     ;   ;    ;     ;;;           ;       ;      ;    ;;;;;
;    ;     ;   ;    ;        ;          ;       ;      ;    ;    
;    ;   ; ;   ;    ;    ;   ;          ;       ;      ;    ;    
;     ;;; ;;; ;;; ;;;;;  ;;;;          ;;;;;  ;;;;;  ;;;;;   ;;;;
;                                                                
;                                                                
;                                                                
;                                                                


(module lw-test mzscheme
  (require "test-util.ss"
           "loc-wrapper.ss"
           "lw-test-util.ss")
  
  (reset-count)
  
  (test (normalize-lw (to-loc-wrapper ()))
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper ")" 0 0 1 1))
                           0 0 0 2))
  
  (test (normalize-lw (to-loc-wrapper "x"))
        (build-loc-wrapper "“x”" 0 0 0 3))
  
  (test (normalize-lw (to-loc-wrapper "#f"))
        (build-loc-wrapper "“#f”" 0 0 0 4))
  
  (test (normalize-lw (to-loc-wrapper #f))
        (build-loc-wrapper "#f" 0 0 0 2))
  
  (test (normalize-lw (to-loc-wrapper/uq ()))
        (make-loc-wrapper (list (make-loc-wrapper "(" 0 0 0 1 #t #f)
                                (make-loc-wrapper ")" 0 0 1 1 #t #f))
                          0 0 0 2 #t #f))
  
  (test (normalize-lw (to-loc-wrapper (a)))
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper 'a 0 0 1 1)
                                 (build-loc-wrapper ")" 0 0 2 1))
                           0 0 0 3))
  
  (test (normalize-lw (to-loc-wrapper (a
                                       b)))
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper 'a 0 0 1 1)
                                 (build-loc-wrapper 'b 1 0 1 1)
                                 (build-loc-wrapper ")" 1 0 2 1))
                           0 1 0 3))
  
  (test (normalize-lw (to-loc-wrapper (a b)))
        (build-loc-wrapper 
         (list (build-loc-wrapper "(" 0 0 0 1)
               (build-loc-wrapper 'a 0 0 1 1)
               (build-loc-wrapper 'b 0 0 3 1)
               (build-loc-wrapper ")" 0 0 4 1))
         0 0 0 5))
  
  
  (test (normalize-lw (to-loc-wrapper (a
                                       (b c)
                                       d)))
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper 'a 0 0 1 1)
                                 (build-loc-wrapper 
                                  (list (build-loc-wrapper "(" 1 0 1 1)
                                        (build-loc-wrapper 'b 1 0 2 1)
                                        (build-loc-wrapper 'c 1 0 4 1)
                                        (build-loc-wrapper ")" 1 0 5 1))
                                  1 0 1 5)
                                 (build-loc-wrapper 'd 2 0 1 1)
                                 (build-loc-wrapper ")" 2 0 2 1))
                           0 2 0 3))
  
  (test (normalize-lw (to-loc-wrapper (abcdefghijkl
                                       b)))
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper 'abcdefghijkl 0 0 1 12)
                                 (build-loc-wrapper 'b 1 0 1 1)
                                 (build-loc-wrapper ")" 1 0 2 1))
                           0 1 0 3))
  
  (test (normalize-lw (to-loc-wrapper ((a b)
                                       c)))
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper 
                                  (list (build-loc-wrapper "(" 0 0 1 1)
                                        (build-loc-wrapper 'a 0 0 2 1)
                                        (build-loc-wrapper 'b 0 0 4 1)
                                        (build-loc-wrapper ")" 0 0 5 1))
                                  0 0 1 5)
                                 (build-loc-wrapper 'c 1 0 1 1)
                                 (build-loc-wrapper ")" 1 0 2 1))
                           0 1 0 3))
  
  (test (normalize-lw (to-loc-wrapper (aaa bbb
                                           (ccc
                                       ddd)))) ;; <--- the ddd should be lined up under the aaa
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper 'aaa 0 0 1 3)
                                 (build-loc-wrapper 'bbb 0 0 5 3)
                                 (build-loc-wrapper
                                  (list
                                   (build-loc-wrapper "(" 1 0 5 1)
                                   (build-loc-wrapper 'ccc 1 0 6 3)
                                   (build-loc-wrapper 'ddd 2 0 1 3)
                                   (build-loc-wrapper ")" 2 0 4 1))
                                  1 1 1 4)
                                 (build-loc-wrapper ")" 2 0 5 1))
                           0 2 0 6))
  
  (test (normalize-lw (to-loc-wrapper (aaa bbb
                                           (ccc
                                       ddd          ;; <--- the ddd should be lined up under the aaa
                                            eee)))) ;; <--- the eee should be lined up under the ccc
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper 'aaa 0 0 1 3)
                                 (build-loc-wrapper 'bbb 0 0 5 3)
                                 (build-loc-wrapper
                                  (list
                                   (build-loc-wrapper "(" 1 0 5 1)
                                   (build-loc-wrapper 'ccc 1 0 6 3)
                                   (build-loc-wrapper 'ddd 2 0 1 3)
                                   (build-loc-wrapper 'eee 3 0 6 3)
                                   (build-loc-wrapper ")" 3 0 9 1))
                                  1 2 1 9)
                                 (build-loc-wrapper ")" 3 0 10 1))
                           0 3 0 11))
  
  (test (normalize-lw (to-loc-wrapper ([{}])))
        (build-loc-wrapper (list (build-loc-wrapper "(" 0 0 0 1)
                                 (build-loc-wrapper
                                  (list
                                   (build-loc-wrapper "[" 0 0 1 1)
                                   (build-loc-wrapper
                                    (list
                                     (build-loc-wrapper "{" 0 0 2 1)
                                     (build-loc-wrapper "}" 0 0 3 1))
                                    0 0 2 2)
                                   (build-loc-wrapper "]" 0 0 4 1))
                                  0 0 1 4)
                                 (build-loc-wrapper ")" 0 0 5 1))
                           0 0 0 6))
  
  (test (normalize-lw (to-loc-wrapper ,x))
        (make-loc-wrapper
         (list 
          (make-loc-wrapper "" 0 0 0 0 #f #f)
          'spring
          (make-loc-wrapper 'x 0 0 1 1 #t #f))
         0 0 0 2 #f #f))
  
  (test (normalize-lw (to-loc-wrapper ,@x))
        (make-loc-wrapper
         (list 
          (make-loc-wrapper "" 0 0 0 0 #f #f)
          'spring
          (make-loc-wrapper 'x 0 0 2 1 #t #f))
         0 0 0 3 #f #f))
  
  (test (normalize-lw (to-loc-wrapper 'x))
        (make-loc-wrapper
         (list 
          (make-loc-wrapper "'" 0 0 0 1 #f #f)
          'spring
          (make-loc-wrapper 'x 0 0 1 1 #f #f))
         0 0 0 2 #f #f))
  
  (test (normalize-lw (to-loc-wrapper ,(term x)))
        (make-loc-wrapper
         (list 
          (make-loc-wrapper "" 0 0 0 0 #f #f)
          'spring
          (make-loc-wrapper
           (list 
            (make-loc-wrapper "" 0 0 1 0 #t #f) 
            'spring
            (make-loc-wrapper 'x 0 0 7 1 #f #f)
            'spring)
           0 0 1 7 #t #f))
         0 0 0 8 #f #f))

  (test (normalize-lw (to-loc-wrapper (term x)))
        (build-loc-wrapper 
         (list 
          (build-loc-wrapper "(" 0 0 0 1)
          (build-loc-wrapper 'term 0 0 1 4)
          (build-loc-wrapper 'x 0 0 6 1)
          (build-loc-wrapper ")" 0 0 7 1))
         0 0 0 8))
  
  (test (normalize-lw (to-loc-wrapper '(term x)))
        (build-loc-wrapper
         (list 
          (build-loc-wrapper "'" 0 0 0 1)
          'spring
          (build-loc-wrapper
           (list
            (build-loc-wrapper "(" 0 0 1 1)
            (build-loc-wrapper 'term 0 0 2 4)
            (build-loc-wrapper 'x 0 0 7 1)
            (build-loc-wrapper ")" 0 0 8 1))
           0
           0
           1
           8))
         0 0 0 9))
  
  (test (normalize-lw (to-loc-wrapper ''x))
        (build-loc-wrapper
         (list 
          (build-loc-wrapper "'" 0 0 0 1)
          'spring
          (build-loc-wrapper
           (list
            (build-loc-wrapper "'" 0 0 1 1)
            'spring
            (build-loc-wrapper 'x 0 0 2 1))
           0
           0
           1
           2))
         0 0 0 3))
  
  ;; this one seems suspicious: why does the second comma start at 1 instead of 0?
  ;; rendering seems to work, however, so we'll go with it ..
  (test (normalize-lw (to-loc-wrapper ,,x))
        (build-loc-wrapper
         (list 
          (build-loc-wrapper "" 0 0 0 0)
          'spring
          (make-loc-wrapper
           (list
            (make-loc-wrapper "," 0 0 1 1 #t #f)
            'spring
            (make-loc-wrapper 'x 0 0 2 1 #t #f))
           0 0 1 2
           #t #f))
         0 0 0 3))
  
  (print-tests-passed "lw-test.ss"))