<commit_before>RefCountedTokenList = require '../lib/ref-counted-token-list'

describe 'RefCountedTokenList', ->
  [list] = []
  beforeEach ->
    list = new RefCountedTokenList

  describe "when words are added and removed from the list", ->
    it "maintains the word in the list until there are no more references", ->
      expect(list.getTokens()).toEqual []

      list.addToken('abc')
      expect(list.getTokens()).toEqual ['abc']

      list.addToken('abc')
      list.addToken('def')
      expect(list.getTokens()).toEqual ['abc', 'def']

      list.removeToken('abc')
      expect(list.getTokens()).toEqual ['abc', 'def']

      list.removeToken('def')
      expect(list.getTokens()).toEqual ['abc']

      list.removeToken('abc')
      expect(list.getTokens()).toEqual []

      list.removeToken('abc')
      expect(list.getTokens()).toEqual []
<commit_msg>Add another spec to the reference counter<commit_after>RefCountedTokenList = require '../lib/ref-counted-token-list'

describe 'RefCountedTokenList', ->
  [list] = []
  beforeEach ->
    list = new RefCountedTokenList

  describe "when tokens are added to and removed from the list", ->
    it "maintains the token in the list until there are no more references", ->
      expect(list.getTokens()).toEqual []

      list.addToken('abc')
      expect(list.getTokens()).toEqual ['abc']

      list.addToken('abc')
      list.addToken('def')
      expect(list.getTokens()).toEqual ['abc', 'def']

      list.removeToken('abc')
      expect(list.getTokens()).toEqual ['abc', 'def']

      list.removeToken('def')
      expect(list.getTokens()).toEqual ['abc']

      list.removeToken('abc')
      expect(list.getTokens()).toEqual []

      list.removeToken('abc')
      expect(list.getTokens()).toEqual []

  describe "when object tokens are added to and removed from the list", ->
    it "maintains the token in the list until there are no more references", ->
      expect(list.getTokens()).toEqual []

      abcToken = {text: 'abc'}
      defToken = {text: 'def'}
      list.addToken(abcToken, 'text')
      expect(list.getTokens()).toEqual [abcToken]

      list.addToken(abcToken, 'text')
      list.addToken(defToken, 'text')
      expect(list.getTokens()).toEqual [abcToken, defToken]

      list.removeToken(abcToken, 'text')
      expect(list.getTokens()).toEqual [abcToken, defToken]

      list.removeToken(defToken, 'text')
      expect(list.getTokens()).toEqual [abcToken]

      list.removeToken(abcToken, 'text')
      expect(list.getTokens()).toEqual []

      list.removeToken(abcToken, 'text')
      expect(list.getTokens()).toEqual []

{'fraction_non_alphanumeric': 0.15425735013363878, 'fraction_numerical': 0.0, 'mean_word_length': 3.3021346469622332, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '7377643', 'n_tokens_mistral': 776, 'n_tokens_neox': 791, 'n_words': 171}