From 5f4d476ad0a93cea93cb6da94ffaf55a50937ac5 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Tue, 4 Mar 2014 10:12:09 -0800 Subject: [PATCH] add posmap matching specs --- spec/error_rewriting_spec.moon | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec/error_rewriting_spec.moon b/spec/error_rewriting_spec.moon index d2f55c9..3c6d128 100644 --- a/spec/error_rewriting_spec.moon +++ b/spec/error_rewriting_spec.moon @@ -3,6 +3,8 @@ moonscript = require "moonscript.base" errors = require "moonscript.errors" util = require "moonscript.util" +import unindent from require "spec.helpers" + get_rewritten_line_no = (fname) -> fname = "spec/error_inputs/#{fname}.moon" chunk = moonscript.loadfile fname @@ -28,3 +30,35 @@ describe "error rewriting", -> it "should rewrite line number", -> assert.same get_rewritten_line_no(name), expected_no +describe "line map", -> + import to_lua from require "moonscript.base" + + it "should create line table", -> + moon_code = unindent [[ + print "hello world" + if something + print "cats" + ]] + + lua_code, posmap = assert to_lua moon_code + -- print util.debug_posmap(posmap, moon_code, lua_code) + assert.same { 7, 29, 42, 27 }, posmap + + it "should create line table for multiline string", -> + moon_code = unindent [[ + print "one" + x = [==[ + one + two + thre + yes + no + ]==] + print "two" + ]] + + lua_code, posmap = assert to_lua moon_code + -- print util.debug_posmap(posmap, moon_code, lua_code) + assert.same {[1]: 7, [7]: 19, [8]: 63}, posmap + +