From 4a1999562ac66bba67688c5af2f0201fe6ca8323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 15 Jan 2025 15:03:09 +0100 Subject: [PATCH] Add specs for `File.match?` --- spec/std/file_spec.cr | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/std/file_spec.cr b/spec/std/file_spec.cr index 0f88b2028c2f..fe572e710084 100644 --- a/spec/std/file_spec.cr +++ b/spec/std/file_spec.cr @@ -1698,6 +1698,11 @@ describe "File" do assert_file_matches "a*", "abc" assert_file_matches "a*/b", "abc/b" assert_file_matches "*x", "xxx" + assert_file_matches "*.x", "a.x" + assert_file_matches "a/b/*.x", "a/b/c.x" + refute_file_matches "*.x", "a/b/c.x" + refute_file_matches "c.x", "a/b/c.x" + refute_file_matches "b/*.x", "a/b/c.x" end it "matches multiple expansions" do @@ -1719,6 +1724,21 @@ describe "File" do refute_file_matches "a*b*c*d*e*/f", "axbxcxdxexxx/fff" end + it "**" do + assert_file_matches "a/b/**", "a/b/c.x" + assert_file_matches "a/**", "a/b/c.x" + assert_file_matches "a/**/d.x", "a/b/c/d.x" + refute_file_matches "a/**b/d.x", "a/bb/c/d.x" + refute_file_matches "a/b**/*", "a/bb/c/d.x" + end + + it "** bugs (#15319)" do + refute_file_matches "a/**/*", "a/b/c/d.x" + assert_file_matches "a/b**/d.x", "a/bb/c/d.x" + refute_file_matches "**/*.x", "a/b/c.x" + assert_file_matches "**.x", "a/b/c.x" + end + it "** matches path separator" do assert_file_matches "a**", "ab/c" assert_file_matches "a**/b", "a/c/b"