Stephen Compall avatar Stephen Compall committed 2442ca1

Rename valid-widget to widget-designator [#35 state:resolved]

Also remove the ability to extend the widget-designator type directly. Test for all of this.

Comments (0)

Files changed (4)

src/widgets/composite.lisp

         (assert (cons-in-list-p place (composite-widgets composite)))
         (cond
           (callee-supplied-p
-            (check-type callee valid-widget
+            (check-type callee widget-designator
                         "a potential member of a composite")
             (rplaca place callee)
             (setf (widget-parent callee) composite)

src/widgets/selector-mixin.lisp

     (lambda (&optional (callee nil callee-supplied-p))
       (assert (find place (selector-mixin-panes selector)))
       (cond (callee-supplied-p
-	     (check-type callee valid-widget
+	     (check-type callee widget-designator
 			 "a potential pane of a selector-mixin")
 	     (rplacd place callee)
 	     (setf (widget-parent callee) selector)

src/widgets/widget/widget.lisp

       (error "Widget ~a already has a parent." obj)
       (setf (slot-value obj 'parent) val)))
 
-(deftype valid-widget ()
+(deftype widget-designator ()
   "The supertype of all widgets.  Check against this type instead of
 `widget' unless you know what you're doing."
-  '(satisfies valid-widget-p))
+  '(or widget (and symbol (not null)) string function))
 
-(defgeneric valid-widget-p (widget)
-  (:documentation "Returns t when widget is a valid, renderable widget;
-   this includes strings, function, etc.")
-  (:method ((obj widget)) t)
-  (:method ((obj symbol)) t)
-  (:method ((obj function)) t)
-  (:method ((obj string)) t)
-  (:method ((obj null)) nil)
-  (:method (obj) nil))
+(defun widget-designator-p (widget)
+  "Returns t when widget is a valid, renderable widget; this includes
+strings, function, etc."
+  (identity (typep widget 'widget-designator)))
 
 ;;; Define widget-rendered-p for objects that don't derive from
 ;;; 'widget'

test/widgets/widget/widget.lisp

     (widget-name 'identity)
   identity)
 
-;;; valid-widget typechecking
+;;; widget-designator typechecking
 (addtest nil-is-not-valid
-  (ensure-null (weblocks::valid-widget-p nil)))
+  (ensure-same (typep nil 'weblocks::widget-designator)
+	       (values nil t))
+  (ensure-null (weblocks::widget-designator-p nil)))
 
-(addtest valid-widget-export-status-same
-  (ensure-same (symbol-status 'weblocks::valid-widget)
-	       (symbol-status 'weblocks::valid-widget-p)))
+(addtest widget-designator-export-status-same
+  (ensure-same (symbol-status 'weblocks::widget-designator)
+	       (symbol-status 'weblocks::widget-designator-p)))
+
+(addtest widget-designator-type-not-extensible
+  (ensure-null
+   (typep #'weblocks::widget-designator-p 'generic-function)))
 
 ;;; test composite-widgets specialization for widgets
 (deftest composite-widgets-1
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.