;;;; Copyright 2002, Jonathan Bachrach.  See file TERMS.

(use goo)
(use tests/driver)
(use eval/dependency)

(test-group dep-types
  (test== (dependency-nul? $nul-dependency)      #t)
  (test== (dependency-nul? $name-parse-dependency) #f)
  (test== (dependency-includes-all? $parse-dependencies $name-parse-dependency)
          #t)
  (let ((n-and-e (dependency-or $name-parse-dependency
                                $expansion-parse-dependency)))
    (test== (dependency-includes-all? n-and-e $name-parse-dependency) #t)
    (test== (dependency-includes-all? n-and-e $expansion-parse-dependency)
            #t)))

(dc <test-dependent> (<dependent>))
  (dp! last-invalidation (<test-dependent> => <dependency-type>)
    $nul-dependency)
  (dp! invalidation-count (<test-dependent> => <int>) 
    0)

(dm invalidate-dependent
    (self|<test-dependent> dependable|<dependable> dtype|<dependency-type>)
  (set (last-invalidation self) dtype)
  (incf (invalidation-count self)))

(test-group dep-track
  (def source1 (new <dependable>))
  (def source2 (new <dependable>))
  (def dest1 (new <test-dependent>))
  (def dest2 (new <test-dependent>))
  (test== (find-dependency source1 dest1) #f)
  (test== (find-dependency source1 dest2) #f)
  (log-dependency source1 dest1 $name-parse-dependency)
  (test=  (find-dependency source1 dest1) $name-parse-dependency)
  (log-dependency source1 dest2 $expansion-parse-dependency)
  (log-dependency source1 dest2 $value-optimization-dependency)
  (test=  (find-dependency source1 dest2)
          (dependency-or $expansion-parse-dependency
                         $value-optimization-dependency))
  (test== (invalidation-count dest1) 0)
  (test=  (last-invalidation dest1) $nul-dependency)
  (test== (invalidation-count dest2) 0)
  (test=  (last-invalidation dest2) $nul-dependency)
  (invalidate-dependents source1 $parse-dependencies)
  (test== (invalidation-count dest1) 1)
  (test=  (last-invalidation dest1) $name-parse-dependency)
  (test== (invalidation-count dest2) 1)
  (test=  (last-invalidation dest2) $expansion-parse-dependency)
  (invalidate-dependents source1 $optimizaton-dependencies)
  (test== (invalidation-count dest1) 1)
  (test== (invalidation-count dest2) 2)
  (test=  (last-invalidation dest2) $value-optimization-dependency)
  (log-dependency source2 dest2 $name-parse-dependency)
  (test=  (find-dependency source2 dest2) $name-parse-dependency)
  (detach-dependent dest2)
  (test=  (find-dependency source1 dest2) #f)
  (test=  (find-dependency source2 dest2) #f))
