Add tests for previous commit

This commit is contained in:
Joey Yakimowich-Payne 2018-06-03 16:51:15 +09:00
commit cccf36eb4f
21 changed files with 86 additions and 3 deletions

View file

@ -20,8 +20,11 @@ let strip_string s =
Str.global_replace (Str.regexp "^[\r\n\t ]") "" rep
let get_files glob =
let path = Filename.concat Config_pfff.path "/tests/generators/nim/" in
sort (Common2.glob (spf "%s/%s" path glob))
try
let path = Filename.concat Config_pfff.path "/tests/generators/nim/" in
sort (Common2.glob (spf "%s/%s" path glob))
with
Common2.CmdError (a, b) -> []
let basename fpath =
let fullpath = Filename.concat Config_pfff.path "/tests/generators/nim//" in
@ -29,8 +32,9 @@ let basename fpath =
let get_code_pairs name =
let cglob = name ^ "*.c" in
let cppglob = name ^ "*.cpp" in
let nimglob = name ^ "*.nim" in
let cfiles = get_files cglob
let cfiles = get_files cglob @ get_files cppglob
and nimfiles = get_files nimglob in
List.map2 (fun cfile nimfile ->
let test_code = _gen_nim cfile in
@ -56,4 +60,9 @@ let unittest =
tests "enums" "test_enum" @
tests "macros" "test_macro" @
tests "operators" "test_operator" @
tests "expressions" "test_expression" @
tests "arrays" "test_array" @
tests "structs" "test_struct" @
tests "casting" "test_cast" @
tests "conditionals" "test_conditional" @
[]

View file

@ -0,0 +1,3 @@
int main() {
a[i++];
}

View file

@ -0,0 +1,2 @@
proc main(): cint =
a[postInc(i)]

View file

@ -0,0 +1,3 @@
int main() {
(double) 20;
}

View file

@ -0,0 +1,2 @@
proc main(): cint =
cast[cdouble](20)

View file

@ -0,0 +1,5 @@
int main() {
if (a > b) {
printf("A is greater");
}
}

View file

@ -0,0 +1,3 @@
proc main(): cint =
if(a > b):
printf("A is greater")

View file

@ -0,0 +1,8 @@
int main() {
if (a > b) {
printf("A is greater");
}
else {
printf("B is greater or equal");
}
}

View file

@ -0,0 +1,5 @@
proc main(): cint =
if(a > b):
printf("A is greater")
else:
printf("B is greater or equal")

View file

@ -0,0 +1,11 @@
int main() {
if (a > b) {
printf("A is greater");
}
else if (a == b) {
printf("A and B are equal");
}
else {
printf("A is less than B");
}
}

View file

@ -0,0 +1,7 @@
proc main(): cint =
if(a > b):
printf("A is greater")
elif(a == b):
printf("A and B are equal")
else:
printf("A is less than B")

View file

@ -0,0 +1,3 @@
int main() {
j = i < 0 ? -5 : 5;
}

View file

@ -0,0 +1,2 @@
proc main(): cint =
j = if i < 0: -5 else: 5

View file

@ -0,0 +1,3 @@
int main() {
sizeof a;
}

View file

@ -0,0 +1,2 @@
proc main(): cint =
sizeof(a)

View file

@ -0,0 +1,3 @@
int main() {
sizeof(int);
}

View file

@ -0,0 +1,2 @@
proc main(): cint =
sizeof(cint)

View file

@ -0,0 +1,3 @@
int main() {
a.twenty;
}

View file

@ -0,0 +1,2 @@
proc main(): cint =
a.twenty

View file

@ -0,0 +1,3 @@
int main() {
a->twenty;
}

View file

@ -0,0 +1,2 @@
proc main(): cint =
a.twenty