package generatedmarker

import (
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestHasInFileScansGeneratedMarkerNearHead(t *testing.T) {
	t.Parallel()

	dir := t.TempDir()
	path := filepath.Join(dir, "generated.go")
	require.NoError(t, os.WriteFile(path, []byte(`// Copyright 2026 trevin-chow.
// SPDX-License-Identifier: Apache-2.0
// Extra generated preamble.
// Generated by CLI Printing Press (https://github.com/mvanhorn/cli-printing-press). DO NOT EDIT.
package cli
`), 0o644))

	assert.True(t, HasInFile(path))
}

func TestHasInFileIgnoresHandAuthoredFile(t *testing.T) {
	t.Parallel()

	dir := t.TempDir()
	path := filepath.Join(dir, "novel.go")
	require.NoError(t, os.WriteFile(path, []byte("package cli\n\nfunc novel() {}\n"), 0o644))

	assert.False(t, HasInFile(path))
}
