Sha256: 75849c0b6138876a916dbf4528b2ed0d11a90c7527cc91ca3bffd69f886262d0

Contents?: true

Size: 1.48 KB

Versions: 35

Compression:

Stored size: 1.48 KB

Contents

require 'test_helper'
require 'wovnrb/services/glob'

module Wovnrb
  class GlobTest < WovnMiniTest
    def test_match
      assert_equal(false, Glob.new('api/*').match?('api'))
      assert_equal(true, Glob.new('api/*').match?('api/'))
      assert_equal(true, Glob.new('api/*').match?('api/a'))
      assert_equal(false, Glob.new('api/*').match?('api/a/b'))
      assert_equal(true, Glob.new('api/*.html').match?('api/a.html'))
      assert_equal(false, Glob.new('api/*.html').match?('api/a/b.html'))
    end

    def test_match_2_star
      assert_equal(false, Glob.new('api/**/*').match?('api'))
      assert_equal(true, Glob.new('api/**/*').match?('api/'))
      assert_equal(true, Glob.new('api/**/*').match?('api/a'))
      assert_equal(true, Glob.new('api/**/*').match?('api/a/b'))
      assert_equal(true, Glob.new('api/**/*.html').match?('api/a.html'))
      assert_equal(true, Glob.new('api/**/*.html').match?('api/a/b.html'))
      assert_equal(false, Glob.new('api/**/*.html').match?('api/a/b'))
      assert_equal(true, Glob.new('api/**').match?('api/a'))
      assert_equal(true, Glob.new('api/**').match?('api/a/b.html'))
    end

    def test_match_regex_injection
      assert_equal(false, Glob.new('api/a?*').match?('api/a'))
      assert_equal(true, Glob.new('api/a?*').match?('api/a?'))
      assert_equal(true, Glob.new('api/a?*').match?('api/a?b'))
      assert_equal(false, Glob.new('api/**?').match?('api/a'))
      assert_equal(true, Glob.new('api/**?').match?('api/?'))
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
wovnrb-1.1.0 test/lib/services/glob_test.rb
wovnrb-1.0.13 test/lib/services/glob_test.rb
wovnrb-1.0.12 test/lib/services/glob_test.rb
wovnrb-1.0.11 test/lib/services/glob_test.rb
wovnrb-1.0.10 test/lib/services/glob_test.rb
wovnrb-1.0.9 test/lib/services/glob_test.rb
wovnrb-1.0.8 test/lib/services/glob_test.rb
wovnrb-1.0.7 test/lib/services/glob_test.rb
wovnrb-1.0.6 test/lib/services/glob_test.rb
wovnrb-1.0.5 test/lib/services/glob_test.rb
wovnrb-1.0.4 test/lib/services/glob_test.rb
wovnrb-1.0.2 test/lib/services/glob_test.rb
wovnrb-1.0.1 test/lib/services/glob_test.rb
wovnrb-1.0.0 test/lib/services/glob_test.rb
wovnrb-0.2.30 test/lib/services/glob_test.rb
wovnrb-0.2.29 test/lib/services/glob_test.rb
wovnrb-0.2.28 test/lib/services/glob_test.rb
wovnrb-0.2.27 test/lib/services/glob_test.rb
wovnrb-0.2.26 test/lib/services/glob_test.rb
wovnrb-0.2.25 test/lib/services/glob_test.rb