<commit_before><commit_msg>spec: clear_spec<commit_after>require 'spec_helper'

require_relative '../../src/compiler/_requires.rb'

describe DabNode do
  it 'sets parent on clear' do
    node1 = DabNodeSymbol.new(:node1)
    node2 = DabNodeSymbol.new(:node2)
    node3 = DabNodeSymbol.new(:node3)
    node4 = DabNodeSymbol.new(:node4)
    node5 = DabNodeSymbol.new(:node5)

    node1 << node2
    node1 << node3
    node2 << node4
    node2 << node5

    expect(node1.root).to eq(node1)
    expect(node2.root).to eq(node1)
    expect(node3.root).to eq(node1)
    expect(node4.root).to eq(node1)
    expect(node5.root).to eq(node1)

    expect(node1.parent).to eq(nil)
    expect(node2.parent).to eq(node1)
    expect(node3.parent).to eq(node1)
    expect(node4.parent).to eq(node2)
    expect(node5.parent).to eq(node2)

    node2.remove!

    expect(node1.root).to eq(node1)
    expect(node2.root).to eq(node2)
    expect(node3.root).to eq(node1)
    expect(node4.root).to eq(node2)
    expect(node5.root).to eq(node2)

    expect(node1.parent).to eq(nil)
    expect(node2.parent).to eq(nil)
    expect(node3.parent).to eq(node1)
    expect(node4.parent).to eq(node2)
    expect(node5.parent).to eq(node2)
  end

  it 'sets parent on dup' do
    node1 = DabNodeSymbol.new(:node1)
    node2 = DabNodeSymbol.new(:node2)
    node3 = DabNodeSymbol.new(:node3)
    node4 = DabNodeSymbol.new(:node4)
    node5 = DabNodeSymbol.new(:node5)

    node1 << node2
    node1 << node3
    node2 << node4
    node2 << node5

    expect(node1.root).to eq(node1)
    expect(node2.root).to eq(node1)
    expect(node3.root).to eq(node1)
    expect(node4.root).to eq(node1)
    expect(node5.root).to eq(node1)

    expect(node1.parent).to eq(nil)
    expect(node2.parent).to eq(node1)
    expect(node3.parent).to eq(node1)
    expect(node4.parent).to eq(node2)
    expect(node5.parent).to eq(node2)

    node6 = node2.dup
    node1 << node6

    expect(node1.root).to eq(node1)
    expect(node2.root).to eq(node1)
    expect(node3.root).to eq(node1)
    expect(node4.root).to eq(node1)
    expect(node5.root).to eq(node1)
    expect(node6.root).to eq(node1)

    expect(node1.parent).to eq(nil)
    expect(node2.parent).to eq(node1)
    expect(node3.parent).to eq(node1)
    expect(node4.parent).to eq(node2)
    expect(node5.parent).to eq(node2)
    expect(node6.parent).to eq(node1)
  end
end
{'fraction_non_alphanumeric': 0.14652631578947367, 'fraction_numerical': 0.05052631578947368, 'mean_word_length': 3.335766423357664, 'pattern_counts': {'":': 0, '<': 21, '<?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': '7432034', 'n_tokens_mistral': 944, 'n_tokens_neox': 929, 'n_words': 148}