add tests on empty brackets

This commit is contained in:
DieMyst 2022-03-04 12:20:55 +03:00
parent 20bdf06e48
commit c1dd156b39
4 changed files with 109 additions and 5 deletions

View File

@ -23,3 +23,15 @@ func optionSugar(numSome: ?u32, strSome: ?string, numNone: ?u32, strNone: ?strin
str <<- i
<- arr, str, str2
func emptySugar() -> []u32, []string, []string, *string, ?u32, []u32, ?string:
numOp = ?[]
strArr = []
strStream = *[]
strEmptyStream: *string
for i <- ?[]:
strEmptyStream <<- "some"
for i <- *[]:
strEmptyStream <<- "some"
for i <- []:
strEmptyStream <<- "some"
<- numOp, strArr, strStream, strEmptyStream, [], ?[], *[]

View File

@ -36,7 +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";
import {allEmptySugarCall, arraySugarCall, optionSugarCall, streamSugarCall} from "../examples/collectionSugarCall";
var selfPeerId: string;
var peer2: FluencePeer;
@ -164,23 +164,25 @@ describe('Testing examples', () => {
});
it('collectionSugar array', async () => {
console.log("collectionSugar array")
let result = await arraySugarCall();
expect(result).toEqual([[1,2,3], [4,5,6]]);
});
it('collectionSugar stream', async () => {
console.log("collectionSugar stream")
let result = await streamSugarCall();
expect(result).toEqual([[1,2,3], [4,5,6]]);
});
it('collectionSugar option', async () => {
console.log("collectionSugar option")
let result = await optionSugarCall()
expect(result).toEqual([[1], ["some"], []]);
});
it('collectionSugar empty', async () => {
let result = await allEmptySugarCall()
expect(result).toEqual([[], [], [], [], null, [], null]);
});
it.skip('recursiveStreams.aqua', async () => {
let recResult = await recursiveStreamsCall();

View File

@ -441,3 +441,89 @@ export function optionSugar(...args: any) {
script
)
}
export type EmptySugarResult = [number[], string[], string[], string[], number | null, number[], string | null]
export function emptySugar(
config?: {ttl?: number}
): Promise<EmptySugarResult>;
export function emptySugar(
peer: FluencePeer,
config?: {ttl?: number}
): Promise<EmptySugarResult>;
export function emptySugar(...args: any) {
let script = `
(xor
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(new $strStream
(seq
(new $strArr
(seq
(new $numOp
(call %init_peer_id% ("op" "identity") [[]] numOp-fix)
)
(call %init_peer_id% ("op" "identity") [[]] strArr-fix)
)
)
(call %init_peer_id% ("op" "identity") [[]] strStream-fix)
)
)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [numOp-fix strArr-fix strStream-fix $strEmptyStream [] [] []])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
`
return callFunction(
args,
{
"functionName" : "emptySugar",
"returnType" : {
"tag" : "multiReturn",
"returnItems" : [
{
"tag" : "primitive"
},
{
"tag" : "primitive"
},
{
"tag" : "primitive"
},
{
"tag" : "primitive"
},
{
"tag" : "optional"
},
{
"tag" : "primitive"
},
{
"tag" : "optional"
}
]
},
"argDefs" : [
],
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
}

View File

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