More tests for primitives.

This commit is contained in:
Bob Nystrom
2013-10-28 06:53:51 -07:00
parent f5d9908346
commit db14c531b8
5 changed files with 20 additions and 1 deletions

View File

@ -164,7 +164,7 @@ def run_test(path):
# Display the results.
if len(fails) == 0:
passed += 1
print color.GREEN + 'PASS' + color.DEFAULT + ': ' + path
#print color.GREEN + 'PASS' + color.DEFAULT + ': ' + path
else:
failed += 1
print_line(color.RED + 'FAIL' + color.DEFAULT + ': ' + path)

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);
}

6
test/number_abs.wren Normal file
View File

@ -0,0 +1,6 @@
io.write(123.abs) // expect: 123
io.write(-123.abs) // expect: 123
io.write(0.abs) // expect: 0
io.write(-0.abs) // expect: 0
// TODO(bob): Floating point numbers.

View File

@ -0,0 +1,8 @@
io.write("".contains("")) // expect: 1
io.write("anything".contains("")) // expect: 1
io.write("something".contains("meth")) // expect: 1
io.write("something".contains("some")) // expect: 1
io.write("something".contains("ing")) // expect: 1
io.write("something".contains("math")) // expect: 0
// TODO(bob): Passing non-string as argument.

2
test/string_count.wren Normal file
View File

@ -0,0 +1,2 @@
io.write("".count) // expect: 0
io.write("a string".count) // expect: 8