From 055d6bee73eb988ae498a57d29dd3d80a8928721 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Fri, 17 Apr 2020 07:37:17 -0600 Subject: Add math_expression and fix ast2 tests Update to include more expressions --- tests/include/tast2.h | 18 ++++++++++++++++++ tests/tast2.nim | 22 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/include/tast2.h b/tests/include/tast2.h index bdf8823..7e15ac0 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -8,6 +8,24 @@ extern "C" { #define D "hello" #define E 'c' +#define UEXPR (1234u << 1) +#define ULEXPR (1234ul << 2) +#define ULLEXPR (1234ull << 3) +#define LEXPR (1234l << 4) +#define LLEXPR (1234ll << 5) + +#define SHL1 (1u << 1) +#define SHL2 (1u << 2) +#define SHL3 (1u << 3) +#define COERCE 645635634896ull + -35436 +#define COERCE2 645635634896 + -35436 +#define BINEXPR ~(-(1u << !-1)) ^ (10 >> 1) +#define BOOL true +#define MATHEXPR (1 + 2/3*20 - 100) +#define ANDEXPR (100 & 11000) + +#define ALLSHL (SHL1 | SHL2 | SHL3) + struct A0; struct A1 {}; typedef struct A2; diff --git a/tests/tast2.nim b/tests/tast2.nim index e13c4ac..d65e34a 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -105,6 +105,26 @@ assert C == 0x10 assert D == "hello" assert E == 'c' +assert UEXPR == (1234.uint shl 1) +assert ULEXPR == (1234.uint32 shl 2) +assert ULLEXPR == (1234.uint64 shl 3) +assert LEXPR == (1234.int32 shl 4) +assert LLEXPR == (1234.int64 shl 5) + +assert COERCE == 645635599460'u64 +assert COERCE2 == 645635599460'i64 + +assert BINEXPR == 5 +assert BOOL == true +assert MATHEXPR == -99 +assert ANDEXPR == 96 + +assert SHL1 == (1.uint shl 1) +assert SHL2 == (1.uint shl 2) +assert SHL3 == (1.uint shl 3) + +assert ALLSHL == (SHL1 or SHL2 or SHL3) + assert A0 is object testFields(A0, "f1!cint") checkPragmas(A0, pHeaderBy, istype = false) @@ -271,7 +291,7 @@ var a21p: A21p a21p = addr a20 assert A22 is object -testFields(A22, "f1|f2!ptr ptr cint|array[123 + 132, ptr cint]") +testFields(A22, "f1|f2!ptr ptr cint|array[typeof(123)(123 + cast[typeof(123)](132)), ptr cint]") checkPragmas(A22, pHeaderBy, istype = false) var a22: A22 a22.f1 = addr a15.a2[0] -- cgit v1.2.3 From 173e6d625c3ea96a95580303fedd011684635cc4 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 19 Apr 2020 19:18:04 -0600 Subject: Add string and char support Update some comments Rename exprparser main proc Don't export parse procs Add missing utils module Try to fix array type test Try fix cast test error Disable cast test for now Revert back comment test. Have to figure out how to test without vm --- tests/include/tast2.h | 6 ++++++ tests/tast2.nim | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/include/tast2.h b/tests/include/tast2.h index 7e15ac0..3c6148a 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -23,6 +23,12 @@ extern "C" { #define BOOL true #define MATHEXPR (1 + 2/3*20 - 100) #define ANDEXPR (100 & 11000) +#define CASTEXPR (int) 34 + +#define NULLCHAR '\0' +#define OCTCHAR '\012' +#define HEXCHAR '\xFE' +#define TRICKYSTR "\x4E\034\nfoo\0\'\"\r\v\a\b\e\f\t\\\?bar" #define ALLSHL (SHL1 | SHL2 | SHL3) diff --git a/tests/tast2.nim b/tests/tast2.nim index d65e34a..d00552c 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -93,11 +93,11 @@ macro testFields(t: typed, fields: static[string] = "") = for i in 0 ..< rl.len: let name = ($rl[i][0]).strip(chars = {'*'}) - typ = ($(rl[i][1].repr())).replace("\n", "").replace(" ", "") + typ = ($(rl[i][1].repr())).replace("\n", "").replace(" ", "").replace("typeof", "type") n = names.find(name) assert n != -1, $t & "." & name & " invalid" - assert types[n] == typ, - "typeof(" & $t & ":" & name & ") != " & types[n] & ", is " & typ + assert types[n].replace("typeof", "type") == typ, + "typeof(" & $t & ":" & name & ") != " & types[n].replace("typeof", "type") & ", is " & typ assert A == 2 assert B == 1.0 @@ -118,6 +118,12 @@ assert BINEXPR == 5 assert BOOL == true assert MATHEXPR == -99 assert ANDEXPR == 96 +assert CASTEXPR == 34.chr + +assert TRICKYSTR == "N\x1C\nfoo\x00\'\"\c\v\a\b\e\f\t\\\\?bar" +assert NULLCHAR == '\0' +assert OCTCHAR == '\n' +assert HEXCHAR.int == 0xFE assert SHL1 == (1.uint shl 1) assert SHL2 == (1.uint shl 2) -- cgit v1.2.3 From aa1086fae37999180b485ced323d35acec7868a1 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Mon, 20 Apr 2020 09:08:08 -0600 Subject: Fix cast type only run tast2 on supported compilers Change cast to gentle type cast Re enable tests for Nim < 1.0.0 --- tests/include/tast2.h | 6 +++--- tests/tast2.nim | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/include/tast2.h b/tests/include/tast2.h index 3c6148a..53b4d64 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -17,13 +17,13 @@ extern "C" { #define SHL1 (1u << 1) #define SHL2 (1u << 2) #define SHL3 (1u << 3) -#define COERCE 645635634896ull + -35436 -#define COERCE2 645635634896 + -35436 +#define COERCE 645635634896ull + 35436 +#define COERCE2 645635634896 + 35436ul #define BINEXPR ~(-(1u << !-1)) ^ (10 >> 1) #define BOOL true #define MATHEXPR (1 + 2/3*20 - 100) #define ANDEXPR (100 & 11000) -#define CASTEXPR (int) 34 +#define CASTEXPR (char) 34 #define NULLCHAR '\0' #define OCTCHAR '\012' diff --git a/tests/tast2.nim b/tests/tast2.nim index d00552c..d43ce9f 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -111,8 +111,8 @@ assert ULLEXPR == (1234.uint64 shl 3) assert LEXPR == (1234.int32 shl 4) assert LLEXPR == (1234.int64 shl 5) -assert COERCE == 645635599460'u64 -assert COERCE2 == 645635599460'i64 +assert COERCE == 645635670332'u64 +assert COERCE2 == 645635670332'i64 assert BINEXPR == 5 assert BOOL == true @@ -297,7 +297,7 @@ var a21p: A21p a21p = addr a20 assert A22 is object -testFields(A22, "f1|f2!ptr ptr cint|array[typeof(123)(123 + cast[typeof(123)](132)), ptr cint]") +testFields(A22, "f1|f2!ptr ptr cint|array[type(123)(255), ptr cint]") checkPragmas(A22, pHeaderBy, istype = false) var a22: A22 a22.f1 = addr a15.a2[0] -- cgit v1.2.3 From 208098b3eb959e477a3625a8a48305ddaa1cec4f Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Mon, 20 Apr 2020 11:33:53 -0600 Subject: Make bitwise_expression forwards compatible Skip syms for tmath Skip more syms Add casting back for cast_expression. Disable cast test on Nim < 1.0.0 Skip more syms for cast expressions on Nim < 1.0.0 --- tests/tast2.nim | 11 +++++++++-- tests/tmath.nim | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/tast2.nim b/tests/tast2.nim index d43ce9f..0b3762a 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -3,11 +3,16 @@ import macros, os, sets, strutils import nimterop/[cimport] static: + # Skip casting on lower nim compilers because + # the VM does not support it + when (NimMajor, NimMinor, NimPatch) < (1, 0, 0): + cSkipSymbol @["CASTEXPR"] cDebug() const path = currentSourcePath.parentDir() / "include" / "tast2.h" + when defined(HEADER): cDefine("HEADER") const @@ -118,7 +123,9 @@ assert BINEXPR == 5 assert BOOL == true assert MATHEXPR == -99 assert ANDEXPR == 96 -assert CASTEXPR == 34.chr + +when (NimMajor, NimMinor, NimPatch) >= (1, 0, 0): + assert CASTEXPR == 34.chr assert TRICKYSTR == "N\x1C\nfoo\x00\'\"\c\v\a\b\e\f\t\\\\?bar" assert NULLCHAR == '\0' @@ -453,4 +460,4 @@ checkPragmas(nested, pHeaderImpBy) when defined(HEADER): assert sitest1(5) == 10 - assert sitest1(10) == 20 \ No newline at end of file + assert sitest1(10) == 20 diff --git a/tests/tmath.nim b/tests/tmath.nim index 5d84700..bbf7abd 100644 --- a/tests/tmath.nim +++ b/tests/tmath.nim @@ -13,6 +13,10 @@ when defined(windows): complex = object static: + when (NimMajor, NimMinor, NimPatch) < (1, 0, 0): + cSkipSymbol @["mingw_choose_expr", "EXCEPTION_DEFINED", "COMPLEX_DEFINED", "matherr", "HUGE", "FP_ILOGB0", "FP_ILOGBNAN"] + else: + cSkipSymbol @["mingw_choose_expr", "EXCEPTION_DEFINED", "COMPLEX_DEFINED", "matherr", "HUGE"] cDebug() cDisableCaching() cAddStdDir() -- cgit v1.2.3 From 4794c076ffc7f46858dfebfdae47d8e3c47d1cf7 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Mon, 20 Apr 2020 19:01:53 -0600 Subject: Fix pcre tests --- tests/tpcre.nim | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/tpcre.nim b/tests/tpcre.nim index c8e8059..3bbd1ba 100644 --- a/tests/tpcre.nim +++ b/tests/tpcre.nim @@ -7,6 +7,7 @@ const pcreH = baseDir/"pcre.h.in" static: + cSkipSymbol @["PCRE_UCHAR16", "PCRE_UCHAR32"] if not pcreH.fileExists(): downloadUrl("https://github.com/svn2github/pcre/raw/master/pcre.h.in", baseDir) cDebug() -- cgit v1.2.3 From b1a445c34dfff04d5c799b7c4ee0f7e806900e91 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Wed, 22 Apr 2020 01:16:19 -0600 Subject: Update based on comments from review. Need to add more docs and reorg to use gstate --- tests/tast2.nim | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/tast2.nim b/tests/tast2.nim index 0b3762a..e82430b 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -12,7 +12,6 @@ static: const path = currentSourcePath.parentDir() / "include" / "tast2.h" - when defined(HEADER): cDefine("HEADER") const -- cgit v1.2.3 From 2813dc61f22aecaaaa82054f144a48c4de520cf2 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Thu, 23 Apr 2020 16:45:19 -0600 Subject: Consolidate shift_expression into binary_expression and write more tests --- tests/include/tast2.h | 10 ++++++++++ tests/tast2.nim | 14 +++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/include/tast2.h b/tests/include/tast2.h index 53b4d64..e72a3b8 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -24,6 +24,16 @@ extern "C" { #define MATHEXPR (1 + 2/3*20 - 100) #define ANDEXPR (100 & 11000) #define CASTEXPR (char) 34 +#define a 100 +#define b 200 +#define EQ1 a <= b +#define EQ2 a >= b +#define EQ3 a > b +#define EQ4 a < b +#define EQ5 a != b +#define EQ6 a == b + +#define SIZEOF sizeof(char) #define NULLCHAR '\0' #define OCTCHAR '\012' diff --git a/tests/tast2.nim b/tests/tast2.nim index e82430b..57bfc90 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -115,6 +115,18 @@ assert ULLEXPR == (1234.uint64 shl 3) assert LEXPR == (1234.int32 shl 4) assert LLEXPR == (1234.int64 shl 5) +assert a == 100 +assert b == 200 + +assert EQ1 == (a <= b) +assert EQ2 == (a >= b) +assert EQ3 == (a > b) +assert EQ4 == (a < b) +assert EQ5 == (a != b) +assert EQ6 == (a == b) + +assert SIZEOF == 1 + assert COERCE == 645635670332'u64 assert COERCE2 == 645635670332'i64 @@ -303,7 +315,7 @@ var a21p: A21p a21p = addr a20 assert A22 is object -testFields(A22, "f1|f2!ptr ptr cint|array[type(123)(255), ptr cint]") +testFields(A22, "f1|f2!ptr ptr cint|array[123 + type(123)(132), ptr cint]") checkPragmas(A22, pHeaderBy, istype = false) var a22: A22 a22.f1 = addr a15.a2[0] -- cgit v1.2.3 From 9e799ee3b19ac152d1c2403c6af1e3806e1a31fe Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Thu, 23 Apr 2020 16:53:52 -0600 Subject: Fix tmath tests Modify tmath.nim to have one skip symbol Fix macro expansion with common value Fix tmath again --- tests/include/tast2.h | 16 ++++++++-------- tests/tast2.nim | 18 +++++++++--------- tests/tmath.nim | 6 ++++-- 3 files changed, 21 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/include/tast2.h b/tests/include/tast2.h index e72a3b8..815791f 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -24,14 +24,14 @@ extern "C" { #define MATHEXPR (1 + 2/3*20 - 100) #define ANDEXPR (100 & 11000) #define CASTEXPR (char) 34 -#define a 100 -#define b 200 -#define EQ1 a <= b -#define EQ2 a >= b -#define EQ3 a > b -#define EQ4 a < b -#define EQ5 a != b -#define EQ6 a == b +#define AVAL 100 +#define BVAL 200 +#define EQ1 AVAL <= BVAL +#define EQ2 AVAL >= BVAL +#define EQ3 AVAL > BVAL +#define EQ4 AVAL < BVAL +#define EQ5 AVAL != BVAL +#define EQ6 AVAL == BVAL #define SIZEOF sizeof(char) diff --git a/tests/tast2.nim b/tests/tast2.nim index 57bfc90..da7fafa 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -115,15 +115,15 @@ assert ULLEXPR == (1234.uint64 shl 3) assert LEXPR == (1234.int32 shl 4) assert LLEXPR == (1234.int64 shl 5) -assert a == 100 -assert b == 200 - -assert EQ1 == (a <= b) -assert EQ2 == (a >= b) -assert EQ3 == (a > b) -assert EQ4 == (a < b) -assert EQ5 == (a != b) -assert EQ6 == (a == b) +assert AVAL == 100 +assert BVAL == 200 + +assert EQ1 == (AVAL <= BVAL) +assert EQ2 == (AVAL >= BVAL) +assert EQ3 == (AVAL > BVAL) +assert EQ4 == (AVAL < BVAL) +assert EQ5 == (AVAL != BVAL) +assert EQ6 == (AVAL == BVAL) assert SIZEOF == 1 diff --git a/tests/tmath.nim b/tests/tmath.nim index bbf7abd..b8477c1 100644 --- a/tests/tmath.nim +++ b/tests/tmath.nim @@ -14,9 +14,11 @@ when defined(windows): static: when (NimMajor, NimMinor, NimPatch) < (1, 0, 0): - cSkipSymbol @["mingw_choose_expr", "EXCEPTION_DEFINED", "COMPLEX_DEFINED", "matherr", "HUGE", "FP_ILOGB0", "FP_ILOGBNAN"] + # FP_ILOGB0 and FP_ILOGBNAN are casts that are unsupported + # on lower Nim VMs + cSkipSymbol @["math_errhandling", "FP_ILOGB0", "FP_ILOGBNAN"] else: - cSkipSymbol @["mingw_choose_expr", "EXCEPTION_DEFINED", "COMPLEX_DEFINED", "matherr", "HUGE"] + cSkipSymbol @["math_errhandling"] cDebug() cDisableCaching() cAddStdDir() -- cgit v1.2.3 From 3e28501826f5d655ad3797cbf29009082be126e1 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Thu, 23 Apr 2020 20:59:21 -0600 Subject: Fix comments breaking code --- tests/include/tast2.h | 4 ++-- tests/tpcre.nim | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/include/tast2.h b/tests/include/tast2.h index 815791f..42c852f 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -35,8 +35,8 @@ extern "C" { #define SIZEOF sizeof(char) -#define NULLCHAR '\0' -#define OCTCHAR '\012' +#define NULLCHAR '\0'/* comments should not break things*/ +#define OCTCHAR '\012' // nor should this comment #define HEXCHAR '\xFE' #define TRICKYSTR "\x4E\034\nfoo\0\'\"\r\v\a\b\e\f\t\\\?bar" diff --git a/tests/tpcre.nim b/tests/tpcre.nim index 3bbd1ba..c8e8059 100644 --- a/tests/tpcre.nim +++ b/tests/tpcre.nim @@ -7,7 +7,6 @@ const pcreH = baseDir/"pcre.h.in" static: - cSkipSymbol @["PCRE_UCHAR16", "PCRE_UCHAR32"] if not pcreH.fileExists(): downloadUrl("https://github.com/svn2github/pcre/raw/master/pcre.h.in", baseDir) cDebug() -- cgit v1.2.3 From 322a0031984cefc278d2a377daa27bffdcbcae73 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Thu, 23 Apr 2020 22:11:39 -0600 Subject: Add test for not supported nodes --- tests/include/tast2.h | 2 ++ tests/tast2.nim | 2 ++ 2 files changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/include/tast2.h b/tests/include/tast2.h index 42c852f..b47a801 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -34,6 +34,8 @@ extern "C" { #define EQ6 AVAL == BVAL #define SIZEOF sizeof(char) +#define REG_STR "regular string" +#define NOTSUPPORTEDSTR "not a " REG_STR #define NULLCHAR '\0'/* comments should not break things*/ #define OCTCHAR '\012' // nor should this comment diff --git a/tests/tast2.nim b/tests/tast2.nim index da7fafa..4cfbeac 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -109,6 +109,8 @@ assert C == 0x10 assert D == "hello" assert E == 'c' +assert not defined(NOTSUPPORTEDSTR) + assert UEXPR == (1234.uint shl 1) assert ULEXPR == (1234.uint32 shl 2) assert ULLEXPR == (1234.uint64 shl 3) -- cgit v1.2.3