forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRangeOperator.Tests.ps1
More file actions
97 lines (87 loc) · 3.35 KB
/
Copy pathRangeOperator.Tests.ps1
File metadata and controls
97 lines (87 loc) · 3.35 KB
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
95
96
97
Describe "Range Operator" -Tags CI {
Context "Range integer operations" {
It "Range operator generates arrays of integers" {
$Range = 5..8
$Range.count | Should Be 4
$Range[0] | Should BeOfType [int]
$Range[1] | Should BeOfType [int]
$Range[2] | Should BeOfType [int]
$Range[3] | Should BeOfType [int]
$Range[0] | Should Be 5
$Range[1] | Should Be 6
$Range[2] | Should Be 7
$Range[3] | Should Be 8
}
It "Range operator accepts negative integer values" {
$Range = -8..-5
$Range.count | Should Be 4
$Range[0] | Should Be -8
$Range[1] | Should Be -7
$Range[2] | Should Be -6
$Range[3] | Should Be -5
}
It "Range operator support single-item sequences" {
$Range = 0..0
$Range.count | Should Be 1
$Range[0] | Should BeOfType [int]
$Range[0] | Should Be 0
}
It "Range operator works in descending order" {
$Range = 4..3
$Range.count | Should Be 2
$Range[0] | Should Be 4
$Range[1] | Should Be 3
}
It "Range operator works for sequences of both negative and positive numbers" {
$Range = -2..2
$Range.count | Should Be 5
$Range[0] | Should Be -2
$Range[1] | Should Be -1
$Range[2] | Should Be 0
$Range[3] | Should Be 1
$Range[4] | Should Be 2
}
}
Context "Character expansion" {
It "Range operator generates an array of [char] from single-character string operands" {
$CharRange = 'A'..'E'
$CharRange.count | Should Be 5
$CharRange[0] | Should BeOfType [char]
$CharRange[1] | Should BeOfType [char]
$CharRange[2] | Should BeOfType [char]
$CharRange[3] | Should BeOfType [char]
$CharRange[4] | Should BeOfType [char]
}
It "Range operator works in ascending and descending order" {
$CharRange = 'a'..'b'
$CharRange.count | Should Be 2
$CharRange[0] | Should Be ([char]'a')
$CharRange[1] | Should Be ([char]'b')
$CharRange = 'b'..'a'
$CharRange.count | Should Be 2
$CharRange[0] | Should Be ([char]'b')
$CharRange[1] | Should Be ([char]'a')
}
It "Range operator works with 16-bit unicode characters" {
$UnicodeRange = "`u{0110}".."`u{0114}"
$UnicodeRange.count | Should Be 5
$UnicodeRange[0] | Should Be "`u{0110}"[0]
$UnicodeRange[1] | Should Be "`u{0111}"[0]
$UnicodeRange[2] | Should Be "`u{0112}"[0]
$UnicodeRange[3] | Should Be "`u{0113}"[0]
$UnicodeRange[4] | Should Be "`u{0114}"[0]
$UnicodeRange.Where({$_ -is [char]}).count | Should Be 5
}
}
Context "Range operator operand types" {
It "Range operator works on [decimal]" {
$Range = 1.1d..3.9d
$Range.count | Should Be 4
$Range[0] | Should Be 1
$Range[1] | Should Be 2
$Range[2] | Should Be 3
$Range[3] | Should Be 4
$Range.Where({$_ -is [int]}).count | Should Be 4
}
}
}