2010-12-29 14:06:57 -05:00
|
|
|
# Number Literals
|
|
|
|
# ---------------
|
|
|
|
|
|
|
|
# * Decimal Integer Literals
|
|
|
|
# * Octal Integer Literals
|
|
|
|
# * Hexadecimal Integer Literals
|
|
|
|
# * Scientific Notation Integer Literals
|
|
|
|
# * Scientific Notation Non-Integer Literals
|
|
|
|
# * Non-Integer Literals
|
2011-10-21 14:44:56 -04:00
|
|
|
# * Binary Integer Literals
|
2010-12-30 22:48:31 -05:00
|
|
|
|
|
|
|
|
2011-10-21 14:44:56 -04:00
|
|
|
# Binary Integer Literals
|
|
|
|
# Binary notation is understood as would be decimal notation.
|
|
|
|
|
|
|
|
test "Parser recognises binary numbers", ->
|
2011-10-21 15:27:08 -04:00
|
|
|
eq 4, 0b100
|
2011-10-21 14:44:56 -04:00
|
|
|
|
2011-03-11 21:41:12 -05:00
|
|
|
# Decimal Integer Literals
|
2010-12-30 22:48:31 -05:00
|
|
|
|
|
|
|
test "call methods directly on numbers", ->
|
|
|
|
eq 4, 4.valueOf()
|
|
|
|
eq '11', 4.toString 3
|
|
|
|
|
|
|
|
eq -1, 3 -4
|
|
|
|
|
|
|
|
#764: Numbers should be indexable
|
|
|
|
eq Number::toString, 42['toString']
|
|
|
|
|
|
|
|
eq Number::toString, 42.toString
|
|
|
|
|
|
|
|
|
2011-03-11 21:41:12 -05:00
|
|
|
# Non-Integer Literals
|
2010-12-30 22:48:31 -05:00
|
|
|
|
|
|
|
# Decimal number literals.
|
|
|
|
value = .25 + .75
|
|
|
|
ok value is 1
|
|
|
|
value = 0.0 + -.25 - -.75 + 0.0
|
|
|
|
ok value is 0.5
|
|
|
|
|
|
|
|
#764: Numbers should be indexable
|
2011-05-24 16:27:07 -04:00
|
|
|
eq Number::toString, 4['toString']
|
2010-12-30 22:48:31 -05:00
|
|
|
eq Number::toString, 4.2['toString']
|
|
|
|
eq Number::toString, .42['toString']
|
2011-05-24 16:27:07 -04:00
|
|
|
eq Number::toString, (4)['toString']
|
2010-12-30 22:48:31 -05:00
|
|
|
|
2011-05-24 16:27:07 -04:00
|
|
|
eq Number::toString, 4.toString
|
2010-12-30 22:48:31 -05:00
|
|
|
eq Number::toString, 4.2.toString
|
|
|
|
eq Number::toString, .42.toString
|
2011-05-24 16:27:07 -04:00
|
|
|
eq Number::toString, (4).toString
|
2011-02-27 02:11:12 -05:00
|
|
|
|
|
|
|
test '#1168: leading floating point suppresses newline', ->
|
|
|
|
eq 1, do ->
|
|
|
|
1
|
|
|
|
.5 + 0.5
|