<commit_before># encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

module Gherkin
  module Parser
    describe Table do
      before do
        @listener = Gherkin::SexpRecorder.new
        @table = Table.new(@listener, 1)
      end
    
      tables = {
        "|a|b|\n"        => [%w{a b}],
        "|a|b|c|\n"      => [%w{a b c}],
        "|c|d|\n|e|f|\n" => [%w{c d}, %w{e f}]
      }
    
      tables.each do |text, expected|
        it "should parse #{text}" do
          @listener.should_receive(:table).with(expected, 1)
          @table.scan(text)
        end
      end      
    
      it "should parse a multicharacter cell content" do
        @listener.should_receive(:table).with([%w{foo bar}], 1)
        @table.scan("| foo | bar |\n")
      end
    
      it "should parse cells with spaces within the content" do
        @listener.should_receive(:table).with([["Dill pickle", "Valencia orange"], ["Ruby red grapefruit", "Tire iron"]], 1)
        @table.scan("| Dill pickle | Valencia orange |\n| Ruby red grapefruit | Tire iron |\n")
      end

      it "should parse a 1x2 table with newline" do
        @listener.should_receive(:table).with([%w{1 2}], 1)
        @table.scan("| 1 | 2 |\n")
      end
    
      it "should allow utf-8" do
        @listener.should_receive(:table).with([%w{ůﻚ 2}], 1)
        @table.scan(" | ůﻚ | 2 | \n")
      end

      it "should parse a 2x2 table" do
        @listener.should_receive(:table).with([%w{1 2}, %w{3 4}], 1)
        @table.scan("| 1 | 2 |\n| 3 | 4 |\n")
      end

      it "should parse a 2x2 table with several newlines" do
        @listener.should_receive(:table).with([%w{1 2}, %w{3 4}], 1)
        @table.scan("| 1 | 2 |\n| 3 | 4 |\n\n\n")
      end

      it "should parse a 2x2 table with empty cells" do
        @listener.should_receive(:table).with([['1', nil], [nil, '4']], 1)
        @table.scan("| 1 |  |\n|| 4 |\n")
      end
    
      it "should parse a 1x2 table without newline" do
        @listener.should_receive(:table).with([%w{1 2}], 1)
        @table.scan("| 1 | 2 |")
      end

      it "should parse a 1x2 table without spaces and newline" do
        @listener.should_receive(:table).with([%w{1 2}], 1)
        @table.scan("|1|2|\n")
      end
      
      it "should parse a table with tab spacing" do
        @listener.should_receive(:table).with([["abc", "123"]], 1)
        @table.scan("|\tabc\t|\t123\t\t\t|\n")
      end

      describe "Bad tables" do

        it "should send a table error for rows that aren't closed" do
          @table.scan("|| 4 \n")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "|| 4", 1]
          ]
        end

        it "should send all closed rows after sending the error" do
          @table.scan("| 1 |  |\n| hi | bad\n| 3 | 4 |")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "| hi | bad", 2],
            [:table, [['1', nil],['3','4']], 1]
          ]
        end

        it "should send multiple table errors for rows that aren't closed" do
          @table.scan("|| 4\n|hi|there")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "|| 4", 1],
            [:table_error, "Unclosed table row", "|hi|there", 2],
          ]
        end
        
        it "should allow multiple newlines between error rows and good rows" do
          @table.scan("|| 4\n\n|hi|there\n\n|1|2|")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "|| 4", 1],
            [:table_error, "Unclosed table row", "|hi|there", 3],
            [:table, [['1', '2']], 1]
          ]
        end
         
        it "should not send a good table row if it ends with a newline" do
          @table.scan("|| 4\n|1|2|\n")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "|| 4", 1],
            [:table, [['1', '2']], 1]
          ]
        end
      end
    end
  end
end<commit_msg>Table ParsingError spec failing<commit_after># encoding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

