From fe4c0f43dc6eb84d404b01bde2ac0b3f4e553b83 Mon Sep 17 00:00:00 2001 From: i10416 Date: Mon, 28 Feb 2022 23:12:20 +0900 Subject: [PATCH] use predefined matcher for exceptions --- test/parser_test.dart | 118 +++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 65 deletions(-) diff --git a/test/parser_test.dart b/test/parser_test.dart index fb9a2d5..23ae232 100644 --- a/test/parser_test.dart +++ b/test/parser_test.dart @@ -305,73 +305,61 @@ void main() { ex.toString(); }); - dynamic parseFail(String source) { - try { - final parser = Parser(source, 'foo', '{{ }}', lenient: false); - parser.parse(); - fail('Did not throw.'); - } on Exception catch (ex, st) { - if (ex is! TemplateException) { - // ignore: avoid_print - print(ex); - // ignore: avoid_print - print(st); - } - return ex; - } + dynamic attemptLenient(String source) { + final parser = Parser(source, 'foo', '{{ }}', lenient: false); + parser.parse(); } - + Matcher exceptionOfType() => TypeMatcher(); test('parse eof', () { - void expectTemplateEx(dynamic ex) => expect(ex is TemplateException, isTrue); - - expectTemplateEx(parseFail('{{#foo}}{{bar}}{{/foo}')); - expectTemplateEx(parseFail('{{#foo}}{{bar}}{{/foo')); - expectTemplateEx(parseFail('{{#foo}}{{bar}}{{/')); - expectTemplateEx(parseFail('{{#foo}}{{bar}}{{')); - expectTemplateEx(parseFail('{{#foo}}{{bar}}{')); - expectTemplateEx(parseFail('{{#foo}}{{bar}}')); - expectTemplateEx(parseFail('{{#foo}}{{bar}')); - expectTemplateEx(parseFail('{{#foo}}{{bar')); - expectTemplateEx(parseFail('{{#foo}}{{')); - expectTemplateEx(parseFail('{{#foo}}{')); - expectTemplateEx(parseFail('{{#foo}}')); - expectTemplateEx(parseFail('{{#foo}')); - expectTemplateEx(parseFail('{{#')); - expectTemplateEx(parseFail('{{')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}{{ / foo }')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}{{ / foo ')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}{{ / foo')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}{{ / ')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}{{ /')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}{{ ')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}{{')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}{')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }}')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar }')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar ')); - expectTemplateEx(parseFail('{{ # foo }}{{ bar')); - expectTemplateEx(parseFail('{{ # foo }}{{ ')); - expectTemplateEx(parseFail('{{ # foo }}{{')); - expectTemplateEx(parseFail('{{ # foo }}{')); - expectTemplateEx(parseFail('{{ # foo }}')); - expectTemplateEx(parseFail('{{ # foo }')); - expectTemplateEx(parseFail('{{ # foo ')); - expectTemplateEx(parseFail('{{ # foo')); - expectTemplateEx(parseFail('{{ # ')); - expectTemplateEx(parseFail('{{ #')); - expectTemplateEx(parseFail('{{ ')); - expectTemplateEx(parseFail('{{')); - - expectTemplateEx(parseFail('{{= || || =}')); - expectTemplateEx(parseFail('{{= || || =')); - expectTemplateEx(parseFail('{{= || || ')); - expectTemplateEx(parseFail('{{= || ||')); - expectTemplateEx(parseFail('{{= || |')); - expectTemplateEx(parseFail('{{= || ')); - expectTemplateEx(parseFail('{{= ||')); - expectTemplateEx(parseFail('{{= |')); - expectTemplateEx(parseFail('{{= ')); - expectTemplateEx(parseFail('{{=')); + expect(()=>attemptLenient('{{#foo}}{{bar}}{{/foo}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{bar}}{{/foo}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{bar}}{{/foo'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{bar}}{{/'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{bar}}{{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{bar}}{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{bar}}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{bar}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{bar'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#foo}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{#'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}{{ / foo }'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}{{ / foo '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}{{ / foo'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}{{ / '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}{{ /'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}{{ '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}{{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar }'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ bar'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{ '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}{'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo }'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # foo'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ # '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ #'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{ '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{'),throwsA(exceptionOfType())); + + expect(()=>attemptLenient('{{= || || =}'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{= || || ='),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{= || || '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{= || ||'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{= || |'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{= || '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{= ||'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{= |'),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{= '),throwsA(exceptionOfType())); + expect(()=>attemptLenient('{{='),throwsA(exceptionOfType())); }); }); }