From a5dfba6d692c14a7e3c7efbd769c037c6af15fef Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Fri, 11 Oct 2019 22:39:20 +0200 Subject: [PATCH] :art: Test import names --- src/lib/import.c | 16 +++++++--------- tests/import/invalid_names.c | 33 +++++++++++++++++++++++++++++++++ tests/sh/import.sh | 2 +- 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 tests/import/invalid_names.c diff --git a/src/lib/import.c b/src/lib/import.c index 78912a79..5180ec5e 100644 --- a/src/lib/import.c +++ b/src/lib/import.c @@ -100,22 +100,20 @@ ANN static m_bool name_valid(const Gwi gwi, const m_str a) { || (c == '_') || (c >= '0' && c <= '9')) continue; if(c == '<') { + if(a[++i] != '~') + GWI_ERR_B(_("illegal templating in name '%s'."), a) lvl++; ++i; continue; - } - if(c == ',') { + } else if(c == ',') { if(!lvl) GWI_ERR_B(_("illegal use of ',' outside of templating in name '%s'."), a) - continue; - } - if(c == '~') { - if(!lvl) + } else if(c == '~') { + if(!lvl || a[++i] != '>') GWI_ERR_B(_("illegal templating in name '%s'."), a) lvl--; - continue; - } - GWI_ERR_B(_("illegal character '%c' in name '%s'."), c, a) + } else + GWI_ERR_B(_("illegal character '%c' in name '%s'."), c, a) } return !lvl ? 1 : -1; } diff --git a/tests/import/invalid_names.c b/tests/import/invalid_names.c new file mode 100644 index 00000000..abb817cb --- /dev/null +++ b/tests/import/invalid_names.c @@ -0,0 +1,33 @@ +#include +#include +#include "gwion_util.h" +#include "gwion_ast.h" +#include "oo.h" +#include "env.h" +#include "vm.h" +#include "gwion.h" +#include "type.h" +#include "instr.h" +#include "object.h" +#include "value.h" +#include "operator.h" +#include "import.h" +#include "ugen.h" +#include "func.h" +#include "gwi.h" + +GWION_IMPORT(trig) { + const Type t0 = gwi_mk_type(gwi, "T~", SZ_INT, NULL); + gwi_add_type(gwi, t0); + + const Type t1 = gwi_mk_type(gwi, "T,", SZ_INT, NULL); + gwi_add_type(gwi, t1); + + const Type t2 = gwi_mk_type(gwi, "T", SZ_INT, NULL); + gwi_add_type(gwi, t2); + + const Type t3 = gwi_mk_type(gwi, "<~a~>T", SZ_INT, NULL); + gwi_add_type(gwi, t3); + + return GW_OK; +} diff --git a/tests/sh/import.sh b/tests/sh/import.sh index d0c1b0e0..0b2c480b 100644 --- a/tests/sh/import.sh +++ b/tests/sh/import.sh @@ -1,5 +1,5 @@ #!/bin/bash -# [test] #39 +# [test] #40 n=0 [ "$1" ] && n="$1" -- 2.43.0