]> Cypherpunks repositories - keks.git/commitdiff
Widen comparable types for EQ command
authorSergey Matveev <stargrave@stargrave.org>
Sat, 5 Apr 2025 07:34:31 +0000 (10:34 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 5 Apr 2025 07:34:31 +0000 (10:34 +0300)
c/lib/schema.c
go/schema/check.go
spec/schema/cmds.texi
tcl/schema2bin

index 7251dd3a4641d5cfc24cbd161bf13f8e3e1b83538eea32451145dbe2737a68c1..988d359833ddf2fac15ccab078557d77db616895ce5a7e449e1dd8c790ac7ee0 100644 (file)
@@ -257,9 +257,9 @@ Eached:
                 return err;
             }
             err.offSchema = schema->offsets[idxSchema];
-            if (schema->list[idxSchema].atom.typ != KEKSItemStr) {
+            if (schema->list[idxSchema].atom.typ != KEKSItemBin) {
                 err.code = KEKSSchemaErrInvalidSchema;
-                err.msg = "non-str EQ";
+                err.msg = "non-bin EQ";
                 return err;
             }
             err.code = ((schema->list[idxSchema].atom.v.str.len ==
index 9e0f2e6e3340ea1764f0bcdd801528161fb35c36c11d6464970eee3025a18925..ffc8aa84b50e3503c06176736c68257010971b25ab388419958b70e69e633a7d 100644 (file)
@@ -16,6 +16,7 @@
 package schema
 
 import (
+       "bytes"
        "errors"
        "fmt"
        "slices"
@@ -115,16 +116,35 @@ func Check(schemaName string, schemas map[string][][]any, data any) error {
                        if len(act) != 2 {
                                return fmt.Errorf("%s: %d: %s: wrong number of args", schemaName, i, cmd)
                        }
-                       expect, ok := act[1].(string)
+                       expect, ok := act[1].([]byte)
                        if !ok {
-                               return fmt.Errorf("%s: %d: %s: bad str: %+v", schemaName, i, cmd, act[1])
+                               return fmt.Errorf("%s: %d: %s: bad bin: %+v", schemaName, i, cmd, act[1])
                        }
                        for _, v := range vs {
-                               got, ok := v.(string)
-                               if !ok {
-                                       return fmt.Errorf("%s: %d: %s: not str: %T", schemaName, i, cmd, v)
+                               var eq bool
+                               switch got := v.(type) {
+                               case string:
+                                       eq = got == string(expect)
+                               case []byte:
+                                       eq = bytes.Equal(got, expect)
+                               case keks.Hexlet:
+                                       eq = bytes.Equal(got[:], expect)
+                               case *tai64n.TAI64:
+                                       eq = bytes.Equal(got[:], expect)
+                               case *tai64n.TAI64N:
+                                       eq = bytes.Equal(got[:], expect)
+                               case *tai64n.TAI64NA:
+                                       eq = bytes.Equal(got[:], expect)
+                               case keks.Magic:
+                                       eq = string(got) == string(expect)
+                               case keks.Raw:
+                                       eq = bytes.Equal(got, expect)
+                               default:
+                                       if !ok {
+                                               return fmt.Errorf("%s: %d: %s: non-comparable: %T", schemaName, i, cmd, v)
+                                       }
                                }
-                               if got != expect {
+                               if !eq {
                                        return fmt.Errorf("%s: %d: %s: !=", schemaName, i, cmd)
                                }
                        }
index f37f324c6c045b466836cf076932cf8385ca87b2340e224b59fe97ec367e97bc..6804d67f9cb2057e4b5b1e7e7c2a32c48a3884714869904aeb08785503d81be6 100644 (file)
@@ -60,7 +60,7 @@ maximal time precision. "p" is integer with following possible values:
     @end itemize
 
 @item = v
-Check that chosen (if it exists) string element's value equals to "v".
+Check that chosen (if it exists) element's value equals to binary string "v".
 
 @end table
 
index 159054d28cf809c1df960f8257379c83f874d38ed0551aca22eb9a6b6895aaa1..23f4d1a721e5d0b8fe5aa9556e64f116d38a845c0957ea7f3ab36f9d0281af65 100755 (executable)
@@ -28,7 +28,7 @@ proc TAKE {v} {
 proc EXISTS {} {return {{LIST {{STR E}}}}}
 proc !EXISTS {} {return {{LIST {{STR !E}}}}}
 proc EACH {} {return {{LIST {{STR *}}}}}
-proc EQ {v} {subst {{LIST {{STR =} {STR $v}}}}}
+proc EQ {v} {subst {{LIST {{STR =} {BIN $v}}}}}
 proc TYPE {vs} {
     set l {{STR T}}
     foreach v $vs {