Skip to content

Commit

Permalink
Update ReflectionOfType to implement IntoString trait.
Browse files Browse the repository at this point in the history
This allows for easier printing of the `reflection_of_type` macro.
  • Loading branch information
jemc committed Aug 30, 2024
1 parent 2ff24e5 commit d7fb05d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions core/Reflection.savi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

:let features Array(ReflectionFeatureOfType(A)): []

:is IntoString
:fun into_string_space USize: @string.size
:fun into_string(out String'ref) None: @string.into_string(out)

:class val ReflectionFeatureOfType(A)
:let name String: ""
:let tags Array(String): []
Expand Down
10 changes: 6 additions & 4 deletions spec/language/semantics/reflection_spec.savi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
:fun run(test MicroTest)
test["reflection_of_type.string String"].pass =
(reflection_of_type "example").string == "String"
test["reflection_of_type.string String'ref"].pass =
(reflection_of_type String.new).string == "String'ref"
test["reflection_of_type.string Array(U8)"].pass =
(reflection_of_type Array(U8).new).string == "Array(U8)"
test["reflection_of_type string String"].pass =
"\(reflection_of_type "example")" == "String"
test["reflection_of_type string String'ref"].pass =
"\(reflection_of_type String.new)" == "String'ref"
test["reflection_of_type string Array(U8)"].pass =
"\(reflection_of_type Array(U8).new)" == "Array(U8)"

test["reflection_of_runtime_type_name U64"].pass =
(reflection_of_runtime_type_name U64[0]) == "U64"
Expand Down

0 comments on commit d7fb05d

Please sign in to comment.