mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 23:04:08 +10:00
Tested custom char trims
This commit is contained in:
@@ -99,6 +99,11 @@ static int nativeTrim(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
|
|||||||
|
|
||||||
if (arguments->count == 2) {
|
if (arguments->count == 2) {
|
||||||
trimCharsLiteral = Toy_popLiteralArray(arguments);
|
trimCharsLiteral = Toy_popLiteralArray(arguments);
|
||||||
|
|
||||||
|
Toy_Literal trimCharsLiteralIdn = trimCharsLiteral;
|
||||||
|
if (TOY_IS_IDENTIFIER(trimCharsLiteral) && Toy_parseIdentifierToValue(interpreter, &trimCharsLiteral)) {
|
||||||
|
Toy_freeLiteral(trimCharsLiteralIdn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
trimCharsLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString(" \t\n\r"));
|
trimCharsLiteral = TOY_TO_STRING_LITERAL(Toy_createRefString(" \t\n\r"));
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import compound;
|
|||||||
assert "Hello World".toUpper() == "HELLO WORLD", "_toUpper() failed";
|
assert "Hello World".toUpper() == "HELLO WORLD", "_toUpper() failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
//test trim
|
//test trim defaults
|
||||||
{
|
{
|
||||||
//test a bunch
|
//test a bunch
|
||||||
fn test(s, pass) {
|
fn test(s, pass) {
|
||||||
@@ -33,4 +33,12 @@ import compound;
|
|||||||
assert " hello world ".trim() == "hello world", "hello world.trim() failed";
|
assert " hello world ".trim() == "hello world", "hello world.trim() failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//test trim custom values
|
||||||
|
{
|
||||||
|
var chars = "heilod";
|
||||||
|
|
||||||
|
assert "hello world".trim(chars) == " wor", "custom _trim() failed";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
print "All good";
|
print "All good";
|
||||||
|
|||||||
Reference in New Issue
Block a user