Skip to content

Commit

Permalink
Merge pull request #11765 from Microsoft/aozgaa/AddTestForComparingNu…
Browse files Browse the repository at this point in the history
…mericLiteral

add test from comparing numeric literals to branded numbers
  • Loading branch information
aozgaa authored Oct 21, 2016
2 parents 3263fde + 9a9cbe1 commit cef9d85
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 0 deletions.
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;

0 comments on commit cef9d85

Please sign in to comment.