<commit_before>assert = require('assert')
fs = require('fs')

{jsdom} = require "jsdom"
document = jsdom()

{parser, compile} = HAMLjr = require('../dist/haml-jr')

describe 'HAMLjr', ->
  describe 'parser', ->
    it 'should exist', ->
      assert(parser)

    it 'should parse some stuff', ->
      assert parser.parse("%yolo")

  describe 'samples', ->
    sampleDir = "test/samples/haml"

    fs.readdirSync(sampleDir).forEach (file) ->
      data = fs.readFileSync "#{sampleDir}/#{file}", "UTF-8"
      ast = null

      it "should parse #{file}", ->
        ast = parser.parse(data)
        assert ast

      it "should compile #{file}", ->
        assert compile(ast)

  describe 'compiler', ->
    describe 'keywords', ->
      it "should not replace `items.each` with `items.__each`", ->
        compiled = compile('- items.each ->')

        assert !compiled.match(/items.__each/)

      it "should replace `on 'click'` with `__on 'click'`", ->
        compiled = compile('- on "click", ->')

        assert compiled.match(/__on\("click"/)

  describe "runtime", ->
    it "should not blow up on undefined text node values", ->
      compiled = compile('= @notThere')
      assert eval(compiled)()
<commit_msg>Added some tests for ids and attributes<commit_after>assert = require('assert')
fs = require('fs')

{jsdom} = require "jsdom"
document = jsdom()

{parser, compile} = HAMLjr = require('../dist/haml-jr')

describe 'HAMLjr', ->
  describe 'parser', ->
    it 'should exist', ->
      assert(parser)

    it 'should parse some stuff', ->
      assert parser.parse("%yolo")

  describe 'samples', ->
    sampleDir = "test/samples/haml"

    fs.readdirSync(sampleDir).forEach (file) ->
      data = fs.readFileSync "#{sampleDir}/#{file}", "UTF-8"
      ast = null

      it "should parse #{file}", ->
        ast = parser.parse(data)
        assert ast

      it "should compile #{file}", ->
        assert compile(ast)

  describe 'compiler', ->
    describe 'keywords', ->
      it "should not replace `items.each` with `items.__each`", ->
        compiled = compile('- items.each ->')

        assert !compiled.match(/items.__each/)

      it "should replace `on 'click'` with `__on 'click'`", ->
        compiled = compile('- on "click", ->')

        assert compiled.match(/__on\("click"/)

  describe "runtime", ->
    it "should not blow up on undefined text node values", ->
      compiled = compile('= @notThere')
      assert eval(compiled)()

  describe "classes", ->
    it "should render the classes passed in along with the classes prefixed", ->
      compiled = eval compile(".radical(class=@myClass)")
      result = compiled
        myClass: "duder"

      assert.equal result.childNodes[0].className, "radical duder"

    # TODO: Observable class attributes

  describe "ids", ->
    it "should get them from the prefix", ->
      compiled = eval compile("#radical")
      result = compiled()

      assert.equal result.childNodes[0].id, "radical"

    it "should be overridden by the attribute value if present", ->
      compiled = eval compile("#radical(id=@id)")
      result = compiled
        id: "wat"

      assert.equal result.childNodes[0].id, "wat"

    it "should not be overridden by the attribute value if not present", ->
      compiled = eval compile("#radical(id=@id)")
      result = compiled()

      # TODO
      # assert.equal result.childNodes[0].id, "radical"

    # TODO: Observable id attributes

{'fraction_non_alphanumeric': 0.1557614360162131, 'fraction_numerical': 0.0017371163867979154, 'mean_word_length': 2.695187165775401, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '5857201', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1011, 'n_words': 299}