Skip to content

Commit

Permalink
adding tests for pForEach and $path
Browse files Browse the repository at this point in the history
  • Loading branch information
nmaguiar authored Oct 28, 2024
1 parent 4c9bea1 commit 1d5dd6c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
24 changes: 24 additions & 0 deletions tests/autoTestAll.Generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@
);
};

exports.testPath = function() {
ow.test.assert($path({ x: true }, "to_number(if(x, '1', '0'))"), 1, "Problem with $path if")
ow.test.assert($path({ y: true }, "assign(@, 'x', `false`)"), { x: false, y: true }, "Problem with $path assign")
ow.test.assert($path({ y: { a: 1 } }, "assignp('y', 'x', `false`)"), { y: { a: 1, x: false } }, "Problem with $path assignp")
ow.test.assert($path({}, "env('PATH')"), getEnv("PATH"), "Problem with $path env")
ow.test.assert($path({}, "envs('^PATH$')"), [ { name: 'PATH', value: getEnv("PATH") } ], "Problem with $path envs")
}

exports.testCache = function() {
$cache("cache")
.fn((k) => {
Expand Down Expand Up @@ -689,6 +697,22 @@
ow.test.assert(af.decrypt(af.encrypt(res1, "1234567890123456"), "1234567890123456"), res1, "Problem with custom encrypt/decrypt.");
};

exports.testPForEach = function() {
var files = listFilesRecursive("..")
var res = pForEach(files, r => {
return r.isFile ? 1 : 0
})
ow.test.assert($from(res).count(), files.length, "Problem with pForEach (1)")
ow.test.assert($from(res).sum(), $from(files).equals("isFile", true).count(), "Problem with pForEach (2)")

files = io.listFiles(".").files
res = pForEach(files, r => {
return r.isFile ? 1 : 0
})
ow.test.assert($from(res).count(), files.length, "Problem with pForEach (3)")
ow.test.assert($from(res).sum(), $from(files).equals("isFile", true).count(), "Problem with pForEach (4)")
}

exports.test2FA = function() {
ow.loadFormat();

Expand Down
14 changes: 13 additions & 1 deletion tests/autoTestAll.Generic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ jobs:
to : oJob Test
exec: args.func = args.tests.testAFScopeIds

- name: OpenAF::Test Path
from: OpenAF::Init
to : oJob Test
exec: args.func = args.tests.testPath

- name: OpenAF::Test pForEach
from: OpenAF::Init
to : oJob Test
exec: args.func = args.tests.testPForEach

todo:
# Generic Tests
# -------------
Expand Down Expand Up @@ -309,4 +319,6 @@ todo:
- OpenAF::Test Void shortcut
- OpenAF::Test Envs
- OpenAF::Test AF Parse
- OpenAF::Test Scope Ids
- OpenAF::Test Scope Ids
- OpenAF::Test Path
- OpenAF::Test pForEach

0 comments on commit 1d5dd6c

Please sign in to comment.