<commit_before>if window?
  parser = require 'gss-compiler'
else
  chai = require 'chai' unless chai
  parser = require '../lib/gss-compiler'

{assert, expect} = chai


describe 'GSS compiler', ->
  it 'should provide the compile method', ->
    chai.expect(parser.compile).to.be.a 'function'
  
  describe 'with a statement containing only CCSS', ->
    statement = '#box[right] == #box2[left];'
    ast = [
      {     
        type: 'constraint'
        cssText: '#box[right] == #box2[left];'
        selectors: [
          '#box'
          '#box2'
        ]
        commands: [
          ['eq', ['get$','right',['$id','box']],['get$','x',['$id','box2']]]
        ]
      }    
    ]  
    it 'should be able to produce correct AST', ->
      results = parser.compile statement
      expect(ast).to.deep.equal results
      #assert results[0]._uuid? is true, 'has uuid'<commit_msg>Add spec helper function for expecting errors.<commit_after>if window?
  parser = require 'gss-compiler'
else
  chai = require 'chai' unless chai
  parser = require '../lib/gss-compiler'

{assert, expect} = chai


# Helper function for expecting errors to be thrown when parsing.
#
# @param source [String] GSS statements.
# @param name [String] The name of the expected error.
# @param [Boolean] Whether the spec should be treated as pending.
#
expectError = (source, name, pending) ->
  itFn = if pending then xit else it

  describe name, ->
    itFn 'should throw an error', ->
      exercise = -> parser.compile source
      expect(exercise).to.throw Error

      try
        exercise()
      catch error
        expect(error.name).to.equal name


describe 'GSS compiler', ->
  it 'should provide the compile method', ->
    chai.expect(parser.compile).to.be.a 'function'
  
  describe 'with a statement containing only CCSS', ->
    statement = '#box[right] == #box2[left];'
    ast = [
      {     
        type: 'constraint'
        cssText: '#box[right] == #box2[left];'
        selectors: [
          '#box'
          '#box2'
        ]
        commands: [
          ['eq', ['get$','right',['$id','box']],['get$','x',['$id','box2']]]
        ]
      }    
    ]  
    it 'should be able to produce correct AST', ->
      results = parser.compile statement
      expect(ast).to.deep.equal results
      #assert results[0]._uuid? is true, 'has uuid'
{'fraction_non_alphanumeric': 0.15085470085470085, 'fraction_numerical': 0.004273504273504274, 'mean_word_length': 2.4528023598820057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1264707', 'n_tokens_mistral': 731, 'n_tokens_neox': 725, 'n_words': 206}