Sha256: 66004ea1cb55afb871a6942fd7aad685be9140d42984d4d50fe88a508593ee1b

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe Textpow do
  before do
    Textpow.send(:class_variable_set, "@@syntax", {})
  end

  it "has a version" do
    Textpow::Version =~ /^\d\.\d\.\d$/
  end

  it "has syntax files named after their scopeName" do
    Dir["#{Textpow.syntax_path}/*"].each do |file|
      next if File.directory?(file)
      (YAML.load_file(file)['scopeName'] + '.syntax').should == File.basename(file)
    end
  end

  describe "syntax" do
    it "finds syntax by path" do
      Textpow.syntax('lib/textpow/syntax/source.ruby.syntax').name.should == 'Ruby'
    end

    it "finds a syntax by scopeName" do
      Textpow.syntax('source.ruby').name.should == 'Ruby'
    end

    it "caches found syntax" do
      Textpow.syntax('ruby').name.should == 'Ruby'
      Dir.should_not_receive(:glob)
      Textpow.syntax('ruby').name.should == 'Ruby'
    end

    it "finds a syntax by name parts" do
      Textpow.syntax('ruby').name.should == 'Ruby'
    end

    it "returns the found syntax for mixed case" do
      Textpow.syntax('RuBy').name.should == 'Ruby'
    end

    it "returns nil for unfound syntax" do
      Textpow.syntax('buby').should == nil
    end

    it "caches nil for unfound syntax" do
      Dir.should_receive(:glob).and_return []
      Textpow.syntax('buby').should == nil
      Dir.should_not_receive(:glob)
      Textpow.syntax('buby').should == nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
textpow1x-1.2.3 spec/textpow_spec.rb
textpow1x-1.2.2 spec/textpow_spec.rb
textpow1x-1.2.1 spec/textpow_spec.rb
textpow1x-1.2.0 spec/textpow_spec.rb