test: add test files for number_abs, string_contains, string_count and fix empty string corner case in string_contains primitive

This commit is contained in:
Bob Nystrom
2013-10-28 13:53:51 +00:00
parent 6e8b5a2861
commit cde3490579
5 changed files with 20 additions and 1 deletions
+3
View File
@@ -35,6 +35,9 @@ DEF_PRIMITIVE(string_contains)
// TODO(bob): Check type of arg first!
const char* search = ((ObjString*)args[1])->value;
// Corner case, the empty string contains the empty string.
if (strlen(string) == 0 && strlen(search) == 0) return (Value)makeNum(1);
// TODO(bob): Return bool.
return (Value)makeNum(strstr(string, search) != NULL);
}