1 /** 2 Only exists to test the wrapping functionality Contains functions 3 with regular D types that will get wrapped so they can be called by 4 the spreadsheet. 5 */ 6 7 module xlld.test_d_funcs; 8 9 version(unittest): 10 11 12 import xlld.worksheet; 13 14 @Register(ArgumentText("Array to add"), 15 HelpTopic("Adds all cells in an array"), 16 FunctionHelp("Adds all cells in an array"), 17 ArgumentHelp(["The array to add"])) 18 double FuncAddEverything(double[][] args) nothrow @nogc { 19 import std.algorithm: fold; 20 import std.math: isNaN; 21 22 double ret = 0; 23 foreach(row; args) 24 ret += row.fold!((a, b) => b.isNaN ? 0.0 : a + b)(0.0); 25 return ret; 26 } 27 28 double[][] FuncTripleEverything(double[][] args) nothrow { 29 double[][] ret; 30 ret.length = args.length; 31 foreach(i; 0 .. args.length) { 32 ret[i].length = args[i].length; 33 foreach(j; 0 .. args[i].length) 34 ret[i][j] = args[i][j] * 3; 35 } 36 37 return ret; 38 } 39 40 double FuncAllLengths(string[][] args) nothrow @nogc { 41 import std.algorithm: fold; 42 43 double ret = 0; 44 foreach(row; args) 45 ret += row.fold!((a, b) => a + b.length)(0.0); 46 return ret; 47 } 48 49 double[][] FuncLengths(string[][] args) nothrow { 50 double[][] ret; 51 52 ret.length = args.length; 53 foreach(i; 0 .. args.length) { 54 ret[i].length = args[i].length; 55 foreach(j; 0 .. args[i].length) 56 ret[i][j] = args[i][j].length; 57 } 58 59 return ret; 60 } 61 62 63 string[][] FuncBob(string[][] args) nothrow { 64 string[][] ret; 65 66 ret.length = args.length; 67 foreach(i; 0 .. args.length) { 68 ret[i].length = args[i].length; 69 foreach(j; 0 .. args[i].length) 70 ret[i][j] = args[i][j] ~ "bob"; 71 } 72 73 return ret; 74 } 75 76 77 double FuncDoubleSlice(double[] arg) nothrow @nogc { 78 return arg.length; 79 } 80 81 double FuncStringSlice(string[] arg) nothrow @nogc { 82 return arg.length; 83 } 84 85 double[] FuncSliceTimes3(double[] arg) nothrow { 86 import std.algorithm; 87 import std.array; 88 return arg.map!(a => a * 3).array; 89 } 90 91 string[] StringsToStrings(string[] args) nothrow { 92 import std.algorithm; 93 import std.array; 94 return args.map!(a => a ~ "foo").array; 95 } 96 97 string StringsToString(string[] args) nothrow { 98 import std.string; 99 return args.join(", "); 100 } 101 102 string StringToString(string arg) nothrow { 103 return arg ~ "bar"; 104 } 105 106 private string shouldNotBeAProblem(string, string[]) nothrow { 107 return ""; 108 } 109 110 string ManyToString(string arg0, string arg1, string arg2) nothrow { 111 return arg0 ~ arg1 ~ arg2; 112 } 113 114 double FuncThrows(double) { 115 throw new Exception("oops"); 116 }