Skip to content

Commit b63512a

Browse files
committed
Add some tests for kernel functions in stringobj.c
1 parent 246719c commit b63512a

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#
2+
# Tests for functions defined in src/strinobj.c
3+
#
4+
gap> START_TEST("kernel/strinobj.tst");
5+
6+
#
7+
gap> s := EmptyString(2);
8+
""
9+
gap> EmptyString(-1);
10+
Error, <len> must be an non-negative integer (not a integer)
11+
12+
#
13+
gap> ShrinkAllocationString(s);
14+
gap> ShrinkAllocationString(1);
15+
Error, <str> must be a string, not a integer)
16+
17+
#
18+
gap> CHAR_INT(fail);
19+
Error, <val> must be an integer (not a boolean or fail)
20+
gap> CHAR_INT(-1);
21+
Error, <val> must be an integer between 0 and 255
22+
gap> CHAR_INT(65);
23+
'A'
24+
25+
#
26+
gap> INT_CHAR(1);
27+
Error, <val> must be a character (not a integer)
28+
gap> INT_CHAR('A');
29+
65
30+
31+
#
32+
gap> CHAR_SINT(fail);
33+
Error, <val> must be an integer (not a boolean or fail)
34+
gap> CHAR_SINT(255);
35+
Error, <val> must be an integer between -128 and 127
36+
gap> CHAR_SINT(65);
37+
'A'
38+
39+
#
40+
gap> SINT_CHAR(1);
41+
Error, <val> must be a character (not a integer)
42+
gap> SINT_CHAR('A');
43+
65
44+
45+
#
46+
gap> INTLIST_STRING("ABC", 1);
47+
[ 65, 66, 67 ]
48+
gap> INTLIST_STRING("ABC", -1);
49+
[ 65, 66, 67 ]
50+
gap> INTLIST_STRING(1, -1);
51+
Error, <val> must be a string, not a integer)
52+
53+
#
54+
gap> SINTLIST_STRING("ABC");
55+
[ 65, 66, 67 ]
56+
gap> SINTLIST_STRING(1);
57+
Error, <val> must be a string, not a integer)
58+
59+
#
60+
gap> STRING_SINTLIST([ 65, 66, 67 ]);
61+
"ABC"
62+
gap> STRING_SINTLIST([ 65 .. 67 ]);
63+
"ABC"
64+
gap> STRING_SINTLIST(1);
65+
Error, <val> must be a plain list of small integers or a range, not a integer
66+
gap> STRING_SINTLIST([ 'B' ]);
67+
Error, <val> must be a plain list of small integers or a range, not a list (pl\
68+
ain,hom)
69+
70+
#
71+
gap> REVNEG_STRING(1);
72+
Error, <val> must be a string, not a integer)
73+
74+
#
75+
gap> CONV_STRING(1);
76+
Error, ConvString: <string> must be a string (not a integer)
77+
78+
#
79+
gap> COPY_TO_STRING_REP(1);
80+
Error, CopyToStringRep: <string> must be a string (not a integer)
81+
82+
#
83+
gap> POSITION_SUBSTRING("abc","x",0);
84+
fail
85+
gap> POSITION_SUBSTRING("abc","b",0);
86+
2
87+
gap> POSITION_SUBSTRING("abc","b",3);
88+
fail
89+
gap> POSITION_SUBSTRING(1,2,3);
90+
Error, POSITION_SUBSTRING: <string> must be a string (not a integer)
91+
gap> POSITION_SUBSTRING("abc",2,3);
92+
Error, POSITION_SUBSTRING: <substr> must be a string (not a integer)
93+
gap> POSITION_SUBSTRING("abc","b",-1);
94+
Error, POSITION_SUBSTRING: <off> must be a non-negative integer (not a integer\
95+
)
96+
97+
#
98+
gap> s:=" abc\n xyz\n";; NormalizeWhitespace(s); s;
99+
"abc xyz"
100+
gap> NormalizeWhitespace(1);
101+
Error, NormalizeWhitespace: <string> must be a string (not a integer)
102+
103+
#
104+
gap> s:="abcdabcd";; REMOVE_CHARACTERS(s, "db"); s;
105+
"acac"
106+
gap> REMOVE_CHARACTERS(1,1);
107+
Error, RemoveCharacters: first argument <string> must be a string (not a integ\
108+
er)
109+
gap> REMOVE_CHARACTERS(s,1);
110+
Error, RemoveCharacters: second argument <rem> must be a string (not a integer\
111+
)
112+
113+
#
114+
gap> s:="abc";; TranslateString(s,UPPERCASETRANSTABLE); s;
115+
"ABC"
116+
gap> TranslateString(1,1);
117+
Error, TranslateString: first argument <string> must be a string (not a intege\
118+
r)
119+
gap> TranslateString("abc",1);
120+
Error, TranslateString: second argument <trans> must be a string (not a intege\
121+
r)
122+
gap> TranslateString("abc","def");
123+
Error, TranslateString: second argument <trans> must have length >= 256
124+
125+
#
126+
gap> STOP_TEST("kernel/strinobj.tst", 1);

0 commit comments

Comments
 (0)