1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/sourcemap.coffee
2013-02-28 15:51:29 -05:00

39 lines
1.3 KiB
CoffeeScript

sourcemap = require '../src/sourcemap'
vlqEncodedValues = [
[1, "C"],
[-1, "D"],
[2, "E"],
[-2, "F"],
[0, "A"],
[16, "gB"],
[948, "o7B"]
]
test "vlqEncodeValue tests", ->
for pair in vlqEncodedValues
eq (sourcemap.vlqEncodeValue pair[0]), pair[1]
test "vlqDecodeValue tests", ->
for pair in vlqEncodedValues
arrayEq (sourcemap.vlqDecodeValue pair[1]), [pair[0], pair[1].length]
test "vlqDecodeValue with offset", ->
for pair in vlqEncodedValues
# Try with an offset, and some cruft at the end.
arrayEq (sourcemap.vlqDecodeValue ("abc" + pair[1] + "efg"), 3), [pair[0], pair[1].length]
test "SourceMap tests", ->
map = new sourcemap.SourceMap()
map.addMapping [0, 0], [0, 0]
map.addMapping [1, 5], [2, 4]
map.addMapping [1, 6], [2, 7]
map.addMapping [1, 9], [2, 8]
map.addMapping [3, 0], [3, 4]
eq (sourcemap.generateV3SourceMap map, "source.coffee", "source.js"), '{"version":3,"file":"source.js","sourceRoot":"","source":["source.coffee"],"names":[],"mappings":"AAAA;;IACK,GAAC,CAAG;IAET"}'
# Look up a generated column - should get back the original source position.
arrayEq map.getSourcePosition([2,8]), [1,9]
# Look up a point futher along on the same line - should get back the same source position.
arrayEq map.getSourcePosition([2,10]), [1,9]