@@ -4,6 +4,23 @@ filter_args <- function(x) {
4
4
x [all_names ]
5
5
}
6
6
7
+ find_partial_match_pairs <- function (args ) {
8
+ if (length(args ) < 2 ) {
9
+ return (NULL )
10
+ }
11
+ combinations <- combn(args , 2L )
12
+ contains <- startsWith(combinations [1 , ], combinations [2 , ]) |
13
+ startsWith(combinations [2 , ], combinations [1 , ])
14
+
15
+ if (! any(contains )) {
16
+ return (NULL )
17
+ }
18
+
19
+ problem <- combinations [, contains , drop = FALSE ]
20
+ paste0(" `" , problem [1 , ], " ` with `" , problem [2 , ], " `" )
21
+ }
22
+
23
+
7
24
test_that(" geom_xxx and GeomXxx$draw arg defaults match" , {
8
25
ggplot2_ns <- asNamespace(" ggplot2" )
9
26
objs <- ls(ggplot2_ns )
@@ -73,3 +90,53 @@ test_that("stat_xxx and StatXxx$compute_panel arg defaults match", {
73
90
)
74
91
})
75
92
})
93
+
94
+ # If the following tests fail, you may have introduced a potential partial match
95
+ # in argument names. The code should be double checked that is doesn't
96
+ # accidentally use `list$arg` when `list$arg_name` also exists. If that doesn't
97
+ # occur, the snapshot can be updated.
98
+
99
+ test_that(" GeomXxx$parameters() does not contain partial matches" , {
100
+ ggplot2_ns <- asNamespace(" ggplot2" )
101
+ objs <- ls(ggplot2_ns )
102
+ geom_class_names <- grep(" ^Geom" , objs , value = TRUE )
103
+ geom_class_names <- setdiff(geom_class_names , c(" Geom" ))
104
+
105
+ problems <- list ()
106
+
107
+ for (geom_class_name in geom_class_names ) {
108
+ geom_obj <- ggplot2_ns [[geom_class_name ]]
109
+ params <- geom_obj $ parameters()
110
+ issues <- find_partial_match_pairs(params )
111
+ if (length(issues ) == 0 ) {
112
+ next
113
+ }
114
+ problems [[geom_class_name ]] <- issues
115
+ }
116
+
117
+ problems <- vapply(problems , paste0 , character (1 ), collapse = " , " )
118
+ problems <- paste0(format(names(problems )), " : " , problems )
119
+ expect_snapshot(problems )
120
+ })
121
+
122
+ test_that(" StatXxx$parameters() does not contain partial matches" , {
123
+ ggplot2_ns <- asNamespace(" ggplot2" )
124
+ objs <- ls(ggplot2_ns )
125
+ stat_class_names <- grep(" ^Stat" , objs , value = TRUE )
126
+ stat_class_names <- setdiff(stat_class_names , c(" Stat" ))
127
+
128
+ problems <- list ()
129
+
130
+ for (stat_class_name in stat_class_names ) {
131
+ stat_obj <- ggplot2_ns [[stat_class_name ]]
132
+ params <- stat_obj $ parameters()
133
+ issues <- find_partial_match_pairs(params )
134
+ if (length(issues ) == 0 ) {
135
+ next
136
+ }
137
+ problems [[stat_class_name ]] <- issues
138
+ }
139
+ problems <- vapply(problems , paste0 , character (1 ), collapse = " , " )
140
+ problems <- paste0(format(names(problems )), " : " , problems )
141
+ expect_snapshot(problems )
142
+ })
0 commit comments