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-0.2.24 test/lib/services/glob_test.rb
wovnrb-0.2.23 test/lib/services/glob_test.rb
wovnrb-0.2.22 test/lib/services/glob_test.rb
wovnrb-0.2.21 test/lib/services/glob_test.rb
wovnrb-0.2.20 test/lib/services/glob_test.rb
wovnrb-0.2.19 test/lib/services/glob_test.rb
wovnrb-0.2.18 test/lib/services/glob_test.rb
wovnrb-0.2.17 test/lib/services/glob_test.rb
wovnrb-0.2.16 test/lib/services/glob_test.rb
wovnrb-0.2.15 test/lib/services/glob_test.rb
wovnrb-0.2.14 test/lib/services/glob_test.rb
wovnrb-0.2.13 test/lib/services/glob_test.rb
wovnrb-0.2.12 test/lib/services/glob_test.rb
wovnrb-0.2.11 test/lib/services/glob_test.rb
wovnrb-0.2.10 test/lib/services/glob_test.rb