@@ -5,71 +5,81 @@ using Test
5
5
vecnames = [:a , :b , :c , :d , :e , :f ]
6
6
tupnames = (:a , :b , :c , :d , :e , :f )
7
7
8
- # vector of integers
8
+ # index selector: vector of integers
9
9
selector = CS. selector ([1 , 3 , 5 ])
10
+ @test selector isa CS. IndexSelector
10
11
snames = selector (vecnames)
11
12
@test snames == [:a , :c , :e ]
12
13
snames = selector (tupnames)
13
14
@test snames == [:a , :c , :e ]
14
15
15
- # tuple of integers
16
+ # index selector: tuple of integers
16
17
selector = CS. selector ((1 , 3 , 5 ))
18
+ @test selector isa CS. IndexSelector
17
19
snames = selector (vecnames)
18
20
@test snames == [:a , :c , :e ]
19
21
snames = selector (tupnames)
20
22
@test snames == [:a , :c , :e ]
21
23
22
- # vector of symbols
24
+ # name selector: vector of symbols
23
25
selector = CS. selector ([:a , :c , :e ])
26
+ @test selector isa CS. NameSelector
24
27
snames = selector (vecnames)
25
28
@test snames == [:a , :c , :e ]
26
29
snames = selector (tupnames)
27
30
@test snames == [:a , :c , :e ]
28
31
29
- # tuple of symbols
32
+ # name selector: tuple of symbols
30
33
selector = CS. selector ((:a , :c , :e ))
34
+ @test selector isa CS. NameSelector
31
35
snames = selector (vecnames)
32
36
@test snames == [:a , :c , :e ]
33
37
snames = selector (tupnames)
34
38
@test snames == [:a , :c , :e ]
35
39
36
- # vector of strings
40
+ # name selector: vector of strings
37
41
selector = CS. selector ([" a" , " c" , " e" ])
42
+ @test selector isa CS. NameSelector
38
43
snames = selector (vecnames)
39
44
@test snames == [:a , :c , :e ]
40
45
snames = selector (tupnames)
41
46
@test snames == [:a , :c , :e ]
42
47
43
- # tuple of strings
48
+ # name selector: tuple of strings
44
49
selector = CS. selector ((" a" , " c" , " e" ))
50
+ @test selector isa CS. NameSelector
45
51
snames = selector (vecnames)
46
52
@test snames == [:a , :c , :e ]
47
53
snames = selector (tupnames)
48
54
@test snames == [:a , :c , :e ]
49
55
50
- # regex
56
+ # regex selector: regex
51
57
selector = CS. selector (r" [ace]" )
58
+ @test selector isa CS. RegexSelector
52
59
snames = selector (vecnames)
53
60
@test snames == [:a , :c , :e ]
54
61
snames = selector (tupnames)
55
62
@test snames == [:a , :c , :e ]
56
63
57
- # colon
64
+ # all selector: colon
58
65
selector = CS. selector (:)
66
+ @test selector isa CS. AllSelector
59
67
snames = selector (vecnames)
60
68
@test snames == [:a , :b , :c , :d , :e , :f ]
61
69
snames = selector (tupnames)
62
70
@test snames == [:a , :b , :c , :d , :e , :f ]
63
71
64
- # nothing
72
+ # none selector: nothing
65
73
selector = CS. selector (nothing )
74
+ @test selector isa CS. NoneSelector
66
75
snames = selector (vecnames)
67
76
@test snames == Symbol[]
68
77
snames = selector (tupnames)
69
78
@test snames == Symbol[]
70
79
71
- # single integer
80
+ # single index selector: integer
72
81
selector = CS. selector (1 )
82
+ @test selector isa CS. SingleIndexSelector
73
83
sname = CS. selectsingle (selector, vecnames)
74
84
snames = CS. select (selector, vecnames)
75
85
@test sname == :a
@@ -79,8 +89,9 @@ using Test
79
89
@test sname == :a
80
90
@test snames == [:a ]
81
91
82
- # single symbol
92
+ # single name selector: symbol
83
93
selector = CS. selector (:b )
94
+ @test selector isa CS. SingleNameSelector
84
95
sname = CS. selectsingle (selector, vecnames)
85
96
snames = CS. select (selector, vecnames)
86
97
@test sname == :b
@@ -90,8 +101,9 @@ using Test
90
101
@test sname == :b
91
102
@test snames == [:b ]
92
103
93
- # single string
104
+ # single name selector: string
94
105
selector = CS. selector (" c" )
106
+ @test selector isa CS. SingleNameSelector
95
107
sname = CS. selectsingle (selector, vecnames)
96
108
snames = CS. select (selector, vecnames)
97
109
@test sname == :c
@@ -101,13 +113,23 @@ using Test
101
113
@test sname == :c
102
114
@test snames == [:c ]
103
115
116
+ # fallback: another selector
117
+ selector = CS. selector (CS. NoneSelector ())
118
+ @test selector isa CS. NoneSelector
119
+
104
120
# shows
105
121
selector = CS. selector ([1 , 2 , 3 ])
106
122
@test sprint (show, selector) == " [1, 2, 3]"
123
+ selector = CS. selector ((1 , 2 , 3 ))
124
+ @test sprint (show, selector) == " [1, 2, 3]"
125
+ selector = CS. selector ([:a , :b , :c ])
126
+ @test sprint (show, selector) == " [:a, :b, :c]"
107
127
selector = CS. selector ((:a , :b , :c ))
108
128
@test sprint (show, selector) == " [:a, :b, :c]"
109
129
selector = CS. selector ([" a" , " b" , " c" ])
110
130
@test sprint (show, selector) == " [:a, :b, :c]"
131
+ selector = CS. selector ((" a" , " b" , " c" ))
132
+ @test sprint (show, selector) == " [:a, :b, :c]"
111
133
selector = CS. selector (r" [abc]" )
112
134
@test sprint (show, selector) == " r\" [abc]\" "
113
135
selector = CS. selector (:)
@@ -129,6 +151,14 @@ using Test
129
151
@test_throws ArgumentError CS. selector (Int[])
130
152
@test_throws ArgumentError CS. selector (Symbol[])
131
153
@test_throws ArgumentError CS. selector (String[])
154
+ # column indices must be unique
155
+ @test_throws ArgumentError CS. selector ([1 , 2 , 2 ])
156
+ @test_throws ArgumentError CS. selector ((1 , 2 , 2 ))
157
+ # column names must be unique
158
+ @test_throws ArgumentError CS. selector ([:a , :b , :b ])
159
+ @test_throws ArgumentError CS. selector ((:a , :b , :b ))
160
+ @test_throws ArgumentError CS. selector ([" a" , " b" , " b" ])
161
+ @test_throws ArgumentError CS. selector ((" a" , " b" , " b" ))
132
162
# regex doesn't match any names in input table
133
163
selector = CS. selector (r" x" )
134
164
@test_throws AssertionError CS. select (selector, vecnames)
0 commit comments