]> gitweb.factorcode.org Git - factor.git/commitdiff
bare: more error checking
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 16 Jun 2022 17:31:51 +0000 (10:31 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 16 Jun 2022 17:31:51 +0000 (10:31 -0700)
extra/bare/bare-tests.factor
extra/bare/bare.factor

index 94e9046b5586b411a402e5b73b52d24eadfeb6aa..80632711b42584e2b6eedae3f5688197010feb74 100644 (file)
@@ -377,15 +377,6 @@ type Person union {Customer | Employee | TerminatedEmployee}
     B{ 0x02 } Person bare>
 ] unit-test
 
-! data checks
-
-[ "type Foo data[0]" parse-schema ] [ invalid-length? ] must-fail-with
-[ "type Foo data[18446744073709551616]" parse-schema ] [ invalid-length? ] must-fail-with
-
-! optional checks
-
-[ "type Foo optional<void>" parse-schema ] [ cannot-be-void? ] must-fail-with
-
 ! enum checks
 
 [
@@ -408,6 +399,27 @@ type Person union {Customer | Employee | TerminatedEmployee}
     }" parse-schema
 ] [ duplicate-values? ] must-fail-with
 
+! data checks
+
+[ "type Foo data[0]" parse-schema ] [ invalid-length? ] must-fail-with
+[ "type Foo data[18446744073709551616]" parse-schema ] [ invalid-length? ] must-fail-with
+
+! optional checks
+
+[ "type Foo optional<void>" parse-schema ] [ cannot-be-void? ] must-fail-with
+
+! list checks
+
+[ "type Foo list<void>" parse-schema ] [ cannot-be-void? ] must-fail-with
+[ "type Foo list<int>[0]" parse-schema ] [ invalid-length? ] must-fail-with
+[ "type Foo list<int>[18446744073709551616]" parse-schema ] [ invalid-length? ] must-fail-with
+
+! map checks
+
+[ "type Foo map<void><int>" parse-schema ] [ cannot-be-void? ] must-fail-with
+[ "type Foo map<void><void>" parse-schema ] [ cannot-be-void? ] must-fail-with
+[ "type Foo map<int><void>" parse-schema ] [ cannot-be-void? ] must-fail-with
+
 ! union checks
 
 [ "type Thing union {int=0|int|str=0}" parse-schema ] [ duplicate-keys? ] must-fail-with
@@ -416,6 +428,7 @@ type Person union {Customer | Employee | TerminatedEmployee}
 ! struct checks
 
 [ "type Thing struct { a: int b: int a: int }" parse-schema ] [ duplicate-keys? ] must-fail-with
+[ "type Thing struct { a: void }" parse-schema ] [ cannot-be-void? ] must-fail-with
 
 ! user checks
 
index ef3937ff221351608f5ef8be42c9541c5864a345..6053585a5088b56371c95cd94d919ac4c2fa1bf7 100644 (file)
@@ -81,13 +81,16 @@ PRIVATE>
 : <list> ( type length -- list )
     [ check-void ] [ check-length ] bi* list boa ;
 
-C: <map> map ! XXX: check key types?
+: <map> ( from to -- map )
+    ! XXX: check key types?
+    [ check-void ] bi@ map boa ;
 
 : <union> ( members -- union )
     assign-values check-duplicates check-entries union boa ;
 
 : <struct> ( fields -- struct )
-    check-duplicate-keys check-entries struct boa ;
+    check-duplicate-keys check-entries
+    dup [ check-void 2drop ] assoc-each struct boa ;
 
 C: <user> user