$:.unshift File.dirname(__FILE__) # required, for some reason.
require 'spec_helper'

$:.unshift File.dirname(__FILE__) + "/../ext/balance_tags_c"
require "balance_tags_c.so"

describe "BalanceTagsCExtension" do
  describe "text without tags" do
    it "should be left untouched" do
      text = "Foo bar baz, this is my excellent test text!"
      Pidgin2Adium.balance_tags_c(text).should == text
    end
  end

  describe "text with tags" do
    it "should be balanced correctly" do
      Pidgin2Adium.balance_tags_c('<p><b>this is unbalanced!').should == "<p><b>this is unbalanced!</b></p>"
    end

    # Make sure it doesn't segfault
    it "should be balanced correctly when run many times" do
      2_000.times do
        text = Faker::Lorem.paragraphs(3)
        Pidgin2Adium.balance_tags_c("<p><b>#{text}").should == "<p><b>#{text}</b></p>"
      end
    end
  end
end

$:.unshift File.dirname(__FILE__) # required, for some reason.
require 'spec_helper'

$:.unshift File.dirname(__FILE__) + "/../ext/balance_tags_c"
require "balance_tags_c.so"

describe "BalanceTagsCExtension" do
  describe "text without tags" do
    it "should be left untouched" do
      text = "Foo bar baz, this is my excellent test text!"
      Pidgin2Adium.balance_tags_c(text).should == text
    end
  end

  describe "text with tags" do
    it "should be balanced correctly" do
      Pidgin2Adium.balance_tags_c('<p><b>this is unbalanced!').should == "<p><b>this is unbalanced!</b></p>"
    end

    # Make sure it doesn't segfault
    it "should be balanced correctly when run many times" do
      text = Faker::Lorem.paragraphs(6)
      2_000.times do
        Pidgin2Adium.balance_tags_c("<p><b>#{text}").should == "<p><b>#{text}</b></p>"
      end
    end
  end
end

Move Faker::Lorem call out of block to speed up balance_tags_c spec dramatically
Move Faker::Lorem call out of block to speed up balance_tags_c spec dramatically
