@@ -67,9 +67,19 @@ test_that("label supports glue syntax for {.seg_val} {.seg_col} {.step} {.col}",
67
67
test_that(" glue scope doesn't expose internal variables" , {
68
68
69
69
# Ex: should not be able to access `columns` local variable in `col_vals_lt()`
70
- expect_error(create_agent(small_table ) %> % col_vals_lt(c , 8 , label = " {columns}" ))
70
+ expect_identical(
71
+ create_agent(small_table ) %> %
72
+ col_vals_lt(c , 8 , label = " {columns}" ) %> %
73
+ {. $ validation_set $ label },
74
+ " {columns}"
75
+ )
71
76
# Ex: should not be able to access `i` local variable in `create_validation_step()`
72
- expect_error(create_agent(small_table ) %> % col_vals_lt(c , 8 , label = " {i}" ))
77
+ expect_identical(
78
+ create_agent(small_table ) %> %
79
+ col_vals_lt(c , 8 , label = " {i}" ) %> %
80
+ {. $ validation_set $ label },
81
+ " {i}"
82
+ )
73
83
74
84
# Should be able to access global vars/fns
75
85
expect_equal(
@@ -83,23 +93,23 @@ test_that("glue scope doesn't expose internal variables", {
83
93
84
94
test_that(" glue env searches from the caller env of the validation function" , {
85
95
86
- to_upper <- function (x ) stop( " Oh no! " )
96
+ to_upper <- function (x ) " global "
87
97
88
- expect_error (
98
+ expect_identical (
89
99
create_agent(small_table ) %> %
90
100
col_vals_lt(c , 8 , label = " {to_upper(.col)}" ) %> %
91
101
{. $ validation_set $ label },
92
- " Oh no! "
102
+ " global "
93
103
)
94
104
95
- expect_equal (
105
+ expect_identical (
96
106
local({
97
- to_upper <- function (x ) toupper( x )
107
+ to_upper <- function (x ) " local "
98
108
create_agent(small_table ) %> %
99
109
col_vals_lt(c , 8 , label = " {to_upper(.col)}" ) %> %
100
110
{. $ validation_set $ label }
101
111
}),
102
- " C "
112
+ " local "
103
113
)
104
114
105
115
})
@@ -281,3 +291,18 @@ test_that("glue works for brief too", {
281
291
)
282
292
283
293
})
294
+
295
+ test_that(" safe fallback when glue fails (#598)" , {
296
+
297
+ expect_no_error({
298
+ agent <- create_agent(small_table ) %> %
299
+ col_vals_regex(b , " ^\\ d{1,2}" ) %> %
300
+ interrogate()
301
+ })
302
+
303
+ expect_identical(
304
+ agent $ validation_set $ brief ,
305
+ generate_autobriefs(agent , " b" , NULL , " ^\\ d{1,2}" , " col_vals_regex" ),
306
+ )
307
+
308
+ })
0 commit comments