StrictCastOverVariant.yqls 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. (
  2. (let config (DataSource 'config))
  3. (let res_sink (DataSink 'result))
  4. ### Tuple
  5. (let srcType (VariantType (TupleType (DataType 'Int32) (DataType 'String))))
  6. (let targetType (VariantType (TupleType (DataType 'Uint8) (DataType 'Utf8))))
  7. # Variant<Tuple<Int32, String>> -> Variant<Tuple<Uint8, Utf8>>? (good)
  8. (let value (Variant (String 'one) '1 srcType))
  9. (let cast (StrictCast value targetType))
  10. (let world (Write! world res_sink (Key) cast '('('type))))
  11. # Variant<Tuple<Int32, String>> -> Variant<Tuple<Uint8, Utf8>>? (null)
  12. (let value (Variant (String '"garbage\xff") '1 srcType))
  13. (let cast (StrictCast value targetType))
  14. (let world (Write! world res_sink (Key) cast '('('type))))
  15. ### Struct
  16. (let srcType (VariantType (StructType '('a (DataType 'Int32)) '('b (DataType 'String)))))
  17. (let targetType (VariantType (StructType '('a (DataType 'Uint8)) '('b (DataType 'Utf8)))))
  18. # Variant<Struct<Int32, String>> -> Variant<Struct<Uint8, Utf8>>? (good)
  19. (let value (Variant (Int32 '1) 'a srcType))
  20. (let cast (StrictCast value targetType))
  21. (let world (Write! world res_sink (Key) cast '('('type))))
  22. # Variant<Struct<Int32, String>> -> Variant<Struct<Uint8, Utf8>>? (null)
  23. (let value (Variant (Int32 '"-1") 'a srcType))
  24. (let cast (StrictCast value targetType))
  25. (let world (Write! world res_sink (Key) cast '('('type))))
  26. (let world (Commit! world res_sink))
  27. (return world)
  28. )