<commit_before>require 'spec_helper'

module Sisimai
  module Lhost
    module Code
      class << self
        # Imported from p5-Sisimai/t/700-bite-json-code
        def maketest(enginename=nil, isexpected=[], privateset=nil, onlydebugs=false)
          return nil unless enginename
          return nil unless isexpected

          require 'sisimai/mail'
          require 'sisimai/message'
          require 'sisimai/data'

          modulename = nil
          outofemail = %w|ARF RFC3464 RFC3834|
          samplepath = 'set-of-emails/obsoleted'
          emailindex = 0
          mesgmethod = {
            'length' => %w|recipient agent|,
            'exists' => %w|date spec reason status command action alias rhost lhost
              diagnosis feedbacktype softbounce|,
          }
          v = nil

          if outofemail.include? enginename
            # ARF, RFC3464, RFC3834
            require sprintf("sisimai/%s", enginename.downcase)
            modulename = Module.const_get(sprintf("Sisimai::%s", enginename))
            samplepath = sprintf("set-of-emails/private/%s", enginename.downcase) if privateset
          else
            # Other MTA modules
            require sprintf("sisimai/lhost/%s", enginename.downcase)
            modulename = Module.const_get(sprintf("Sisimai::Lhost::%s", enginename))
            samplepath = sprintf("set-of-emails/private/json-%s", enginename.downcase) if privateset
          end

          describe modulename do
            describe '.description' do
              it 'returns String' do
                expect(modulename.description).to be_a Object::String
                expect(modulename.description.size).to be > 0
              end
            end

            if enginename == 'AmasonSES'
              describe '.make' do
                it('returns nil') { expect(modulename.make(nil,nil)).to be nil }
              end
            end
            describe '.json' do
              it('returns nil') { expect(modulename.json(nil)).to be nil }
            end
          end

          isexpected.each do |e|
            # Open each email in set-of-emails/ directory
            samplefile = nil
            jsonstring = nil
            jsonobject = nil
            indexlabel = sprintf("%02d", e['n'].to_i)

            if onlydebugs
              # Debug mode
              emailindex += 1
              next unless onlydebugs.to_i == e['n'].to_i
            end

            if privateset
              # Private sample
              samplefile = Dir.glob(sprintf("./%s/%s-*.json", samplepath, e['n'])).shift
            else
              # Public sample
              if outofemail.include? enginename
                # ARF, RFC3464, RFC3834
                samplefile = sprintf("./%s/%s-%02d.json", samplepath, enginename.downcase, e['n'].to_i)
              else
                # Other MTA modules
                samplefile = sprintf("./%s/json-%s-%02d.json", samplepath, enginename.downcase, e['n'].to_i)
              end
            end

            if privateset
              next unless samplefile
            end

            describe sprintf("%s[%s]", enginename, e['n']) do<commit_msg>Skip tests if ./set-of-emails/obsoleted directory does not exist<commit_after>require 'spec_helper'

module Sisimai
  module Lhost
    module Code
      class << self
        # Imported from p5-Sisimai/t/700-bite-json-code
        def maketest(enginename=nil, isexpected=[], privateset=nil, onlydebugs=false)
          return nil unless enginename
          return nil unless isexpected

          require 'sisimai/mail'
          require 'sisimai/message'
          require 'sisimai/data'

          modulename = nil
          outofemail = %w|ARF RFC3464 RFC3834|
          samplepath = 'set-of-emails/obsoleted'
          emailindex = 0
          mesgmethod = {
            'length' => %w|recipient agent|,
            'exists' => %w|date spec reason status command action alias rhost lhost
              diagnosis feedbacktype softbounce|,
          }
          v = nil

          if outofemail.include? enginename
            # ARF, RFC3464, RFC3834
            require sprintf("sisimai/%s", enginename.downcase)
            modulename = Module.const_get(sprintf("Sisimai::%s", enginename))
            samplepath = sprintf("set-of-emails/private/%s", enginename.downcase) if privateset
          else
            # Other MTA modules
            require sprintf("sisimai/lhost/%s", enginename.downcase)
            modulename = Module.const_get(sprintf("Sisimai::Lhost::%s", enginename))
            samplepath = sprintf("set-of-emails/private/json-%s", enginename.downcase) if privateset
          end

          describe modulename do
            describe '.description' do
              it 'returns String' do
                expect(modulename.description).to be_a Object::String
                expect(modulename.description.size).to be > 0
              end
            end

            if enginename == 'AmasonSES'
              describe '.make' do
                it('returns nil') { expect(modulename.make(nil,nil)).to be nil }
              end
            end
            describe '.json' do
              it('returns nil') { expect(modulename.json(nil)).to be nil }
            end
          end

          isexpected.each do |e|
            # Open each email in set-of-emails/ directory
            samplefile = nil
            jsonstring = nil
            jsonobject = nil
            indexlabel = sprintf("%02d", e['n'].to_i)

            if onlydebugs
              # Debug mode
              emailindex += 1
              next unless onlydebugs.to_i == e['n'].to_i
            end

            if privateset
              # Private sample
              samplefile = Dir.glob(sprintf("./%s/%s-*.json", samplepath, e['n'])).shift
            else
              # Public sample
              if outofemail.include? enginename
                # ARF, RFC3464, RFC3834
                samplefile = sprintf("./%s/%s-%02d.json", samplepath, enginename.downcase, e['n'].to_i)
              else
                # Other MTA modules
                samplefile = sprintf("./%s/json-%s-%02d.json", samplepath, enginename.downcase, e['n'].to_i)
              end
            end
            next unless Dir.exist?(samplepath)

            if privateset
              next unless samplefile
            end

            describe sprintf("%s[%s]", enginename, e['n']) do
{'fraction_non_alphanumeric': 0.09906976744186047, 'fraction_numerical': 0.011472868217054264, 'mean_word_length': 1.6085725839061868, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3940801', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1801, 'n_words': 425}