Add dynamic param test

This commit is contained in:
Agus Zubiaga 2024-08-17 16:35:48 -03:00
parent 0adad85634
commit 50efed6612
No known key found for this signature in database
3 changed files with 19 additions and 3 deletions

View File

@ -735,14 +735,19 @@ mod cli_run {
r#"
App1.baseUrl: https://api.example.com/one
App2.baseUrl: http://api.example.com/two
App3.baseUrl: https://api.example.com/three
App1.getUser 1: https://api.example.com/one/users/1
App2.getUser 2: http://api.example.com/two/users/2
App3.getUser 3: https://api.example.com/three/users/3
App1.getPost 1: https://api.example.com/one/posts/1
App2.getPost 2: http://api.example.com/two/posts/2
App3.getPost 3: https://api.example.com/three/posts/3
App1.getPostComments 1: https://api.example.com/one/posts/1/comments
App2.getPostComments 2: http://api.example.com/two/posts/2/comments
App2.getPostComments 3: http://api.example.com/two/posts/3/comments
App1.getCompanies [1, 2]: ["https://api.example.com/one/companies/1", "https://api.example.com/one/companies/2"]
App2.getCompanies [3, 4]: ["http://api.example.com/two/companies/3", "http://api.example.com/two/companies/4"]
App2.getCompanies [5, 6]: ["http://api.example.com/two/companies/5", "http://api.example.com/two/companies/6"]
"#
),
UseValgrind::No,

View File

@ -1,25 +1,27 @@
module { appId, protocol } -> [baseUrl, getUser, getPost, getPostComments, getCompanies]
## value def referencing params
baseUrl : Str
baseUrl =
protocol "api.example.com/$(appId)"
## function def referencing params
getUser : U32 -> Str
getUser = \userId ->
# purposefully not using baseUrl to test top-level fn referencing param
protocol "api.example.com/$(appId)/users/$(Num.toStr userId)"
## function def referencing top-level value that references param
getPost : U32 -> Str
getPost = \postId ->
"$(baseUrl)/posts/$(Num.toStr postId)"
## function def referencing top-level function that references param
getPostComments : U32 -> Str
getPostComments = \postId ->
"$(getPost postId)/comments"
## function def referencing nested function that references param
getCompanies : List U32 -> List Str
getCompanies = \ids ->
getCompany = \id ->

View File

@ -9,15 +9,24 @@ https = \url -> "https://$(url)"
http = \url -> "http://$(url)"
main =
app3Id = "three"
import Api { appId: app3Id, protocol: https } as App3
"""
App1.baseUrl: $(App1.baseUrl)
App2.baseUrl: $(App2.baseUrl)
App3.baseUrl: $(App3.baseUrl)
App1.getUser 1: $(App1.getUser 1)
App2.getUser 2: $(App2.getUser 2)
App3.getUser 3: $(App3.getUser 3)
App1.getPost 1: $(App1.getPost 1)
App2.getPost 2: $(App2.getPost 2)
App3.getPost 3: $(App3.getPost 3)
App1.getPostComments 1: $(App1.getPostComments 1)
App2.getPostComments 2: $(App2.getPostComments 2)
App2.getPostComments 3: $(App2.getPostComments 3)
App1.getCompanies [1, 2]: $(Inspect.toStr (App1.getCompanies [1, 2]))
App2.getCompanies [3, 4]: $(Inspect.toStr (App2.getCompanies [3, 4]))
App2.getCompanies [5, 6]: $(Inspect.toStr (App2.getCompanies [5, 6]))
"""