@@ -117,29 +117,73 @@ expect_match_ <- function(
117117 return (pass(act $ val ))
118118 }
119119
120- text <- encodeString(act $ val )
121120 if (length(act $ val ) == 1 ) {
122- values <- paste0(title , ' : "' , text , ' "' )
123121 which <- " "
124122 } else {
125- bullet <- ifelse(
126- condition ,
127- cli :: col_green(cli :: symbol $ tick ),
128- cli :: col_red(cli :: symbol $ cross )
129- )
130- values <- paste0(title , " :\n " , paste0(bullet , " " , text , collapse = " \n " ))
131123 which <- if (all ) " Every element of " else " Some element of "
132124 }
133125 match <- if (negate ) " matches" else " does not match"
134126
135127 msg <- sprintf(
136- " %s%s %s %s %s.\n %s" ,
128+ " %s%s %s %s %s.\n %s: \n %s " ,
137129 which ,
138130 act $ lab ,
139131 match ,
140132 if (fixed ) " string" else " regexp" ,
141133 encodeString(regexp , quote = ' "' ),
142- values
134+ title ,
135+ paste0(show_text(act $ val , condition ), collapse = " \n " )
143136 )
144137 return (fail(msg , info = info , trace_env = trace_env ))
145138}
139+
140+
141+ # Adapted from print.ellmer_prompt
142+ show_text <- function (
143+ x ,
144+ condition ,
145+ ... ,
146+ max_items = 20 ,
147+ max_lines = max_items * 25
148+ ) {
149+ n <- length(x )
150+ n_extra <- length(x ) - max_items
151+ if (n_extra > 0 ) {
152+ x <- x [seq_len(max_items )]
153+ condition <- condition [seq_len(max_items )]
154+ }
155+
156+ if (length(x ) == 0 ) {
157+ return (character ())
158+ }
159+
160+ bar <- if (cli :: is_utf8_output()) " \u 2502" else " |"
161+
162+ id <- ifelse(
163+ condition ,
164+ cli :: col_green(cli :: symbol $ tick ),
165+ cli :: col_red(cli :: symbol $ cross )
166+ )
167+
168+ indent <- paste0(id , " " , bar , " " )
169+ exdent <- paste0(" " , cli :: col_grey(bar ), " " )
170+
171+ x [is.na(x )] <- cli :: col_red(" <NA>" )
172+ x <- paste0(indent , x )
173+ x <- gsub(" \n " , paste0(" \n " , exdent ), x )
174+
175+ lines <- strsplit(x , " \n " )
176+ ids <- rep(seq_along(x ), length(lines ))
177+ lines <- unlist(lines )
178+
179+ if (length(lines ) > max_lines ) {
180+ lines <- lines [seq_len(max_lines )]
181+ lines <- c(lines , paste0(exdent , " ..." ))
182+ n_extra <- n - ids [max_lines - 1 ]
183+ }
184+
185+ if (n_extra > 0 ) {
186+ lines <- c(lines , paste0(" ... and " , n_extra , " more.\n " ))
187+ }
188+ lines
189+ }
0 commit comments