Skip to content

Commit

Permalink
added new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonymousAAArdvark committed Feb 12, 2022
1 parent 5034ab2 commit 4201c6c
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 21 deletions.
38 changes: 38 additions & 0 deletions src/cmake-build-release/CMakeFiles/qi.dir/C.includecache
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ stddef.h
stdint.h
-

/Users/andrewyang/CLionProjects/qi/src/compiler.h
object.h
/Users/andrewyang/CLionProjects/qi/src/object.h
vm.h
/Users/andrewyang/CLionProjects/qi/src/vm.h

/Users/andrewyang/CLionProjects/qi/src/debug.h
chunk.h
/Users/andrewyang/CLionProjects/qi/src/chunk.h

/Users/andrewyang/CLionProjects/qi/src/lib.c
stdarg.h
-
Expand Down Expand Up @@ -70,6 +80,34 @@ string.h
common.h
/Users/andrewyang/CLionProjects/qi/src/common.h

/Users/andrewyang/CLionProjects/qi/src/vm.c
stdarg.h
-
stdio.h
-
string.h
-
time.h
-
ctype.h
-
math.h
-
common.h
/Users/andrewyang/CLionProjects/qi/src/common.h
compiler.h
/Users/andrewyang/CLionProjects/qi/src/compiler.h
debug.h
/Users/andrewyang/CLionProjects/qi/src/debug.h
object.h
/Users/andrewyang/CLionProjects/qi/src/object.h
memory.h
/Users/andrewyang/CLionProjects/qi/src/memory.h
vm.h
/Users/andrewyang/CLionProjects/qi/src/vm.h
lib.h
/Users/andrewyang/CLionProjects/qi/src/lib.h

/Users/andrewyang/CLionProjects/qi/src/vm.h
chunk.h
/Users/andrewyang/CLionProjects/qi/src/chunk.h
Expand Down
Binary file modified src/cmake-build-release/CMakeFiles/qi.dir/lib.c.o
Binary file not shown.
Binary file modified src/cmake-build-release/CMakeFiles/qi.dir/vm.c.o
Binary file not shown.
4 changes: 2 additions & 2 deletions src/cmake-build-release/Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Start testing: Oct 11 16:31 MST
Start testing: Oct 11 22:08 MST
----------------------------------------------------------
End testing: Oct 11 16:31 MST
End testing: Oct 11 22:08 MST
Binary file modified src/cmake-build-release/qi
Binary file not shown.
4 changes: 2 additions & 2 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ bool ntosNative(int argCount, Value* args) {
"Argument 1 (input) must be of type 'number', not '%s'.", getType(args[0]));
}
char str[100];
sprintf(str, "%f", AS_NUMBER(args[0]));
sprintf(str, "%g", AS_NUMBER(args[0]));
args[-1] = OBJ_VAL(copyString(str, strlen(str)));
return true;
}

bool typeNative(int argCount, Value* args) {
bool typeofNative(int argCount, Value* args) {
char* type = getType(args[0]);
args[-1] = OBJ_VAL(copyString(type, strlen(type)));
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ bool maxNative(int argCount, Value* args);
bool roundNative(int argCount, Value* args);
bool stonNative(int argCount, Value* args);
bool ntosNative(int argCount, Value* args);
bool typeNative(int argCount, Value* args);
bool typeofNative(int argCount, Value* args);

#endif //QI_LIB_H
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int main(int argc, const char* argv[]) {
// if(chinese[i] == L'\u4E0D')
// printf("also found\n");
// }

initVM();

if (argc == 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void initVM() {
defineNative("round", roundNative, -1);
defineNative("ston", stonNative, 1);
defineNative("ntos", ntosNative, 1);
defineNative("type", typeNative, 1);
defineNative("typeof", typeofNative, 1);
}

void freeVM() {
Expand Down
3 changes: 3 additions & 0 deletions test/native/conversion.qi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
println(ston("1, 2, 3, lets go!")); // expect: 1
println(ntos(4 / 8)); // expect: 0.5
println(ntos(4 / 7)); // expect: 0.571429
4 changes: 4 additions & 0 deletions test/native/exponent.qi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
println(sqrt(4)); // expect: 2
println(pow(3, 4)); // expect: 81
println(pow(9, 0.5)); // expect: 3
println(sqrt("3")); // expect runtime error: Argument 1 (input) must be of type 'number', not 'string'.
3 changes: 3 additions & 0 deletions test/native/minmax.qi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
println(min(3, 2)); // expect: 2
println(max(3, 2)); // expect: 3
println(min("err", 3)); // expect runtime error: Argument 1 must be of type 'number', not 'string'.
File renamed without changes.
6 changes: 6 additions & 0 deletions test/native/round.qi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var test = [10, 11.5, 1.5, 1.05, 1.005];
for (var i = 0; i < test.length(); i++) {
test[i] = round(test[i], 1);
}
println(test); // expect: [10, 11.5, 1.5, 1.1, 1]
round(); // expect runtime error: Expected 1 to 2 arguments but got 0.
12 changes: 12 additions & 0 deletions test/native/typeof.qi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fun function() {}
class klass {
method() {}
}
println(typeof(klass)); // expect: class
println(typeof(min)); // expect: native function
println(typeof(klass())); // expect: instance
println(typeof("")); // expect: string
println(typeof([])); // expect: list
println(typeof(false)); // expect: bool
println(typeof(0)); // expect: number
println(typeof(nil)); // expect: nil
18 changes: 3 additions & 15 deletions test/scratch.qi
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
// nontest
var list = [];
var i = 0;
for (; i < 10; i++) {
if (i == 5) break;
list.push(i);
}
println(list); // expect: [0, 1, 2, 3, 4]
while (true) {
if (i == 10) break;
list.push(i);
i++;
}
println(list); // expect: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
{
break;
fun function() {}
class klass {
method() {}
}

0 comments on commit 4201c6c

Please sign in to comment.