require "test_helper" module RegexpPreview class MultilineTest < ActiveSupport::TestCase test "simple usage" do config = { "format_firstline" => "/foo/", "time_format" => "time_format", } config["format1"] = "/(?foo)\n/" config["format2"] = "/(?bar)/" 3.upto(Fluentd::Setting::InTail::MULTI_LINE_MAX_FORMAT_COUNT) do |i| config["format#{i}"] = "//" end preview = RegexpPreview::MultiLine.new(fixture_path("error0.log"), "multiline", config) matches = [ { whole: "foo\nbar\nbaz\n1\n2\n3\n4\n5\n6\n10\n11\n12", matches: [ { key: "foo", matched: "foo", pos: [0, 3] }, { key: "bar", matched: "bar", pos: [4, 7] } ] } ] assert_equal(matches, preview.matches[:matches]) end test "detect only continuous patterns" do config = { "format_firstline" => "/foo/", "time_format" => "time_format", } config["format1"] = "/(?foo)\n/" config["format2"] = "/(?baz)/" 3.upto(Fluentd::Setting::InTail::MULTI_LINE_MAX_FORMAT_COUNT) do |i| config["format#{i}"] = "//" end preview = RegexpPreview::MultiLine.new(fixture_path("error0.log"), "multiline", config) assert_equal([], preview.matches[:matches]) end # http://docs.fluentd.org/articles/in_tail test "example on document" do config = { "format_firstline" => "/\\d{4}-\\d{1,2}-\\d{1,2}/", "format1" => "/^(?