<commit_before>package ohmyglob

import (
	"os"
	"testing"

	log "github.com/cihub/seelog"
	"github.com/stretchr/testify/assert"
)

func init() {
	Logger, _ = log.LoggerFromWriterWithMinLevel(os.Stderr, log.TraceLvl)
}

func TestSimpleGlob(t *testing.T) {
	pattern := "foo/*/b?r"
	glob, err := Compile(pattern, nil)
	assert.NoError(t, err)

	match := "foo/baz/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/bbr"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/bdr"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz∆˙¨®˙¨¥ƒ®†˙ƒ†¨®†√˙/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/bar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)

	// With a * as a partial component
	pattern = "foo/*/baz/--foo/--*/--baz"
	glob, err = Compile(pattern, nil)
	assert.NoError(t, err)
	match = "foo/bar/baz/--foo/--bar/--baz"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
}

func TestGlobStar(t *testing.T) {
	pattern := "foo/**/bar/**"
	glob, err := Compile(pattern, nil)
	assert.NoError(t, err)

	match := "foo/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/bar/barrrrr"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/boop/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/boop/µ∂^~®˙¨˙çƒ®†¨^/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "thisistotal/garbage/ÔÔÈ´^¨∆~∆≈∆∫"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
	match = "foobar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
	match = "foobar/bar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
	match = "foo/barbar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)

	// Check consecutive globstars work correctly
	pattern = "foo/**/**/bar"
	glob, err = Compile(pattern, nil)
	assert.NoError(t, err)
	match = "foo/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/boop/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/boop/µ∂^~®˙¨˙çƒ®†¨^/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "thisistotal/garbage/ÔÔÈ´^¨∆~∆≈∆∫"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
	match = "foobar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
}

// Check that setting MatchAtStart to false allows any prefix
func TestNoMatchAtStart(t *testing.T) {
	pattern := "foo"
	glob, err := Compile(pattern, &Options{
		Separator:    DefaultOptions.Separator,
		MatchAtStart: false,
		MatchAtEnd:   DefaultOptions.MatchAtEnd,
	})
	assert.NoError(t, err)

	// Test without a prefix still works
	match := "foo"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)

	// Test with a prefix still works
	match = "bar/baz/foo"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)

	// Test that a prefix and a suffix does not
	match = "bar/baz/foo/boop"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
}<commit_msg>More globstar tests (covering the special head/tail cases)<commit_after>package ohmyglob

import (
	"os"
	"testing"

	log "github.com/cihub/seelog"
	"github.com/stretchr/testify/assert"
)

func init() {
	Logger, _ = log.LoggerFromWriterWithMinLevel(os.Stderr, log.TraceLvl)
}

func TestSimpleGlob(t *testing.T) {
	pattern := "foo/*/b?r"
	glob, err := Compile(pattern, nil)
	assert.NoError(t, err)

	match := "foo/baz/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/bbr"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/bdr"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz∆˙¨®˙¨¥ƒ®†˙ƒ†¨®†√˙/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/bar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)

	// With a * as a partial component
	pattern = "foo/*/baz/--foo/--*/--baz"
	glob, err = Compile(pattern, nil)
	assert.NoError(t, err)
	match = "foo/bar/baz/--foo/--bar/--baz"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
}

func TestGlobStar(t *testing.T) {
	pattern := "foo/**/bar/**"
	glob, err := Compile(pattern, nil)
	assert.NoError(t, err)

	match := "foo/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/bar/barrrrr"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/boop/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/boop/µ∂^~®˙¨˙çƒ®†¨^/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "thisistotal/garbage/ÔÔÈ´^¨∆~∆≈∆∫"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
	match = "foobar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
	match = "foobar/bar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
	match = "foo/barbar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)

	// Check consecutive globstars work correctly
	pattern = "foo/**/**/bar"
	glob, err = Compile(pattern, nil)
	assert.NoError(t, err)
	match = "foo/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/boop/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/baz/boop/µ∂^~®˙¨˙çƒ®†¨^/bar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "thisistotal/garbage/ÔÔÈ´^¨∆~∆≈∆∫"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
	match = "foobar"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)

	// Globstar at the head
	pattern = "**/**/foobar"
	glob, err = Compile(pattern, nil)
	assert.NoError(t, err)
	match = "foobar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/foobar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foo/bar/foo/bar/foobar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)

	// Globstar at the tail
	pattern = "foobar/**/**"
	glob, err = Compile(pattern, nil)
	assert.NoError(t, err)
	match = "foobar"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foobar/baz/boo"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
	match = "foobar/baz"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)
}

// Check that setting MatchAtStart to false allows any prefix
func TestNoMatchAtStart(t *testing.T) {
	pattern := "foo"
	glob, err := Compile(pattern, &Options{
		Separator:    DefaultOptions.Separator,
		MatchAtStart: false,
		MatchAtEnd:   DefaultOptions.MatchAtEnd,
	})
	assert.NoError(t, err)

	// Test without a prefix still works
	match := "foo"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)

	// Test with a prefix still works
	match = "bar/baz/foo"
	assert.True(t, glob.MatchString(match), "%s should match %s", pattern, match)

	// Test that a prefix and a suffix does not
	match = "bar/baz/foo/boop"
	assert.False(t, glob.MatchString(match), "%s should not match %s", pattern, match)
}
{'fraction_non_alphanumeric': 0.18323239520247, 'fraction_numerical': 0.0, 'mean_word_length': 4.70209884901828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1243803', 'n_tokens_mistral': 3234, 'n_tokens_neox': 3215, 'n_words': 805}