Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix printing of strings inside functions #4458

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/function.gi
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ function(fun)
local s, stream;
s := "";
stream := OutputTextString(s, true);
fingolfin marked this conversation as resolved.
Show resolved Hide resolved
SetPrintFormattingStatus(stream, false);
PrintTo(stream, fun);
CloseStream(stream);
NormalizeWhitespace(s);
return MakeImmutable(s);
return ReplacedString(s, "\n", " ");
end);

BIND_GLOBAL( "VIEW_STRING_OPERATION",
Expand Down
30 changes: 29 additions & 1 deletion tst/testinstall/function.tst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#@local f,g,h,l,mh,r,x,makeCounter,funcloop
#@local f,g,h,l,mh,r,x,makeCounter,funcloop,funcstr
gap> START_TEST("function.tst");
gap> IsKernelFunction(IsKernelFunction);
true
Expand Down Expand Up @@ -137,6 +137,34 @@ gap> Print({x,y} -> x + y, "\n");
function ( x, y )
return x + y;
end
gap> String({x,y} -> x + y);
"function ( x, y ) return x + y; end"

# Test nesting
gap> Print(function(x) if x then if x then while x do od; fi; fi; end, "\n");
function ( x )
if x then
if x then
while x do
;
od;
fi;
fi;
return;
end
gap> String(function(x) if x then if x then while x do od; fi; fi; end);
"function ( x ) if x then if x then while x do ; od; fi; fi; return; end"

# Check strings in functions
gap> Print({x} -> "a b","\n");
function ( x )
return "a b";
end
gap> String({x} -> "a b");
"function ( x ) return \"a b\"; end"
gap> funcstr := Concatenation("function ( x ) return \"a", ListWithIdenticalEntries(1000, ' '),"b\"; end");;
gap> String(EvalString(funcstr)) = funcstr;
true
gap> f := ({x,y} -> x + y);
function( x, y ) ... end
gap> f(2,3);
Expand Down