deno.land / x / linq@4.0.2 / test / convert.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { test, testModule, deepEqual, equal, ok } from './testutils.js'import Enumerable from '../linq.js'
testModule("Convert");
test("toArray", function (){ let actual = Enumerable.range(1, 10).toArray(); deepEqual(actual, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);});
test("toLookup", function (){ var fileList = ["temp.xls", "temp2.xls", "temp.pdf", "temp.jpg", "temp2.pdf"]; let actual = Enumerable.from(fileList).toLookup("file=>file.match(/\\.(.+$)/)[1]");
deepEqual(["temp.xls", "temp2.xls"], actual.get("xls").toArray()); deepEqual(["temp.pdf", "temp2.pdf"], actual.get("pdf").toArray()); deepEqual(["temp.jpg"], actual.get("jpg").toArray()); equal(3, actual.count()); ok(actual.contains("xls")); ok(!actual.contains("XLS")); var array = actual.toEnumerable().toArray(); equal("xls", array[0].key()); deepEqual(["temp.xls", "temp2.xls"], array[0].toArray());
actual = Enumerable.from(fileList).toLookup("file=>file.match(/\\.(.+$)/)[1]", "file=>file +'ele'"); deepEqual(["temp.xlsele", "temp2.xlsele"], actual.get("xls").toArray()); deepEqual(["temp.pdfele", "temp2.pdfele"], actual.get("pdf").toArray()); deepEqual(["temp.jpgele"], actual.get("jpg").toArray());
fileList = ["temp.xls", "temp2.XLS", "temp.pdf", "temp.jpg", "temp2.pDf"]; actual = Enumerable.from(fileList).toLookup("file=>file.match(/\\.(.+$)/)[1]", "file=>file +'ele'", function (s) { return s.toLowerCase() }); deepEqual(actual.get("xLS").toArray(), ["temp.xlsele", "temp2.XLSele"]); deepEqual(actual.get("PDf").toArray(), ["temp.pdfele", "temp2.pDfele"]); deepEqual(actual.get("Jpg").toArray(), ["temp.jpgele"]); ok(actual.contains("xls")); ok(actual.contains("XLS"));});
test("toObject", function (){ let actual = Enumerable.range(1, 3).toObject("i=>'foo'+i", "i=>i*4"); deepEqual(actual, { foo1: 4, foo2: 8, foo3: 12 });});

test("toDictionary", function (){ let actual = Enumerable.range(1, 3).toDictionary("i=>'foo'+i", "i=>i*4"); equal(4, actual.get("foo1")); equal(8, actual.get("foo2")); equal(12, actual.get("foo3"));
actual = Enumerable.range(1, 3).toDictionary("i=>{key:i,V:'foo'+i}", "i=>i*4", "$.key"); equal(4, actual.get({ key: 1 })); equal(8, actual.get({ key: 2 })); equal(12, actual.get({ key: 3 }));});
test("toJoinedString", function (){ let actual = Enumerable.range(1, 3).toJoinedString(); equal(actual, "123");
actual = Enumerable.range(1, 3).toJoinedString("-"); equal(actual, "1-2-3");
actual = Enumerable.range(1, 3).toJoinedString("-", "i=>i*2"); equal(actual, "2-4-6");});
test("toJSONString", function (){ let actual = Enumerable.from([{ a: 1, b: true }, { a: null, b: "aaa"}]).toJSONString(); equal(actual, '[{"a":1,"b":true},{"a":null,"b":"aaa"}]');
actual = Enumerable.range(1, 5).toJSONString(); equal(actual, '[1,2,3,4,5]');
actual = Enumerable.from(["a", "b", "c"]) .toJSONString(function (key, value) { if (typeof value === 'object') return value; return value.toString().toUpperCase(); }); equal(actual, '["A","B","C"]');
actual = Enumerable.from([1, 2, 3, 4, 5]) .toJSONString(function (key, value) { return value; }, 1); ok(actual.indexOf("\n") != -1);});
linq

Version Info

Tagged at
7 months ago