-
Notifications
You must be signed in to change notification settings - Fork 18
/
Last.ts
65 lines (51 loc) · 2.07 KB
/
Last.ts
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
import { InvalidOperationException } from "linq-to-typescript"
import { asAsync, expectAsync, itAsync, itEnumerable, itParallel } from "../TestHelpers"
describe("last", () => {
it("String", () => {
expect("abc".last()).toEqual("c")
})
it("String Empty", () => {
expect(() => "".last()).toThrow(InvalidOperationException)
})
itEnumerable("Last", (asEnumerable) => {
expect(asEnumerable([1, 2]).last()).toBe(2)
})
itAsync("Last", async () => {
expect(await asAsync([1, 2]).last()).toBe(2)
})
itParallel("Last", async (asParallel) => {
expect(await asParallel([1, 2]).last()).toBe(2)
})
itEnumerable("LastEmpty", (asEnumerable) => {
expect(() => asEnumerable([]).last()).toThrowError(InvalidOperationException)
})
itAsync("LastEmpty", async () => {
const expect = await expectAsync(asAsync([]).last())
expect.toThrowError(InvalidOperationException)
})
itParallel("LastEmpty", async (asParallel) => {
const expect = await expectAsync(asParallel([]).last())
expect.toThrowError(InvalidOperationException)
})
itEnumerable("LastPredicate", (asEnumerable) => {
expect(asEnumerable([1, 2]).last((x) => x === 1)).toBe(1)
})
itAsync("LastPredicate", async () => {
expect(await asAsync([1, 2]).last((x) => x === 1)).toBe(1)
})
itParallel("LastPredicate", async (asParallel) => {
expect(await asParallel([1, 2]).last((x) => x === 1)).toBe(1)
})
itEnumerable("Last Empty With Predicate", (asEnumerable) => {
expect(() => asEnumerable([]).last((x) => x > 2))
.toThrowError(InvalidOperationException)
})
itAsync("Last Empty With Predicate", async () => {
const expect = await expectAsync(asAsync([]).last((x) => x > 2))
expect.toThrowError(InvalidOperationException)
})
itParallel("Last Empty With Predicate", async (asParallel) => {
const expect = await expectAsync(asParallel([]).last((x) => x > 2))
expect.toThrowError(InvalidOperationException)
})
})