-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added test cases for left functions
- Loading branch information
1 parent
142bbd5
commit aafd2be
Showing
9 changed files
with
390 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
import TestClient from '@aoi.js/testing/testClient.js'; | ||
import { $abs } from './$abs.js'; | ||
|
||
const client = new TestClient(); | ||
client.transpiler.addFunctions({ $abs }); | ||
|
||
const transpilerOptions = { | ||
scopeData: { | ||
name: 'global', | ||
vars: [], | ||
embeds: [], | ||
env: [], | ||
object: {}, | ||
embeddedJS: [], | ||
sendFunction: 'console.log', | ||
}, | ||
}; | ||
|
||
const codeToFail = '$abs'; | ||
const codeToPass = '$abs[2000]'; | ||
const codeWithPositive = '$abs[200]'; | ||
const codeWithNegative = '$abs[-200]'; | ||
|
||
|
||
void describe('$abs', () => { | ||
void it('should not compile successfully without arg', () => { | ||
|
||
// expect this to throw an error | ||
assert.throws(() => { | ||
client.transpiler.transpile(codeToFail, transpilerOptions); | ||
}); | ||
}); | ||
|
||
void it('should compile successfully with arg', () => { | ||
const func = client.transpiler.transpile(codeToPass, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
|
||
void it('should return 200 for 200', async () => { | ||
// logs true | ||
const orignalLog = console.log; | ||
let logged: Record<string, string> = { content: 'hi' }; | ||
|
||
console.log = (log: Record<string, string>) => { | ||
logged = log; | ||
// orignalLog(log); | ||
}; | ||
|
||
const { func } = client.transpiler.transpile(codeWithPositive, transpilerOptions); | ||
|
||
// @ts-expect-error: func is a function | ||
await func?.(); | ||
|
||
console.log = orignalLog; | ||
|
||
assert.strictEqual(logged.content.toString(), '200'); | ||
}); | ||
|
||
void it('should return 200 for -200', async () => { | ||
// logs false | ||
const orignalLog = console.log; | ||
let logged: Record<string, string> = { content: 'hi' }; | ||
|
||
console.log = (log: Record<string, string>) => { | ||
logged = log; | ||
// orignalLog(log); | ||
}; | ||
|
||
const { func } = client.transpiler.transpile(codeWithNegative, transpilerOptions); | ||
|
||
// @ts-expect-error: func is a function | ||
await func?.(); | ||
|
||
console.log = orignalLog; | ||
|
||
assert.strictEqual(logged.content.toString(), -200); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
import TestClient from '@aoi.js/testing/testClient.js'; | ||
import { $math } from './$math.js'; | ||
|
||
const client = new TestClient(); | ||
client.transpiler.addFunctions({ $math }); | ||
|
||
const transpilerOptions = { | ||
scopeData: { | ||
name: 'global', | ||
vars: [], | ||
embeds: [], | ||
env: [], | ||
object: {}, | ||
embeddedJS: [], | ||
sendFunction: 'console.log', | ||
}, | ||
}; | ||
|
||
const codeToFail = '$math'; | ||
const codeToFailWithArg = '$math[hi+bye]'; | ||
const codeToPass = '$math[2000+1]'; | ||
const codewithBasicMath = '$math[2000/2+2-2*2]'; | ||
const codeWithAdvMath = '$math[pow(sin(90), 2) + pow(cos(90), 2)]'; | ||
|
||
|
||
void describe('$math', () => { | ||
void it('should not compile successfully without arg', () => { | ||
|
||
// expect this to throw an error | ||
assert.throws(() => { | ||
client.transpiler.transpile(codeToFail, transpilerOptions); | ||
}); | ||
}); | ||
|
||
void it('should not compile successfully with arg', () => { | ||
|
||
// expect this to throw an error | ||
assert.throws(() => { | ||
client.transpiler.transpile(codeToFailWithArg, transpilerOptions); | ||
}); | ||
}); | ||
|
||
void it('should compile successfully with arg', () => { | ||
const func = client.transpiler.transpile(codeToPass, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
|
||
void it('should return 998 for 2000/2+2-2*2', async () => { | ||
// logs true | ||
const orignalLog = console.log; | ||
let logged: Record<string, string> = { content: 'hi' }; | ||
|
||
console.log = (log: Record<string, string>) => { | ||
logged = log; | ||
// orignalLog(log); | ||
}; | ||
|
||
const { func } = client.transpiler.transpile(codewithBasicMath, transpilerOptions); | ||
|
||
// @ts-expect-error: func is a function | ||
await func?.(); | ||
|
||
console.log = orignalLog; | ||
|
||
assert.strictEqual(logged.content.toString(), '998'); | ||
}); | ||
|
||
void it('should return 1 for pow(sin(90), 2) + pow(cos(90), 2)', async () => { | ||
// logs false | ||
const orignalLog = console.log; | ||
let logged: Record<string, string> = { content: 'hi' }; | ||
|
||
console.log = (log: Record<string, string>) => { | ||
logged = log; | ||
// orignalLog(log); | ||
}; | ||
|
||
const { func } = client.transpiler.transpile(codeWithAdvMath, transpilerOptions); | ||
|
||
// @ts-expect-error: func is a function | ||
await func?.(); | ||
|
||
console.log = orignalLog; | ||
|
||
assert.strictEqual(logged.content.toString(), '1'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
import TestClient from '@aoi.js/testing/testClient.js'; | ||
import { $let } from './$let.js'; | ||
|
||
const client = new TestClient(); | ||
client.transpiler.addFunctions({ $let }); | ||
|
||
const transpilerOptions = { | ||
scopeData: { | ||
name: 'global', | ||
vars: [], | ||
embeds: [], | ||
env: [], | ||
object: {}, | ||
embeddedJS: [], | ||
sendFunction: 'console.log', | ||
}, | ||
}; | ||
|
||
const codeToFail = '$let'; | ||
const codeToFailWithArg = '$let[hi+bye]'; | ||
const codeToPass = '$let[hi;bye]'; | ||
|
||
|
||
void describe('$let', () => { | ||
void it('should not compile successfully without arg', () => { | ||
|
||
// expect this to throw an error | ||
assert.throws(() => { | ||
client.transpiler.transpile(codeToFail, transpilerOptions); | ||
}); | ||
}); | ||
|
||
void it('should not compile successfully with arg', () => { | ||
|
||
// expect this to throw an error | ||
assert.throws(() => { | ||
client.transpiler.transpile(codeToFailWithArg, transpilerOptions); | ||
}); | ||
}); | ||
|
||
void it('should compile successfully with arg', () => { | ||
const func = client.transpiler.transpile(codeToPass, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
import TestClient from '@aoi.js/testing/testClient.js'; | ||
import { $cpu } from './$cpu.js'; | ||
|
||
const client = new TestClient(); | ||
client.transpiler.addFunctions({ $cpu }); | ||
|
||
const transpilerOptions = { | ||
scopeData: { | ||
name: 'global', | ||
vars: [], | ||
embeds: [], | ||
env: [], | ||
object: {}, | ||
embeddedJS: [], | ||
sendFunction: 'console.log', | ||
}, | ||
}; | ||
|
||
const codeToPassWithoutArg = '$cpu'; | ||
const codeToFailWithArg = '$cpu[hi]'; | ||
const codeToPass = '$cpu[os]'; | ||
|
||
|
||
void describe('$cpu', () => { | ||
void it('should compile successfully without arg', () => { | ||
|
||
const func = client.transpiler.transpile(codeToPassWithoutArg, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
|
||
void it('should not compile successfully with arg', () => { | ||
|
||
// expect this to throw an error | ||
assert.throws(() => { | ||
client.transpiler.transpile(codeToFailWithArg, transpilerOptions); | ||
}); | ||
}); | ||
|
||
void it('should compile successfully with arg', () => { | ||
const func = client.transpiler.transpile(codeToPass, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
import TestClient from '@aoi.js/testing/testClient.js'; | ||
import { $cwd } from './$cwd.js'; | ||
|
||
const client = new TestClient(); | ||
client.transpiler.addFunctions({ $cwd }); | ||
|
||
const transpilerOptions = { | ||
scopeData: { | ||
name: 'global', | ||
vars: [], | ||
embeds: [], | ||
env: [], | ||
object: {}, | ||
embeddedJS: [], | ||
sendFunction: 'console.log', | ||
}, | ||
}; | ||
|
||
const codeToPassWithoutArg = '$cwd'; | ||
|
||
|
||
void describe('$cwd', () => { | ||
void it('should compile successfully without arg', () => { | ||
|
||
const func = client.transpiler.transpile(codeToPassWithoutArg, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
import TestClient from '@aoi.js/testing/testClient.js'; | ||
import { $procenv } from './$procenv.js'; | ||
|
||
const client = new TestClient(); | ||
client.transpiler.addFunctions({ $procenv }); | ||
|
||
const transpilerOptions = { | ||
scopeData: { | ||
name: 'global', | ||
vars: [], | ||
embeds: [], | ||
env: [], | ||
object: {}, | ||
embeddedJS: [], | ||
sendFunction: 'console.log', | ||
}, | ||
}; | ||
|
||
const codeToPassWithoutArg = '$procenv'; | ||
const codeToPassWithArg = '$procenv[hi]'; | ||
|
||
|
||
void describe('$procenv', () => { | ||
void it('should compile successfully without arg', () => { | ||
|
||
const func = client.transpiler.transpile(codeToPassWithoutArg, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
|
||
void it('should compile successfully with arg', () => { | ||
|
||
const func = client.transpiler.transpile(codeToPassWithArg, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { describe, it } from 'node:test'; | ||
import assert from 'node:assert'; | ||
|
||
import TestClient from '@aoi.js/testing/testClient.js'; | ||
import { $ram } from './$ram.js'; | ||
|
||
const client = new TestClient(); | ||
client.transpiler.addFunctions({ $ram }); | ||
|
||
const transpilerOptions = { | ||
scopeData: { | ||
name: 'global', | ||
vars: [], | ||
embeds: [], | ||
env: [], | ||
object: {}, | ||
embeddedJS: [], | ||
sendFunction: 'console.log', | ||
}, | ||
}; | ||
|
||
const codeToPassWithoutArg = '$ram'; | ||
const codeToFail = '$ram[hi]'; | ||
const codeWithParam = '$ram[rss]'; | ||
|
||
void describe('$ram', () => { | ||
void it('should compile successfully without arg', () => { | ||
|
||
const func = client.transpiler.transpile(codeToPassWithoutArg, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
|
||
void it('should not compile successfully with arg', () => { | ||
|
||
// expect this to throw an error | ||
assert.throws(() => { | ||
client.transpiler.transpile(codeToFail, transpilerOptions); | ||
}); | ||
}); | ||
|
||
void it('should compile successfully with arg', () => { | ||
const func = client.transpiler.transpile(codeWithParam, transpilerOptions); | ||
assert.ok(func); | ||
assert.strictEqual(typeof func.func, 'function'); | ||
}); | ||
}); |
Oops, something went wrong.