<commit_before>ColorScanner = require '../lib/color-scanner'
{TextEditor} = require 'atom'

describe 'ColorScanner', ->
  [scanner, editor, bufferColor] = []

  withTextEditor = (fixture, block) ->
    describe "with #{fixture} buffer", ->
      beforeEach ->
        waitsForPromise -> atom.workspace.open(fixture)
        runs -> editor = atom.workspace.getActiveTextEditor()

      afterEach -> editor = null

      do block

  withScannerForTextEditor = (fixture, block) ->
    withTextEditor fixture, ->
      beforeEach -> scanner = new ColorScanner(buffer: editor.getBuffer())

      afterEach -> scanner = null

      do block

  describe '::search', ->
    withScannerForTextEditor 'four-variables.styl', ->
      beforeEach ->
        bufferColor = scanner.search()

      it 'returns the first buffer color match', ->
        expect(bufferColor).toBeDefined()

      describe 'successive searches', ->
        it 'returns a buffer color for each match and then undefined', ->
          expect(scanner.search()).toBeDefined()
          expect(scanner.search()).toBeDefined()
          # expect(scanner.search()).toBeDefined()
          expect(scanner.search()).toBeUndefined()<commit_msg>:white_check_mark: Add tests for buffer color properties<commit_after>ColorScanner = require '../lib/color-scanner'
{TextEditor} = require 'atom'

describe 'ColorScanner', ->
  [scanner, editor, bufferColor] = []

  withTextEditor = (fixture, block) ->
    describe "with #{fixture} buffer", ->
      beforeEach ->
        waitsForPromise -> atom.workspace.open(fixture)
        runs -> editor = atom.workspace.getActiveTextEditor()

      afterEach -> editor = null

      do block

  withScannerForTextEditor = (fixture, block) ->
    withTextEditor fixture, ->
      beforeEach -> scanner = new ColorScanner(buffer: editor.getBuffer())

      afterEach -> scanner = null

      do block

  describe '::search', ->
    withScannerForTextEditor 'four-variables.styl', ->
      beforeEach ->
        bufferColor = scanner.search()

      it 'returns the first buffer color match', ->
        expect(bufferColor).toBeDefined()

      describe 'the resulting buffer color', ->
        it 'has a text range', ->
          expect(bufferColor.textRange).toEqual([8,12])

        it 'has a buffer range', ->
          expect(bufferColor.bufferRange).toEqual([[0, 8],[0, 12]])

        it 'has a color', ->
          expect(bufferColor.color).toBeColor('#ffffff')

        it 'stores the matched text', ->
          expect(bufferColor.match).toEqual('#fff')

      describe 'successive searches', ->
        it 'returns a buffer color for each match and then undefined', ->
          expect(scanner.search()).toBeDefined()
          expect(scanner.search()).toBeDefined()
          # expect(scanner.search()).toBeDefined()
          expect(scanner.search()).toBeUndefined()
{'fraction_non_alphanumeric': 0.1316340782122905, 'fraction_numerical': 0.002793296089385475, 'mean_word_length': 2.804780876494024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 42, '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': '7196509', 'n_tokens_mistral': 810, 'n_tokens_neox': 777, 'n_words': 189}