module Gherkin
  module Parser
    describe Table do
      before do
        @listener = Gherkin::SexpRecorder.new
        @table = Table.new(@listener, 1)
      end
    
      tables = {
        "|a|b|\n"        => [%w{a b}],
        "|a|b|c|\n"      => [%w{a b c}],
        "|c|d|\n|e|f|\n" => [%w{c d}, %w{e f}]
      }
    
      tables.each do |text, expected|
        it "should parse #{text}" do
          @listener.should_receive(:table).with(expected, 1)
          @table.scan(text)
        end
      end      
    
      it "should parse a multicharacter cell content" do
        @listener.should_receive(:table).with([%w{foo bar}], 1)
        @table.scan("| foo | bar |\n")
      end
    
      it "should parse cells with spaces within the content" do
        @listener.should_receive(:table).with([["Dill pickle", "Valencia orange"], ["Ruby red grapefruit", "Tire iron"]], 1)
        @table.scan("| Dill pickle | Valencia orange |\n| Ruby red grapefruit | Tire iron |\n")
      end

      it "should parse a 1x2 table with newline" do
        @listener.should_receive(:table).with([%w{1 2}], 1)
        @table.scan("| 1 | 2 |\n")
      end
    
      it "should allow utf-8" do
        @listener.should_receive(:table).with([%w{ůﻚ 2}], 1)
        @table.scan(" | ůﻚ | 2 | \n")
      end

      it "should parse a 2x2 table" do
        @listener.should_receive(:table).with([%w{1 2}, %w{3 4}], 1)
        @table.scan("| 1 | 2 |\n| 3 | 4 |\n")
      end

      it "should parse a 2x2 table with several newlines" do
        @listener.should_receive(:table).with([%w{1 2}, %w{3 4}], 1)
        @table.scan("| 1 | 2 |\n| 3 | 4 |\n\n\n")
      end

      it "should parse a 2x2 table with empty cells" do
        @listener.should_receive(:table).with([['1', nil], [nil, '4']], 1)
        @table.scan("| 1 |  |\n|| 4 |\n")
      end
    
      it "should parse a 1x2 table without newline" do
        @listener.should_receive(:table).with([%w{1 2}], 1)
        @table.scan("| 1 | 2 |")
      end

      it "should parse a 1x2 table without spaces and newline" do
        @listener.should_receive(:table).with([%w{1 2}], 1)
        @table.scan("|1|2|\n")
      end
      
      it "should parse a table with tab spacing" do
        @listener.should_receive(:table).with([["abc", "123"]], 1)
        @table.scan("|\tabc\t|\t123\t\t\t|\n")
      end

      describe "Bad tables" do

        it "should raise ParsingError for rows that aren't closed" do
          lambda { @table.scan("|| 4 \n") }.should raise_error(ParsingError)
        end
        
        it "should send a table error for rows that aren't closed" do
          @table.scan("|| 4 \n")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "|| 4", 1]
          ]
        end

        xit "should send all closed rows after sending the error" do
          @table.scan("| 1 |  |\n| hi | bad\n| 3 | 4 |")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "| hi | bad", 2],
            [:table, [['1', nil],['3','4']], 1]
          ]
        end

        xit "should send multiple table errors for rows that aren't closed" do
          @table.scan("|| 4\n|hi|there")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "|| 4", 1],
            [:table_error, "Unclosed table row", "|hi|there", 2],
          ]
        end
        
        xit "should allow multiple newlines between error rows and good rows" do
          @table.scan("|| 4\n\n|hi|there\n\n|1|2|")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "|| 4", 1],
            [:table_error, "Unclosed table row", "|hi|there", 3],
            [:table, [['1', '2']], 1]
          ]
        end
         
        xit "should not send a good table row if it ends with a newline" do
          @table.scan("|| 4\n|1|2|\n")
          @listener.to_sexp.should == [
            [:table_error, "Unclosed table row", "|| 4", 1],
            [:table, [['1', '2']], 1]
          ]
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.16573714839961204, 'fraction_numerical': 0.02388457807953443, 'mean_word_length': 1.9231041814316088, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '784789', 'n_tokens_mistral': 2965, 'n_tokens_neox': 2744, 'n_words': 795}