Skip to content

Commit

Permalink
Fix printing of strings inside functions
Browse files Browse the repository at this point in the history
Previously we normalised all whitespace in printed out functions,
which would effect whitespace inside strings.
  • Loading branch information
ChrisJefferson committed May 6, 2021
1 parent d8fdd19 commit 575ed3e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
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);
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

0 comments on commit 575ed3e

Please sign in to comment.