<commit_before>
fs = require 'fs'
should = require 'should'
mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
test = require './test'

describe 'render', ->

  scratch = test.scratch @
  
  it 'should use `content`', (next) ->
    destination = "#{scratch}/render.eco"
    mecano.render
      content: 'Hello <%- @who %>'
      destination: destination
      context: who: 'you'
    , (err, rendered) ->
      return next err if err
      rendered.should.eql 1
      fs.readFile destination, 'ascii', (err, content) ->
        content.should.eql 'Hello you'
        next()
  
  it 'should use `source`', (next) ->
    destination = "#{scratch}/render.eco"
    mecano.render
      source: "#{__dirname}/../resources/render.eco"
      destination: destination
      context: who: 'you'
    , (err, rendered) ->
      return next err if err
      rendered.should.eql 1
      fs.readFile destination, 'ascii', (err, content) ->
        content.should.eql 'Hello you'
        next()
  
  it 'doesnt increment if destination is same than generated content', (next) ->
    destination = "#{scratch}/render.eco"
    mecano.render
      source: "#{__dirname}/../resources/render.eco"
      destination: destination
      context: who: 'you'
    , (err, rendered) ->
      return next err if err
      rendered.should.eql 1
      mecano.render
        source: "#{__dirname}/../resources/render.eco"
        destination: destination
        context: who: 'you'
      , (err, rendered) ->
        return next err if err
        rendered.should.eql 0
        next()
  
  it 'complain if source doesnt exist', (next) -> 
    mecano.render
      source: "oups"
      destination: "#{scratch}/render.eco"
    , (err, rendered) ->
      err.message.should.eql 'Invalid source, got "oups"'
      next()
  
  it 'accept destination as a callback', (next) ->
    content = null
    mecano.render
      source: "#{__dirname}/../resources/render.eco"
      destination: (c) ->
        content = c
      context: who: 'you'
    , (err, rendered) ->
      content.should.eql 'Hello you'
      next()



<commit_msg>Test parse error in eco rendering<commit_after>
fs = require 'fs'
should = require 'should'
mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
test = require './test'

describe 'render', ->

  scratch = test.scratch @
  
  it 'should use `content`', (next) ->
    destination = "#{scratch}/render.eco"
    mecano.render
      content: 'Hello <%- @who %>'
      destination: destination
      context: who: 'you'
    , (err, rendered) ->
      return next err if err
      rendered.should.eql 1
      fs.readFile destination, 'ascii', (err, content) ->
        content.should.eql 'Hello you'
        next()
  
  it 'should use `source`', (next) ->
    destination = "#{scratch}/render.eco"
    mecano.render
      source: "#{__dirname}/../resources/render.eco"
      destination: destination
      context: who: 'you'
    , (err, rendered) ->
      return next err if err
      rendered.should.eql 1
      fs.readFile destination, 'ascii', (err, content) ->
        content.should.eql 'Hello you'
        next()
  
  it 'doesnt increment if destination is same than generated content', (next) ->
    destination = "#{scratch}/render.eco"
    mecano.render
      source: "#{__dirname}/../resources/render.eco"
      destination: destination
      context: who: 'you'
    , (err, rendered) ->
      return next err if err
      rendered.should.eql 1
      mecano.render
        source: "#{__dirname}/../resources/render.eco"
        destination: destination
        context: who: 'you'
      , (err, rendered) ->
        return next err if err
        rendered.should.eql 0
        next()
  
  it 'accept destination as a callback', (next) ->
    content = null
    mecano.render
      source: "#{__dirname}/../resources/render.eco"
      destination: (c) ->
        content = c
      context: who: 'you'
    , (err, rendered) ->
      content.should.eql 'Hello you'
      next()

  describe 'error', ->
  
    it 'when source doesnt exist', (next) -> 
      mecano.render
        source: "oups"
        destination: "#{scratch}/render.eco"
      , (err, rendered) ->
        err.message.should.eql 'Invalid source, got "oups"'
        next()
  
    it.only 'when syntax is incorrect', (next) -> 
      mecano.render
        content: '<%- @host ->'
        destination: "#{scratch}/render.eco"
        context: toto: 'lulu'
      , (err, rendered) ->
        err.should.eql 'Parse error on line 1: unexpected end of template'
        next()




{'fraction_non_alphanumeric': 0.14010810810810811, 'fraction_numerical': 0.0019459459459459458, 'mean_word_length': 2.244039270687237, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3261862', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1431, 'n_words': 399}