terms = require '../lib/parser/codeGenerator'.code generator ()
should = require 'chai'.should()
sm = require 'source-map'

serialise(code) =
    @new sm.SourceNode (0, 0, 0, code).toString()

(term) should generate (source) generated by (generate) (print: false) =
    code = serialise (generate (term, new (terms.Symbol Scope)))

    if (print)
        console.log (code)

    should.equal (code, source)
    

global.(term) should generate expression (source, options) =
    (term) should generate (source) generated by @(term, scope)
        serialise (term.generate (scope))
    (options)

global.(term) should generate statement (source, options) =
    (term) should generate (source) generated by @(term, scope)
        serialise (term.generate statement (scope))
    (options)

global.(term) should generate statements (source, options) =
    (term) should generate (source) generated by @(term, scope)
        serialise (term.generate statements (scope, in closure: true))
    (options)

global.(term) should generate global statements (source, options) =
    (term) should generate (source) generated by @(term, scope)
        serialise (term.generate statements (scope, global: true))
    (options)

global.(term) should generate module (source, options) =
    (term) should generate (source) generated by @(term)
        serialise (term.generate module ())
    (options)
