<commit_before>package excelize_test

import (
	"fmt"
	"path/filepath"
	"strings"
	"testing"

	"github.com/360EntSecGroup-Skylar/excelize/v2"
	"github.com/mohae/deepcopy"
	"github.com/stretchr/testify/assert"
)

func ExampleFile_SetPageLayout() {
	f := excelize.NewFile()

	if err := f.SetPageLayout(
		"Sheet1",
		excelize.PageLayoutOrientation(excelize.OrientationLandscape),
	); err != nil {
		panic(err)
	}
	if err := f.SetPageLayout(
		"Sheet1",
		excelize.PageLayoutPaperSize(10),
	); err != nil {
		panic(err)
	}
	// Output:
}

func ExampleFile_GetPageLayout() {
	f := excelize.NewFile()
	var (
		orientation excelize.PageLayoutOrientation
		paperSize   excelize.PageLayoutPaperSize
	)
	if err := f.GetPageLayout("Sheet1", &orientation); err != nil {
		panic(err)
	}
	if err := f.GetPageLayout("Sheet1", &paperSize); err != nil {
		panic(err)
	}
	fmt.Println("Defaults:")
	fmt.Printf("- orientation: %q\n", orientation)
	fmt.Printf("- paper size: %d\n", paperSize)
	// Output:
	// Defaults:
	// - orientation: "portrait"
	// - paper size: 1
}

func TestPageLayoutOption(t *testing.T) {
	const sheet = "Sheet1"

	testData := []struct {
		container  excelize.PageLayoutOptionPtr
		nonDefault excelize.PageLayoutOption
	}{
		{new(excelize.PageLayoutOrientation), excelize.PageLayoutOrientation(excelize.OrientationLandscape)},
		{new(excelize.PageLayoutPaperSize), excelize.PageLayoutPaperSize(10)},
	}

	for i, test := range testData {
		t.Run(fmt.Sprintf("TestData%d", i), func(t *testing.T) {

			opt := test.nonDefault
			t.Logf("option %T", opt)

			def := deepcopy.Copy(test.container).(excelize.PageLayoutOptionPtr)
			val1 := deepcopy.Copy(def).(excelize.PageLayoutOptionPtr)
			val2 := deepcopy.Copy(def).(excelize.PageLayoutOptionPtr)

			f := excelize.NewFile()
			// Get the default value
			assert.NoError(t, f.GetPageLayout(sheet, def), opt)
			// Get again and check
			assert.NoError(t, f.GetPageLayout(sheet, val1), opt)
			if !assert.Equal(t, val1, def, opt) {
				t.FailNow()
			}
			// Set the same value
			assert.NoError(t, f.SetPageLayout(sheet, val1), opt)
			// Get again and check
			assert.NoError(t, f.GetPageLayout(sheet, val1), opt)
			if !assert.Equal(t, val1, def, "%T: value should not have changed", opt) {<commit_msg>Add unit test for SetPageLayout<commit_after>package excelize_test

import (
	"fmt"
	"path/filepath"
	"strings"
	"testing"

	"github.com/360EntSecGroup-Skylar/excelize/v2"
	"github.com/mohae/deepcopy"
	"github.com/stretchr/testify/assert"
)

func ExampleFile_SetPageLayout() {
	f := excelize.NewFile()

	if err := f.SetPageLayout(
		"Sheet1",
		excelize.PageLayoutOrientation(excelize.OrientationLandscape),
	); err != nil {
		panic(err)
	}
	if err := f.SetPageLayout(
		"Sheet1",
		excelize.PageLayoutPaperSize(10),
		excelize.FitToHeight(2),
		excelize.FitToWidth(2),
	); err != nil {
		panic(err)
	}
	// Output:
}

func ExampleFile_GetPageLayout() {
	f := excelize.NewFile()
	var (
		orientation excelize.PageLayoutOrientation
		paperSize   excelize.PageLayoutPaperSize
		fitToHeight excelize.FitToHeight
		fitToWidth  excelize.FitToWidth
	)
	if err := f.GetPageLayout("Sheet1", &orientation); err != nil {
		panic(err)
	}
	if err := f.GetPageLayout("Sheet1", &paperSize); err != nil {
		panic(err)
	}
	if err := f.GetPageLayout("Sheet1", &fitToHeight); err != nil {
		panic(err)
	}

	if err := f.GetPageLayout("Sheet1", &fitToWidth); err != nil {
		panic(err)
	}
	fmt.Println("Defaults:")
	fmt.Printf("- orientation: %q\n", orientation)
	fmt.Printf("- paper size: %d\n", paperSize)
	fmt.Printf("- fit to height: %d\n", fitToHeight)
	fmt.Printf("- fit to width: %d\n", fitToWidth)
	// Output:
	// Defaults:
	// - orientation: "portrait"
	// - paper size: 1
	// - fit to height: 1
	// - fit to width: 1
}

func TestPageLayoutOption(t *testing.T) {
	const sheet = "Sheet1"

	testData := []struct {
		container  excelize.PageLayoutOptionPtr
		nonDefault excelize.PageLayoutOption
	}{
		{new(excelize.PageLayoutOrientation), excelize.PageLayoutOrientation(excelize.OrientationLandscape)},
		{new(excelize.PageLayoutPaperSize), excelize.PageLayoutPaperSize(10)},
		{new(excelize.FitToHeight), excelize.FitToHeight(2)},
		{new(excelize.FitToWidth), excelize.FitToWidth(2)},
	}

	for i, test := range testData {
		t.Run(fmt.Sprintf("TestData%d", i), func(t *testing.T) {

			opt := test.nonDefault
			t.Logf("option %T", opt)

			def := deepcopy.Copy(test.container).(excelize.PageLayoutOptionPtr)
			val1 := deepcopy.Copy(def).(excelize.PageLayoutOptionPtr)
			val2 := deepcopy.Copy(def).(excelize.PageLayoutOptionPtr)

			f := excelize.NewFile()
			// Get the default value
			assert.NoError(t, f.GetPageLayout(sheet, def), opt)
			// Get again and check
			assert.NoError(t, f.GetPageLayout(sheet, val1), opt)
			if !assert.Equal(t, val1, def, opt) {
				t.FailNow()
			}
			// Set the same value
			assert.NoError(t, f.SetPageLayout(sheet, val1), opt)
			// Get again and check
			assert.NoError(t, f.GetPageLayout(sheet, val1), opt)
			if !assert.Equal(t, val1, def, "%T: value should not have changed", opt) {
{'fraction_non_alphanumeric': 0.15196368659956583, 'fraction_numerical': 0.009867771857114663, 'mean_word_length': 4.2086330935251794, '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': '1944837', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1870, 'n_words': 364}