# Copyright (c) 2020 Jerome Arbez-Gindre # frozen_string_literal: true require('defmastership/parsing_state') RSpec.describe(DefMastership::ParsingState) do subject(:parsing_state) do described_class.new end describe '.new' do it { is_expected.not_to(be_nil) } end describe '#enabled_with?' do context 'when single line commment' do it { expect(parsing_state.enabled?("//whatever\n")).to(be(false)) } end context 'when starting' do it { expect(parsing_state.enabled?("whatever\n")).to(be(true)) } it { expect(parsing_state.enabled?("----\n")).to(be(false)) } it { expect(parsing_state.enabled?("....\n")).to(be(false)) } it { expect(parsing_state.enabled?("////\n")).to(be(false)) } it { expect(parsing_state.enabled?('....')).to(be(false)) } end context 'when disabled' do before { parsing_state.enabled?("----\n") } it { expect(parsing_state.enabled?("whatever\n")).to(be(false)) } it { expect(parsing_state.enabled?("----\n")).to(be(true)) } it { expect(parsing_state.enabled?("....\n")).to(be(false)) } it { expect(parsing_state.enabled?("////\n")).to(be(false)) } end context 'with intricated disables starting with "...."' do before do ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) } end it { expect(parsing_state.enabled?("----\n")).to(be(false)) } it { expect(parsing_state.enabled?("....\n")).to(be(true)) } end context 'with intricated disables starting with "----"' do before do ["....\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) } end it { expect(parsing_state.enabled?("....\n")).to(be(true)) } end context 'with intricated disables starting with "////"' do before do ["////\n", "----\n", "whatever\n"].each { |line| parsing_state.enabled?(line) } end it { expect(parsing_state.enabled?("////\n")).to(be(true)) } end end end