Add tests for previous commit
This commit is contained in:
parent
ded58071a1
commit
cccf36eb4f
21 changed files with 86 additions and 3 deletions
|
|
@ -20,8 +20,11 @@ let strip_string s =
|
||||||
Str.global_replace (Str.regexp "^[\r\n\t ]") "" rep
|
Str.global_replace (Str.regexp "^[\r\n\t ]") "" rep
|
||||||
|
|
||||||
let get_files glob =
|
let get_files glob =
|
||||||
let path = Filename.concat Config_pfff.path "/tests/generators/nim/" in
|
try
|
||||||
sort (Common2.glob (spf "%s/%s" path glob))
|
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 basename fpath =
|
||||||
let fullpath = Filename.concat Config_pfff.path "/tests/generators/nim//" in
|
let fullpath = Filename.concat Config_pfff.path "/tests/generators/nim//" in
|
||||||
|
|
@ -29,8 +32,9 @@ let basename fpath =
|
||||||
|
|
||||||
let get_code_pairs name =
|
let get_code_pairs name =
|
||||||
let cglob = name ^ "*.c" in
|
let cglob = name ^ "*.c" in
|
||||||
|
let cppglob = name ^ "*.cpp" in
|
||||||
let nimglob = name ^ "*.nim" 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
|
and nimfiles = get_files nimglob in
|
||||||
List.map2 (fun cfile nimfile ->
|
List.map2 (fun cfile nimfile ->
|
||||||
let test_code = _gen_nim cfile in
|
let test_code = _gen_nim cfile in
|
||||||
|
|
@ -56,4 +60,9 @@ let unittest =
|
||||||
tests "enums" "test_enum" @
|
tests "enums" "test_enum" @
|
||||||
tests "macros" "test_macro" @
|
tests "macros" "test_macro" @
|
||||||
tests "operators" "test_operator" @
|
tests "operators" "test_operator" @
|
||||||
|
tests "expressions" "test_expression" @
|
||||||
|
tests "arrays" "test_array" @
|
||||||
|
tests "structs" "test_struct" @
|
||||||
|
tests "casting" "test_cast" @
|
||||||
|
tests "conditionals" "test_conditional" @
|
||||||
[]
|
[]
|
||||||
|
|
|
||||||
3
tests/generators/nim/test_array_access.c
Normal file
3
tests/generators/nim/test_array_access.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
int main() {
|
||||||
|
a[i++];
|
||||||
|
}
|
||||||
2
tests/generators/nim/test_array_access.nim
Normal file
2
tests/generators/nim/test_array_access.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
proc main(): cint =
|
||||||
|
a[postInc(i)]
|
||||||
3
tests/generators/nim/test_cast_simple.c
Normal file
3
tests/generators/nim/test_cast_simple.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
int main() {
|
||||||
|
(double) 20;
|
||||||
|
}
|
||||||
2
tests/generators/nim/test_cast_simple.nim
Normal file
2
tests/generators/nim/test_cast_simple.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
proc main(): cint =
|
||||||
|
cast[cdouble](20)
|
||||||
5
tests/generators/nim/test_conditional_if.c
Normal file
5
tests/generators/nim/test_conditional_if.c
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
int main() {
|
||||||
|
if (a > b) {
|
||||||
|
printf("A is greater");
|
||||||
|
}
|
||||||
|
}
|
||||||
3
tests/generators/nim/test_conditional_if.nim
Normal file
3
tests/generators/nim/test_conditional_if.nim
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
proc main(): cint =
|
||||||
|
if(a > b):
|
||||||
|
printf("A is greater")
|
||||||
8
tests/generators/nim/test_conditional_ifelse.c
Normal file
8
tests/generators/nim/test_conditional_ifelse.c
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
int main() {
|
||||||
|
if (a > b) {
|
||||||
|
printf("A is greater");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("B is greater or equal");
|
||||||
|
}
|
||||||
|
}
|
||||||
5
tests/generators/nim/test_conditional_ifelse.nim
Normal file
5
tests/generators/nim/test_conditional_ifelse.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
proc main(): cint =
|
||||||
|
if(a > b):
|
||||||
|
printf("A is greater")
|
||||||
|
else:
|
||||||
|
printf("B is greater or equal")
|
||||||
11
tests/generators/nim/test_conditional_ifelseif.c
Normal file
11
tests/generators/nim/test_conditional_ifelseif.c
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
7
tests/generators/nim/test_conditional_ifelseif.nim
Normal file
7
tests/generators/nim/test_conditional_ifelseif.nim
Normal 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")
|
||||||
3
tests/generators/nim/test_expression_cond.c
Normal file
3
tests/generators/nim/test_expression_cond.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
int main() {
|
||||||
|
j = i < 0 ? -5 : 5;
|
||||||
|
}
|
||||||
2
tests/generators/nim/test_expression_cond.nim
Normal file
2
tests/generators/nim/test_expression_cond.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
proc main(): cint =
|
||||||
|
j = if i < 0: -5 else: 5
|
||||||
3
tests/generators/nim/test_expression_sizeof.c
Normal file
3
tests/generators/nim/test_expression_sizeof.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
int main() {
|
||||||
|
sizeof a;
|
||||||
|
}
|
||||||
2
tests/generators/nim/test_expression_sizeof.nim
Normal file
2
tests/generators/nim/test_expression_sizeof.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
proc main(): cint =
|
||||||
|
sizeof(a)
|
||||||
3
tests/generators/nim/test_expression_sizeof_type.c
Normal file
3
tests/generators/nim/test_expression_sizeof_type.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
int main() {
|
||||||
|
sizeof(int);
|
||||||
|
}
|
||||||
2
tests/generators/nim/test_expression_sizeof_type.nim
Normal file
2
tests/generators/nim/test_expression_sizeof_type.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
proc main(): cint =
|
||||||
|
sizeof(cint)
|
||||||
3
tests/generators/nim/test_struct_record_access.c
Normal file
3
tests/generators/nim/test_struct_record_access.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
int main() {
|
||||||
|
a.twenty;
|
||||||
|
}
|
||||||
2
tests/generators/nim/test_struct_record_access.nim
Normal file
2
tests/generators/nim/test_struct_record_access.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
proc main(): cint =
|
||||||
|
a.twenty
|
||||||
3
tests/generators/nim/test_struct_record_access_ptr.c
Normal file
3
tests/generators/nim/test_struct_record_access_ptr.c
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
int main() {
|
||||||
|
a->twenty;
|
||||||
|
}
|
||||||
2
tests/generators/nim/test_struct_record_access_ptr.nim
Normal file
2
tests/generators/nim/test_struct_record_access_ptr.nim
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
proc main(): cint =
|
||||||
|
a.twenty
|
||||||
Loading…
Add table
Add a link
Reference in a new issue