<commit_before>package gophercloud

import (
	"bytes"
	"errors"
	"io"
	"net/http"
	"reflect"
	"testing"

	"github.com/mitchellh/mapstructure"
)

type nopCloser struct {
	io.Reader
}

func (nopCloser) Close() error { return nil }

func responseWithBody(body string) (http.Response, error) {
	return http.Response{
		Body: nopCloser{bytes.NewReader([]byte(body))},
	}, nil
}

// SinglePage sample and test cases.

type SingleIntList struct {
	SinglePage
}

func ExtractSingleInts(page Page) ([]int, error) {
	var response struct {
		Ints []int `mapstructure:"ints"`
	}

	err := mapstructure.Decode(page.(SingleIntList).Body, &response)
	if err != nil {
		return nil, err
	}

	return response.Ints, nil
}

func setupSinglePaged() Pager {
	return NewSinglePager(func() (http.Response, error) {
		return responseWithBody(`{ "ints": [1, 2, 3] }`)
	})
}

func TestEnumerateSinglePaged(t *testing.T) {
	callCount := 0
	err := setupSinglePaged().EachPage(func(page Page) bool {
		callCount++

		expected := []int{1, 2, 3}
		actual, err := ExtractSingleInts(page)
		if err != nil {
			t.Fatalf("Unexpected error extracting ints: %v", err)
		}
		if !reflect.DeepEqual(expected, actual) {
			t.Errorf("Expected %v, but was %v", expected, actual)
		}
		return true
	})
	if err != nil {
		t.Fatalf("Unexpected error calling EachPage: %v", err)
	}

	if callCount != 1 {
		t.Errorf("Callback was invoked %d times", callCount)
	}
}

// LinkedPager sample and test cases.

type LinkedIntPage struct {
	PaginatedLinksPage
}

func ExtractLinkedInts(page Page) ([]int, error) {
	var response struct {
		Ints []int `mapstructure:"ints"`
	}

	err := mapstructure.Decode(page.(LinkedIntPage).Body, &response)
	if err != nil {
		return nil, err<commit_msg>This passes, but I still want result types...<commit_after>package gophercloud

import (
	"bytes"
	"errors"
	"io"
	"net/http"
	"reflect"
	"testing"

	"github.com/mitchellh/mapstructure"
)

type nopCloser struct {
	io.Reader
}

func (nopCloser) Close() error { return nil }

func responseWithBody(body string) (http.Response, error) {
	return http.Response{
		Body: nopCloser{bytes.NewReader([]byte(body))},
	}, nil
}

// SinglePage sample and test cases.

func ExtractSingleInts(page Page) ([]int, error) {
	var response struct {
		Ints []int `mapstructure:"ints"`
	}

	err := mapstructure.Decode(page.(SinglePage).Body, &response)
	if err != nil {
		return nil, err
	}

	return response.Ints, nil
}

func setupSinglePaged() Pager {
	return NewSinglePager(func() (http.Response, error) {
		return responseWithBody(`{ "ints": [1, 2, 3] }`)
	})
}

func TestEnumerateSinglePaged(t *testing.T) {
	callCount := 0
	err := setupSinglePaged().EachPage(func(page Page) bool {
		callCount++

		expected := []int{1, 2, 3}
		actual, err := ExtractSingleInts(page)
		if err != nil {
			t.Fatalf("Unexpected error extracting ints: %v", err)
		}
		if !reflect.DeepEqual(expected, actual) {
			t.Errorf("Expected %v, but was %v", expected, actual)
		}
		return true
	})
	if err != nil {
		t.Fatalf("Unexpected error calling EachPage: %v", err)
	}

	if callCount != 1 {
		t.Errorf("Callback was invoked %d times", callCount)
	}
}

// LinkedPager sample and test cases.

func ExtractLinkedInts(page Page) ([]int, error) {
	var response struct {
		Ints []int `mapstructure:"ints"`
	}

	err := mapstructure.Decode(page.(PaginatedLinksPage).Body, &response)
	if err != nil {
		return nil, err
{'fraction_non_alphanumeric': 0.14462081128747795, 'fraction_numerical': 0.004703115814226925, 'mean_word_length': 4.227342549923195, 'pattern_counts': {'":': 2, '<': 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': '5679335', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1199, 'n_words': 318}