<commit_before>package observer

import (
	"errors"
	"testing"

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

func TestPipe(t *testing.T) {
	assert := assert.New(t)

	obs1 := New(0)
	obs2 := New(0)

	values := []int{}
	go func() {
		for v := range obs2.Out() {
			values = append(values, v.(int))
		}
	}()

	go func() {
		obs1.In() <- 1
		obs1.In() <- 2
		obs1.In() <- 3
		obs1.Close()
	}()

	<-Pipe(obs1, obs2)

	assert.Exactly([]int{1, 2, 3}, values)
}

func TestPipeError(t *testing.T) {
	assert := assert.New(t)

	obs1 := New(0)
	obs2 := New(0)
	err := errors.New("Not")

	values := []int{}
	go func() {
		for v := range obs2.Out() {
			switch v := v.(type) {
			case error:
				err = v
			default:
				values = append(values, v.(int))
			}
		}
	}()

	go func() {
		obs1.In() <- 1
		obs1.In() <- 2
		obs1.In() <- 3
		obs1.In() <- errors.New("Bang")
		obs1.Close()
	}()

	<-Pipe(obs1, obs2)

	assert.Exactly([]int{1, 2, 3}, values)
	assert.Exactly(errors.New("Bang"), err)
}

func TestPipeUnsubscribe(t *testing.T) {
	assert := assert.New(t)

	obs1 := New(0)
	obs2 := New(0)<commit_msg>fix pipe test<commit_after>package observer

import (
	"errors"
	"testing"

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

func TestPipe(t *testing.T) {
	assert := assert.New(t)

	obs1 := New(0)
	obs2 := New(0)

	values := []int{}
	go func() {
		for v := range obs2.Out() {
			values = append(values, v.(int))
		}
	}()

	go func() {
		obs1.In() <- 1
		obs1.In() <- 2
		obs1.In() <- 3
		obs1.Close()
	}()

	<-Pipe(obs1, obs2)

	assert.Exactly([]int{1, 2, 3}, values)
}

func TestPipeError(t *testing.T) {
	assert := assert.New(t)

	obs1 := New(0)
	obs2 := New(0)
	err := errors.New("Not")
	done := make(chan bool, 1)

	values := []int{}
	go func() {
		for v := range obs2.Out() {
			switch v := v.(type) {
			case error:
				err = v
			default:
				values = append(values, v.(int))
			}
		}
		done <- true
	}()

	go func() {
		obs1.In() <- 1
		obs1.In() <- 2
		obs1.In() <- 3
		obs1.In() <- errors.New("Bang")
		obs1.Close()
	}()

	<-Pipe(obs1, obs2)
	<-done

	assert.Exactly([]int{1, 2, 3}, values)
	assert.Exactly(errors.New("Bang"), err)
}

func TestPipeUnsubscribe(t *testing.T) {
	assert := assert.New(t)

	obs1 := New(0)
	obs2 := New(0)
{'fraction_non_alphanumeric': 0.21766561514195584, 'fraction_numerical': 0.035601622352410996, 'mean_word_length': 2.8947368421052633, 'pattern_counts': {'":': 0, '<': 23, '<?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': '7518847', 'n_tokens_mistral': 1099, 'n_tokens_neox': 971, 'n_words': 206}