Skip to content
This repository was archived by the owner on Jan 18, 2025. It is now read-only.

Commit 2c5d97d

Browse files
c42fJeffBezanson
authored andcommitted
var"ident" syntax for non-standard identifiers (JuliaLang/julia#32408)
Allow identifiers like Symbol("#example#") to be represented in julia code with the syntax `var"#example#"`. This needed support in the parser rather than being a string macro so that it could be used in any context where a normal identifier is allowed. Show nonstandard identifiers in Exprs with var"ident" syntax
1 parent acc653c commit 2c5d97d

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/Test.jl

+5-12
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate
236236
evaled_args = evaluated.args
237237
quoted_args = quoted.args
238238
n = length(evaled_args)
239+
kw_suffix = ""
239240
if evaluated.head == :comparison
240241
args = evaled_args
241242
while i < n
@@ -260,17 +261,9 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate
260261
func_sym = quoted_args[1]
261262
if isempty(kwargs)
262263
quoted = Expr(:call, func_sym, args...)
263-
elseif func_sym === :
264-
# in case of `≈(x, y, atol = z)`
265-
# make the display like `Evaluated: x ≈ y (atol=z)`
266-
kws = [Symbol(Expr(:kw, k, v), ",") for (k, v) in kwargs]
267-
kws[end] = Symbol(Expr(:kw, kwargs[end]...))
268-
kws[1] = Symbol("(", kws[1])
269-
kws[end] = Symbol(kws[end], ")")
270-
quoted = Expr(:comparison, args[1], func_sym, args[2], kws...)
271-
if length(quoted.args) & 1 == 0 # hack to fit `show_unquoted`
272-
push!(quoted.args, Symbol())
273-
end
264+
elseif func_sym === : && !res
265+
quoted = Expr(:call, func_sym, args...)
266+
kw_suffix = " ($(join(["$k=$v" for (k, v) in kwargs], ", ")))"
274267
else
275268
kwargs_expr = Expr(:parameters, [Expr(:kw, k, v) for (k, v) in kwargs]...)
276269
quoted = Expr(:call, func_sym, kwargs_expr, args...)
@@ -286,7 +279,7 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate
286279

287280
Returned(res,
288281
# stringify arguments in case of failure, for easy remote printing
289-
res ? quoted : sprint(io->print(IOContext(io, :limit => true), quoted)),
282+
res ? quoted : sprint(io->print(IOContext(io, :limit => true), quoted))*kw_suffix,
290283
source)
291284
end
292285

0 commit comments

Comments
 (0)