Convert vector elements when needed (#7271)

Adds a test case demonstrating the _use of automatic conversions_ when processing vector elements.
This commit is contained in:
Jaroslav Tulach 2023-07-12 14:05:33 +01:00 committed by GitHub
parent 1d77f7cd8e
commit 724a788500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -2,6 +2,7 @@ from Standard.Base import all
import project.Semantic.Conversion.Methods import project.Semantic.Conversion.Methods
import project.Semantic.Conversion.Types import project.Semantic.Conversion.Types
import project.Semantic.Conversion_Use.Hello
from Standard.Test import Test, Test_Suite from Standard.Test import Test, Test_Suite
import Standard.Test.Extensions import Standard.Test.Extensions
@ -115,4 +116,11 @@ spec =
Test.specify "should not allow currying" <| Test.specify "should not allow currying" <|
Panic.recover Any (Foo.from) . catch Any .to_display_text . should_equal "Conversion currying without `that` argument is not supported." Panic.recover Any (Foo.from) . catch Any .to_display_text . should_equal "Conversion currying without `that` argument is not supported."
Test.specify "Use conversions to in Conversion_Use module" <|
Hello.formulate [ Hello.Say "Proper", Hello.Say "Type" ] . should_equal "ProperType"
Hello.formulate [ Foo.Value "Perform", Bar.Value "Conversion" ] . should_equal "PERFORM conversion!"
Hello.from (that:Foo) = Hello.Say <| (that.foo.to_case Case.Upper) + " "
Hello.from (that:Bar) = Hello.Say <| (that.bar.to_case Case.Lower) + "!"
main = Test_Suite.run_main spec main = Test_Suite.run_main spec

View File

@ -0,0 +1,9 @@
from Standard.Base import all
type Hello
Say (msg:Text)
formulate : Vector Hello -> Text
formulate arr =
process (t:Text) (h:Hello) = t + h.msg
arr.fold "" process