<commit_before>require File.expand_path('../spec_helper', __FILE__)
describe WLang do

  it "should have a version number" do
    WLang.const_defined?(:VERSION).should be_true
  end

  it 'allows building on-the-fly dialects' do
    d = WLang::dialect do
      tag('$') do |buf, fn| 
        buf << evaluate(fn)
      end
    end
    d.render("Hello ${who}!", :who => "world").should eq("Hello world!")
  end

  it 'allows overriding super-dialect tags' do
    d = WLang::dialect(Upcasing) do
      tag('$') do |buf, fn1| 
        buf << render(fn1).capitalize
      end
    end
    d.render('Hello ${world}!').should eq("Hello World!")
  end

  it 'allows overriding super-dialect evaluation rules' do
    d = WLang::dialect(Upcasing) do
      default_options :evaluator => [:nofail]
    end
    d.render('Hello #{who}!').should eq("Hello !")
  end

  it 'does not override the super-dialect evaluation rules' do
    d = WLang::dialect(Upcasing) do
      default_options :evaluator => [:nofail]
    end
    lambda{ Upcasing.render('Hello #{who}!') }.should raise_error(NameError)
  end

  it 'allows overriding super-dialect evaluation rules at compile time' do
    Upcasing.compile('Hello #{who}!', :evaluator => [:nofail]).render.should eq("Hello !")
  end

end
<commit_msg>Add full-stack test for dialect switching<commit_after>require File.expand_path('../spec_helper', __FILE__)
describe WLang do

  it "should have a version number" do
    WLang.const_defined?(:VERSION).should be_true
  end

  it 'allows building on-the-fly dialects' do
    d = WLang::dialect do
      tag('$') do |buf, fn| 
        buf << evaluate(fn)
      end
    end
    d.render("Hello ${who}!", :who => "world").should eq("Hello world!")
  end

  ### overriding

  it 'allows overriding super-dialect tags' do
    d = WLang::dialect(Upcasing) do
      tag('$') do |buf, fn1| 
        buf << render(fn1).capitalize
      end
    end
    d.render('Hello ${world}!').should eq("Hello World!")
  end

  it 'allows overriding super-dialect evaluation rules' do
    d = WLang::dialect(Upcasing) do
      default_options :evaluator => [:nofail]
    end
    d.render('Hello #{who}!').should eq("Hello !")
  end

  it 'does not override the super-dialect evaluation rules' do
    d = WLang::dialect(Upcasing) do
      default_options :evaluator => [:nofail]
    end
    lambda{ Upcasing.render('Hello #{who}!') }.should raise_error(NameError)
  end

  it 'allows overriding super-dialect evaluation rules at compile time' do
    Upcasing.compile('Hello #{who}!', :evaluator => [:nofail]).render.should eq("Hello !")
  end

  ### high-order and multi-dialects

  it 'allows high-order constructions' do
    d = WLang::dialect do
      tag '!' do |buf,fn| buf << evaluate(fn).to_s; end
    end
    scope = {:who => :world, :world => "World"}
    d.render('Hello !{!{who}}!', scope).should eq("Hello World!")
  end
  
  it 'allows switching the current dialect' do
    d = WLang::dialect do
      tag '!', [Upcasing] do |buf,fn|
        buf << evaluate(Upcasing.render(fn)).to_s;
      end
    end
    scope = {:WHO => "World"}
    d.render('Hello !{${who}}!', scope).should eq("Hello World!")
  end
  
end

{'fraction_non_alphanumeric': 0.14699401951526597, 'fraction_numerical': 0.0012590494176896443, 'mean_word_length': 3.1981505944517834, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, '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': '1157414', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1057, 'n_words': 300}