From 575ed3e16c9800fbaa4ef92f40bcb80c56042dc2 Mon Sep 17 00:00:00 2001 From: Chris Jefferson Date: Fri, 30 Apr 2021 15:03:48 +0100 Subject: [PATCH] Fix printing of strings inside functions Previously we normalised all whitespace in printed out functions, which would effect whitespace inside strings. --- lib/function.gi | 4 ++-- tst/testinstall/function.tst | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/function.gi b/lib/function.gi index 60fe73a3e6..e34ebed9ae 100644 --- a/lib/function.gi +++ b/lib/function.gi @@ -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", diff --git a/tst/testinstall/function.tst b/tst/testinstall/function.tst index 92e683630b..97edb76d9a 100644 --- a/tst/testinstall/function.tst +++ b/tst/testinstall/function.tst @@ -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 @@ -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);