made the import path relative to the current script

This commit is contained in:
cozis
2022-08-16 18:41:29 +02:00
parent 0a090c4cfa
commit 4d4e365002
6 changed files with 186 additions and 23 deletions
+1 -19
View File
@@ -265,22 +265,4 @@ fun compareAny(A, B) {
error("Maps aren't supported yet!");
return A == B;
}
assert(compareAny(1, 2) == true);
assert(compareAny([], []) == true);
assert(compareAny([], [1]) == false);
assert(compareAny([1, 2, 3], [1, 2, 3]) == true);
assert(compareAny([1, 2, 3], [1, 2, 4]) == false);
assert(compareAny([1, 2, 3], [1, 2, 3, 4]) == false);
assert(parse("null") == none);
assert(parse("true") == true);
assert(parse("false") == false);
assert(parse('"Hello, world!"') == "Hello, world!");
assert(compareAny(parse('[]'), []));
assert(compareAny(parse('[1, 2, 3]'), [1, 2, 3]));
val, err = parse('[1, 2, 3]');
print("val=[", val, "]\n");
print("err=[", err, "]\n");
}
+12
View File
@@ -0,0 +1,12 @@
json, err = import("json.noja");
utils = import("utils.noja");
assert(json.parse("null") == none);
assert(json.parse("true") == true);
assert(json.parse("false") == false);
assert(json.parse('"Hello, world!"') == "Hello, world!");
assert(utils.compareAny(json.parse('[]'), []));
assert(utils.compareAny(json.parse('[1, 2, 3]'), [1, 2, 3]));
print("No assertions fired!\n");
+37
View File
@@ -0,0 +1,37 @@
fun compareAny(A, B) {
fun compareLists(A: List, B: List) {
n = count(A);
if n != count(B):
return false;
i = 0;
while i < n: {
if not compareAny(A[i], B[i]):
return false;
i = i + 1;
}
return true;
}
T = type(A);
if T != type(B):
return false;
if T == List:
return compareLists(A, B);
if T == Map:
error("Maps aren't supported yet!");
return A == B;
}
assert(compareAny(1, 2) == false);
assert(compareAny([], []) == true);
assert(compareAny([], [1]) == false);
assert(compareAny([1, 2, 3], [1, 2, 3]) == true);
assert(compareAny([1, 2, 3], [1, 2, 4]) == false);
assert(compareAny([1, 2, 3], [1, 2, 3, 4]) == false);