<commit_before>

require 'minitest/autorun'
require 'yaml'
require_relative '../../../lib/tritium/parser/legacy/reader'
require_relative '../../../lib/tritium/parser/legacy/preprocess'

class ReaderTest < MiniTest::Unit::TestCase
  include Tritium::Parser
  
  def setup
    @reader = Reader.new
  end
  
  def test_blank_script
    output = @reader._read("")
    assert_equal 0, output.children.size
    assert_equal nil, output.parent
  end
  
  def test_single_instruction
    root = @reader._read("html() { select('hi') }")
    output = root.children.first

    assert_equal 1, output.children.size
    assert_equal true, root.root?
    assert_equal false, output.root?
    assert_equal 'select', output.children.first.name
    assert_equal 0, output.children.first.children.size
  end
  
  def test_one_scope
    root = @reader._read("html() { select('./shit') { inner('hello') { remove }; remove } }")
    output = root.children.first
    
    assert_equal 1, output.children.size
    assert_equal 'select', output.children.first.name
    
    select = output.children.first
    
    assert_equal "XMLNode", select.scope.name
    assert_equal 2, select.children.size
    assert_equal 1, select.args.size
    assert_equal './shit', select.args.first
    
    html = select.children.first
    
    assert_equal 1, html.children.size
    assert_equal 'inner', html.name
    assert_equal ['hello'], html.args
    assert_equal "Text", html.scope.name
    
    # Remove should inherit the parent's scope
    html_remove = html.children.last
    assert_equal html.scope, html_remove.scope
    assert_equal 'remove', html_remove.name
    
    remove = select.children.last
    
    assert_equal 'remove', remove.name
    assert_equal [], remove.args
    assert_equal [], remove.children
    assert_equal remove.root, root
    assert_equal "XMLNode", remove.scope.name
  end
  
  def test_debug_lines
    script = preprocess("\n\nhtml() { \n$('./shit') { \inner($hi)\n } }")
    output = @reader._read(script)
    doc = output.children.first
    select = doc.children.first<commit_msg>Updating an old test with new specs.<commit_after>

require 'minitest/autorun'
require 'yaml'
require_relative '../../../lib/tritium/parser/legacy/reader'
require_relative '../../../lib/tritium/parser/legacy/preprocess'

class ReaderTest < MiniTest::Unit::TestCase
  include Tritium::Parser
  
  def setup
    @reader = Reader.new
  end
  
  def test_blank_script
    output = @reader._read("")
    assert_equal 0, output.children.size
    assert_equal nil, output.parent
  end
  
  def test_single_instruction
    root = @reader._read("html() { select('hi') }")
    output = root.children.first

    assert_equal 1, output.children.size
    assert_equal true, root.root?
    assert_equal false, output.root?
    assert_equal 'select', output.children.first.name
    assert_equal 0, output.children.first.children.size
  end
  
  def test_one_scope
    root = @reader._read("html() { select('./shit') { inner('hello') { clear() }; remove() } }")
    output = root.children.first
    
    assert_equal 1, output.children.size
    assert_equal 'select', output.children.first.name
    
    select = output.children.first
    
    assert_equal "XMLNode", select.scope.name
    assert_equal 2, select.children.size
    assert_equal 1, select.args.size
    assert_equal './shit', select.args.first
    
    html = select.children.first
    
    assert_equal 1, html.children.size
    assert_equal 'inner', html.name
    assert_equal ['hello'], html.args
    assert_equal "Text", html.scope.name
    
    # Remove should inherit the parent's scope
    html_remove = html.children.last
    assert_equal html.scope, html_remove.scope
    assert_equal 'clear', html_remove.name
    
    remove = select.children.last
    
    assert_equal 'remove', remove.name
    assert_equal [], remove.args
    assert_equal [], remove.children
    assert_equal remove.root, root
    assert_equal "XMLNode", remove.scope.name
  end
  
  def test_debug_lines
    script = preprocess("\n\nhtml() { \n$('./shit') { \inner($hi)\n } }")
    output = @reader._read(script)
    doc = output.children.first
    select = doc.children.first
{'fraction_non_alphanumeric': 0.12007639054666985, 'fraction_numerical': 0.0033420864168059203, 'mean_word_length': 3.1321499013806706, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7568800', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1289, 'n_words': 283}