skipped collection sugar tests

This commit is contained in:
DieMyst 2022-03-02 18:54:58 +03:00
parent 13b4c58855
commit 29696fe06e
5 changed files with 488 additions and 2 deletions

View File

@ -0,0 +1,25 @@
func arraySugar(n: u32, m: u32) -> []u32, []u32:
arr = [1,2,n]
str: *u32
for i <- [4,5,m]:
str <<- i
<- arr, str
func streamSugar(n: u32, m: u32) -> []u32, []u32:
arr = *[1,2,n]
str: *u32
for i <- *[4,5,m]:
str <<- i
<- arr, str
func optionSugar(numSome: ?u32, strSome: ?string, numNone: ?u32, strNone: ?string) -> []u32, []string, []string:
arr = ?[numNone!, numSome!]
str: *string
str2 = ?[strNone!, strNone!]
for i <- ?[strSome!,strNone!, "random string"]:
str <<- i
for i <- ?[strNone!,strNone!]:
str <<- i
<- arr, str, str2

View File

@ -9,7 +9,5 @@ func recursiveStream() -> []string:
for l <- loop:
if l == "yes":
loop <- YesNoService.get()
else:
loop <- YesNoService.get()
result <<- "success"
<- result

View File

@ -36,6 +36,7 @@ import {streamResCall} from "../examples/streamRestrictionsCall";
import {joinIdxCall, joinIdxLocalCall, joinIdxRelayCall} from "../examples/joinCall";
import {topologyBug427} from "../compiled/examples/topology";
import {recursiveStreamsCall} from "../examples/recursiveStreamsCall";
import {arraySugarCall, optionSugarCall, streamSugarCall} from "../examples/collectionSugarCall";
var selfPeerId: string;
var peer2: FluencePeer;
@ -162,6 +163,21 @@ describe('Testing examples', () => {
expect(streamCanResult).toEqual([["a"], ["b"], []]);
});
it.skip('collectionSugar.aqua array', async () => {
let result = await arraySugarCall();
expect(result).toEqual([[1,2,3], [4,5,6]]);
});
it.skip('collectionSugar.aqua stream', async () => {
let result = await streamSugarCall();
expect(result).toEqual([[1,2,3], [4,5,6]]);
});
it.skip('collectionSugar.aqua option', async () => {
let result = await optionSugarCall()
expect(result).toEqual([[1], ["some"], []]);
});
it.skip('recursiveStreams.aqua', async () => {
let recResult = await recursiveStreamsCall();

View File

@ -0,0 +1,434 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.6.3-SNAPSHOT
*
*/
import { Fluence, FluencePeer } from '@fluencelabs/fluence';
import {
CallParams,
callFunction,
registerService,
} from '@fluencelabs/fluence/dist/internal/compilerSupport/v2';
// Services
// Functions
export type ArraySugarResult = [number[], number[]]
export function arraySugar(
n: number,
m: number,
config?: {ttl?: number}
): Promise<ArraySugarResult>;
export function arraySugar(
peer: FluencePeer,
n: number,
m: number,
config?: {ttl?: number}
): Promise<ArraySugarResult>;
export function arraySugar(...args: any) {
let script = `
(xor
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "n") [] n)
)
(call %init_peer_id% ("getDataSrv" "m") [] m)
)
(new $str
(seq
(seq
(seq
(seq
(seq
(new $array-sugar
(seq
(seq
(seq
(ap 1 $array-sugar)
(ap 2 $array-sugar)
)
(ap n $array-sugar)
)
(call %init_peer_id% ("op" "identity") [$array-sugar] array-sugar-0)
)
)
(new $array-sugar-1
(seq
(seq
(seq
(ap 4 $array-sugar-1)
(ap 5 $array-sugar-1)
)
(ap m $array-sugar-1)
)
(call %init_peer_id% ("op" "identity") [$array-sugar-1] array-sugar-1-0)
)
)
)
(fold array-sugar-1-0 i
(null)
)
)
(ap i $str)
)
(next i)
)
(call %init_peer_id% ("op" "identity") [$str] str-fix)
)
)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [array-sugar-0 str-fix])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`
return callFunction(
args,
{
"functionName" : "arraySugar",
"returnType" : {
"tag" : "multiReturn",
"returnItems" : [
{
"tag" : "primitive"
},
{
"tag" : "primitive"
}
]
},
"argDefs" : [
{
"name" : "n",
"argType" : {
"tag" : "primitive"
}
},
{
"name" : "m",
"argType" : {
"tag" : "primitive"
}
}
],
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
}
export type StreamSugarResult = [number[], number[]]
export function streamSugar(
n: number,
m: number,
config?: {ttl?: number}
): Promise<StreamSugarResult>;
export function streamSugar(
peer: FluencePeer,
n: number,
m: number,
config?: {ttl?: number}
): Promise<StreamSugarResult>;
export function streamSugar(...args: any) {
let script = `
(xor
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "n") [] n)
)
(call %init_peer_id% ("getDataSrv" "m") [] m)
)
(new $str
(seq
(new $arr
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(ap 1 $stream-sugar)
(ap 2 $stream-sugar)
)
(ap n $stream-sugar)
)
(ap 4 $stream-sugar-0)
)
(ap 5 $stream-sugar-0)
)
(ap m $stream-sugar-0)
)
(fold $stream-sugar-0 i
(null)
)
)
(ap i $str)
)
(next i)
)
(call %init_peer_id% ("op" "identity") [$stream-sugar] arr-fix)
)
)
(call %init_peer_id% ("op" "identity") [$str] str-fix)
)
)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [arr-fix str-fix])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`
return callFunction(
args,
{
"functionName" : "streamSugar",
"returnType" : {
"tag" : "multiReturn",
"returnItems" : [
{
"tag" : "primitive"
},
{
"tag" : "primitive"
}
]
},
"argDefs" : [
{
"name" : "n",
"argType" : {
"tag" : "primitive"
}
},
{
"name" : "m",
"argType" : {
"tag" : "primitive"
}
}
],
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
}
export type OptionSugarResult = [number[], string[], string[]]
export function optionSugar(
numSome: number | null,
strSome: string | null,
numNone: number | null,
strNone: string | null,
config?: {ttl?: number}
): Promise<OptionSugarResult>;
export function optionSugar(
peer: FluencePeer,
numSome: number | null,
strSome: string | null,
numNone: number | null,
strNone: string | null,
config?: {ttl?: number}
): Promise<OptionSugarResult>;
export function optionSugar(...args: any) {
let script = `
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "numSome") [] numSome)
)
(call %init_peer_id% ("getDataSrv" "strSome") [] strSome)
)
(call %init_peer_id% ("getDataSrv" "numNone") [] numNone)
)
(call %init_peer_id% ("getDataSrv" "strNone") [] strNone)
)
(new $str
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(new $option-sugar
(seq
(xor
(ap numNone.$.[0]! $option-sugar)
(ap numSome.$.[0]! $option-sugar)
)
(call %init_peer_id% ("op" "identity") [$option-sugar] option-sugar-0)
)
)
(new $option-sugar-1
(seq
(xor
(ap strNone.$.[0]! $option-sugar-1)
(ap strNone.$.[0]! $option-sugar-1)
)
(call %init_peer_id% ("op" "identity") [$option-sugar-1] option-sugar-1-0)
)
)
)
(new $option-sugar-2
(seq
(xor
(xor
(ap strSome.$.[0]! $option-sugar-2)
(ap strNone.$.[0]! $option-sugar-2)
)
(ap "random string" $option-sugar-2)
)
(call %init_peer_id% ("op" "identity") [$option-sugar-2] option-sugar-2-0)
)
)
)
(fold option-sugar-2-0 i
(null)
)
)
(ap i $str)
)
(next i)
)
(new $option-sugar-3
(seq
(xor
(ap strNone.$.[0]! $option-sugar-3)
(ap strNone.$.[0]! $option-sugar-3)
)
(call %init_peer_id% ("op" "identity") [$option-sugar-3] option-sugar-3-0)
)
)
)
(fold option-sugar-3-0 i
(null)
)
)
(ap i $str)
)
(next i)
)
(call %init_peer_id% ("op" "identity") [$str] str-fix)
)
)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [option-sugar-0 str-fix option-sugar-1-0])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`
return callFunction(
args,
{
"functionName" : "optionSugar",
"returnType" : {
"tag" : "multiReturn",
"returnItems" : [
{
"tag" : "primitive"
},
{
"tag" : "primitive"
},
{
"tag" : "primitive"
}
]
},
"argDefs" : [
{
"name" : "numSome",
"argType" : {
"tag" : "optional"
}
},
{
"name" : "strSome",
"argType" : {
"tag" : "optional"
}
},
{
"name" : "numNone",
"argType" : {
"tag" : "optional"
}
},
{
"name" : "strNone",
"argType" : {
"tag" : "optional"
}
}
],
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
}

View File

@ -0,0 +1,13 @@
import {arraySugar, optionSugar, streamSugar} from "../compiled/examples/collectionSugar";
export async function arraySugarCall(): Promise<[number[], number[]]> {
return await arraySugar(3, 6)
}
export async function streamSugarCall(): Promise<[number[], number[]]> {
return await streamSugar(3, 6)
}
export async function optionSugarCall(): Promise<[number[], string[], string[]]> {
return await optionSugar(1, "some", null, null)
}