Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test from comparing numeric literals to branded numbers #11765

Merged
merged 3 commits into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts(5,1): error TS2365: Operator '>' cannot be applied to types 'BrandedNum' and '0'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts(10,1): error TS2365: Operator '<' cannot be applied to types 'BrandedNum' and '0'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts(15,1): error TS2365: Operator '>=' cannot be applied to types 'BrandedNum' and '0'.
tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts(20,1): error TS2365: Operator '<=' cannot be applied to types 'BrandedNum' and '0'.


==== tests/cases/conformance/expressions/binaryOperators/comparisonOperator/comparisonOperatorWithNumericLiteral.ts (4 errors) ====
type BrandedNum = number & { __numberBrand: any };
var x : BrandedNum;

// operator >
x > 0;
~~~~~
!!! error TS2365: Operator '>' cannot be applied to types 'BrandedNum' and '0'.
x > <number>0;
x > <BrandedNum>0;

// operator <
x < 0;
~~~~~
!!! error TS2365: Operator '<' cannot be applied to types 'BrandedNum' and '0'.
x < <number>0;
x < <BrandedNum>0;

// operator >=
x >= 0;
~~~~~~
!!! error TS2365: Operator '>=' cannot be applied to types 'BrandedNum' and '0'.
x >= <number>0;
x >= <BrandedNum>0;

// operator <=
x <= 0;
~~~~~~
!!! error TS2365: Operator '<=' cannot be applied to types 'BrandedNum' and '0'.
x <= <number>0;
x <= <BrandedNum>0;

// operator ==
x == 0;
x == <number>0;
x == <BrandedNum>0;

// operator !=
x != 0;
x != <number>0;
x != <BrandedNum>0;

// operator ===
x === 0;
x === <number>0;
x === <BrandedNum>0;

// operator !==
x !== 0;
x !== <number>0;
x !== <BrandedNum>0;

79 changes: 79 additions & 0 deletions tests/baselines/reference/comparisonOperatorWithNumericLiteral.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//// [comparisonOperatorWithNumericLiteral.ts]
type BrandedNum = number & { __numberBrand: any };
var x : BrandedNum;

// operator >
x > 0;
x > <number>0;
x > <BrandedNum>0;

// operator <
x < 0;
x < <number>0;
x < <BrandedNum>0;

// operator >=
x >= 0;
x >= <number>0;
x >= <BrandedNum>0;

// operator <=
x <= 0;
x <= <number>0;
x <= <BrandedNum>0;

// operator ==
x == 0;
x == <number>0;
x == <BrandedNum>0;

// operator !=
x != 0;
x != <number>0;
x != <BrandedNum>0;

// operator ===
x === 0;
x === <number>0;
x === <BrandedNum>0;

// operator !==
x !== 0;
x !== <number>0;
x !== <BrandedNum>0;


//// [comparisonOperatorWithNumericLiteral.js]
var x;
// operator >
x > 0;
x > 0;
x > 0;
// operator <
x < 0;
x < 0;
x < 0;
// operator >=
x >= 0;
x >= 0;
x >= 0;
// operator <=
x <= 0;
x <= 0;
x <= 0;
// operator ==
x == 0;
x == 0;
x == 0;
// operator !=
x != 0;
x != 0;
x != 0;
// operator ===
x === 0;
x === 0;
x === 0;
// operator !==
x !== 0;
x !== 0;
x !== 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
type BrandedNum = number & { __numberBrand: any };
var x : BrandedNum;

// operator >
x > 0;
x > <number>0;
x > <BrandedNum>0;

// operator <
x < 0;
x < <number>0;
x < <BrandedNum>0;

// operator >=
x >= 0;
x >= <number>0;
x >= <BrandedNum>0;

// operator <=
x <= 0;
x <= <number>0;
x <= <BrandedNum>0;

// operator ==
x == 0;
x == <number>0;
x == <BrandedNum>0;

// operator !=
x != 0;
x != <number>0;
x != <BrandedNum>0;

// operator ===
x === 0;
x === <number>0;
x === <BrandedNum>0;

// operator !==
x !== 0;
x !== <number>0;
x !== <BrandedNum>0;