From c764ae12ab8b716cb3eef845c9ef85a172819414 Mon Sep 17 00:00:00 2001 From: chen ruixiang Date: Thu, 15 Sep 2022 17:22:37 +0800 Subject: [PATCH] fix: add more test coverage for binary expression --- tests/compiler/binary-error.json | 24 ++++++++++++++++++++++++ tests/compiler/binary-error.ts | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/compiler/binary-error.json create mode 100644 tests/compiler/binary-error.ts diff --git a/tests/compiler/binary-error.json b/tests/compiler/binary-error.json new file mode 100644 index 0000000000..e7167c9f36 --- /dev/null +++ b/tests/compiler/binary-error.json @@ -0,0 +1,24 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "TS2365: Operator '<' cannot be applied to types 'binary-error/A | null' and 'i8'.", + "TS2365: Operator '>' cannot be applied to types 'binary-error/A | null' and 'i8'.", + "TS2365: Operator '<=' cannot be applied to types 'binary-error/A | null' and 'i8'.", + "TS2365: Operator '>=' cannot be applied to types 'binary-error/A | null' and 'i8'.", + "TS2365: Operator '==' cannot be applied to types 'binary-error/A | null' and 'i8'.", + "TS2365: Operator '!=' cannot be applied to types 'binary-error/A | null' and 'i8'.", + "TS2365: Operator '+' cannot be applied to types 'i8' and '() => void'.", + "TS2365: Operator '-' cannot be applied to types 'i8' and '() => void'.", + "TS2365: Operator '*' cannot be applied to types 'i8' and '() => void'.", + "TS2365: Operator '**' cannot be applied to types 'i8' and '() => void'.", + "TS2365: Operator '/' cannot be applied to types 'i8' and '() => void'.", + "TS2365: Operator '%' cannot be applied to types 'i8' and '() => void'.", + "TS2469: The '>>' operator cannot be applied to type '() => void'.", + "TS2469: The '<<' operator cannot be applied to type '() => void'.", + "TS2469: The '>>>' operator cannot be applied to type '() => void'.", + "TS2469: The '&' operator cannot be applied to type '() => void'.", + "TS2469: The '|' operator cannot be applied to type '() => void'.", + "TS2469: The '^' operator cannot be applied to type '() => void'." + ] +} diff --git a/tests/compiler/binary-error.ts b/tests/compiler/binary-error.ts new file mode 100644 index 0000000000..d80d32e122 --- /dev/null +++ b/tests/compiler/binary-error.ts @@ -0,0 +1,22 @@ +class A { } +let b: A | null; +let c: i8 = 1; +b < c; // TS2365: Operator '<' cannot be applied to types 'binary-error/A | null' and 'i8'. +b > c; // TS2365: Operator '>' cannot be applied to types 'binary-error/A | null' and 'i8'. +b <= c; // TS2365: Operator '<=' cannot be applied to types 'binary-error/A | null' and 'i8'. +b >= c; // TS2365: Operator '>=' cannot be applied to types 'binary-error/A | null' and 'i8'. +b == c; // TS2365: Operator '==' cannot be applied to types 'binary-error/A | null' and 'i8'. +b != c; // TS2365: Operator '!=' cannot be applied to types 'binary-error/A | null' and 'i8'. +let d: () => void = (): void => { }; +c + d; // TS2365: Operator '+' cannot be applied to types 'i8' and '() => void'. +c - d; // TS2365: Operator '-' cannot be applied to types 'i8' and '() => void'. +c * d; // TS2365: Operator '*' cannot be applied to types 'i8' and '() => void'. +c ** d; // TS2365: Operator '**' cannot be applied to types 'i8' and '() => void'. +c / d; // TS2365: Operator '/' cannot be applied to types 'i8' and '() => void'. +c % d; // TS2365: Operator '%' cannot be applied to types 'i8' and '() => void'. +d >> 1; // TS2469: The '>>' operator cannot be applied to type '() => void'. +d << 1; // TS2469: The '<<' operator cannot be applied to type '() => void'. +d >>> 1; // TS2469: The '>>>' operator cannot be applied to type '() => void'. +d & 1; // TS2469: The '&' operator cannot be applied to type '() => void'. +d | 1; // TS2469: The '|' operator cannot be applied to type '() => void'. +d ^ 1; // TS2469: The '^' operator cannot be applied to type '() => void'.