-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a simple method of formatting strings, strongly inspired by Python's "format" function
- Loading branch information
1 parent
24c69d0
commit 60eb80b
Showing
4 changed files
with
214 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
gap> START_TEST("format.tst"); | ||
gap> Formatted("a{}b{}c{}d", 1,(),"xyz"); | ||
"a1b()cxyzd" | ||
gap> Formatted("{}{}{}", 1,(),"xyz"); | ||
"1()xyz" | ||
gap> Formatted("{{}}{}}}{{", 0); | ||
"{}0}{" | ||
gap> Formatted("{", 1); | ||
Error, Invalid format string, no matching '}' at position 1 | ||
gap> Formatted("{abc", 1); | ||
Error, Invalid format string, no matching '}' at position 1 | ||
gap> Formatted("}", 1); | ||
Error, Mismatched '}' at position 1 | ||
gap> Formatted("{3}{2}{2}{3}{1}", 1,2,3,4); | ||
"32231" | ||
gap> Formatted("{3}{}{2}{}{1}", 1,2,3,4); | ||
"31221" | ||
gap> Formatted("{a}{b}{a}", rec(a := (1,2), b := "ch")); | ||
"(1,2)ch(1,2)" | ||
gap> Formatted("{a}{b}{a}", 1,2); | ||
Error, first data argument must be a record when using {a} | ||
gap> Formatted("{}", rec()); | ||
"rec( )" | ||
gap> Formatted("{1}", rec()); | ||
"rec( )" | ||
gap> r1 := SymmetricGroup([3..5]);; | ||
gap> r2 := AlternatingGroup([1,3,5]);; | ||
gap> r3 := AlternatingGroup([11,12,13]);; | ||
gap> Formatted("{1!s} {1!v} {1!d}", r1); | ||
"SymmetricGroup( [ 3 .. 5 ] ) Sym( [ 3 .. 5 ] ) <object>\n" | ||
gap> Formatted("{!s} {!v} {!d}", r1, r2, r3); | ||
"SymmetricGroup( [ 3 .. 5 ] ) Alt( [ 1, 3 .. 5 ] ) <object>\n" | ||
gap> Formatted("{a!s} {b!v} {c!d}", rec(a := r1, b := r2, c := r3)); | ||
"SymmetricGroup( [ 3 .. 5 ] ) Alt( [ 1, 3 .. 5 ] ) <object>\n" | ||
gap> Formatted("{a!x}", rec(a := r1)); | ||
Error, Invalid formatting option: 'x' | ||
gap> Formatted("{a!}", rec(a := r1)); | ||
"SymmetricGroup( [ 3 .. 5 ] )" | ||
gap> Formatted("{!x}", r1); | ||
Error, Invalid formatting option: 'x' | ||
gap> STOP_TEST("format.tst",1); |