commit
message
Formulas.CHAR written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-01 23:42:15
stats
2 file(s) changed,
34 insertions(+),
0 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
2index 334d3a6..bb630b5 100644
3--- a/src/RawFormulas/RawFormulas.ts
4+++ b/src/RawFormulas/RawFormulas.ts
5@@ -57,7 +57,19 @@ var DECIMAL = Formula["DECIMAL"];
6 var CEILING = Formula["CEILING"];
7 var CEILINGMATH = Formula["CEILINGMATH"];
8 var CEILINGPRECISE = Formula["CEILINGPRECISE"];
9-var CHAR = Formula["CHAR"];
10+
11+
12+/**
13+ * Convert a number into a character according to the current Unicode table.
14+ * @param values[0] The number of the character to look up from the current Unicode table in decimal format.
15+ * @returns {string} character corresponding to Unicode number
16+ * @constructor
17+ */
18+var CHAR = function (...values) : string {
19+ checkArgumentsLength(values, 1);
20+ var n = firstValueAsNumber(values[0]);
21+ return String.fromCharCode(n);
22+};
23
24 /**
25 * Returns the numeric Unicode map value of the first character in the string provided.
26diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
27index 70db752..2d1662b 100644
28--- a/tests/FormulasTest.ts
29+++ b/tests/FormulasTest.ts
30@@ -294,7 +294,27 @@ assertEquals(CEILINGMATH(1001.112131), 1002);
31
32 assertEquals(CEILINGPRECISE(1001.112131), 1002);
33
34+
35+// Test CHAR
36 assertEquals(CHAR(97), "a");
37+assertEquals(CHAR("97"), "a");
38+assertEquals(CHAR([97, "m"]), "a");
39+assertEquals(CHAR([[97], "m"]), "a");
40+catchAndAssertEquals(function() {
41+ CHAR([[], [97], "m"]);
42+}, ERRORS.REF_ERROR);
43+catchAndAssertEquals(function() {
44+ CHAR(false);
45+}, ERRORS.NUM_ERROR);
46+catchAndAssertEquals(function() {
47+ CHAR(10000000);
48+}, ERRORS.NUM_ERROR);
49+catchAndAssertEquals(function() {
50+ CHAR(0);
51+}, ERRORS.NUM_ERROR);
52+catchAndAssertEquals(function() {
53+ CHAR();
54+}, ERRORS.NA_ERROR);
55
56
57 // Test CODE