|
| 1 | +// |
| 2 | +// Note: This example test is leveraging the Mocha test framework. |
| 3 | +// Please refer to their documentation on https://mochajs.org/ for help. |
| 4 | +// |
| 5 | + |
| 6 | +// The module 'assert' provides assertion methods from node |
| 7 | +import * as assert from 'assert'; |
| 8 | +import * as fs from 'fs'; |
| 9 | +import { validVariableName, parseFunction, parseArgs } from '../src/lib/functions'; |
| 10 | + |
| 11 | +suite("function helper test", () => { |
| 12 | + |
| 13 | + test("validVariableName does not allow variables starting with number", () => { |
| 14 | + assert.equal(false, validVariableName("1as")); |
| 15 | + }); |
| 16 | + test("validVariableName returns true with correct variable", () => { |
| 17 | + assert.equal(true, validVariableName("matA")); |
| 18 | + }); |
| 19 | + test("validVariableName returns true for variables starting with uppercase", () => { |
| 20 | + assert.equal(true, validVariableName("MatA")); |
| 21 | + }); |
| 22 | + test("validVariableName return true for variable starting with _", () => { |
| 23 | + assert.equal(true, validVariableName("_matA")); |
| 24 | + }); |
| 25 | + test("parseFuntion return undefined on empty line", () => { |
| 26 | + assert.equal(undefined, parseFunction("")); |
| 27 | + }); |
| 28 | + test("parseFuntion return undefined if function keyword is missing", () => { |
| 29 | + assert.equal(undefined, parseFunction("hello")); |
| 30 | + }); |
| 31 | + test("parseFuntion return correct function name", () => { |
| 32 | + assert.equal("hello", parseFunction("function hello()").name); |
| 33 | + }); |
| 34 | + |
| 35 | + test("parseFuntion return correct number of args", () => { |
| 36 | + assert.equal(2, parseFunction("function hello( a, b)").args.length); |
| 37 | + }); |
| 38 | + test("parseArgs return the correct number of args", () => { |
| 39 | + assert.equal(2, parseArgs("a,b").length); |
| 40 | + }) |
| 41 | + test("parseArgs handle spaces well", () => { |
| 42 | + assert.equal(2, parseArgs(" a, b").length); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
| 46 | + |
0 commit comments