<commit_before>package eventsource

import (
	"bytes"
	"testing"
)

var message []byte = []byte("{id: 1}")
var deflated = "eJyqzkyxUjCsBQQAAP//CfUCUQ=="

func TestEventBytesWithName(t *testing.T) {
	expecting := []byte("event: test\ndata: {id: 1}\n\n")
	e := Event{
		Name:    "test",
		Message: message,
	}
	result := e.bytes()
	if !bytes.Equal(expecting, result) {
		t.Errorf("expected:\n%s\ngot:\n%s\n", expecting, result)
	}
}

func TestEventBytesWithoutName(t *testing.T) {
	expecting := []byte("data: {id: 1}\n\n")<commit_msg>Add initial test for send method<commit_after>package eventsource

import (
	"bytes"
	"testing"
)

var message []byte = []byte("{id: 1}")
var deflated = "eJyqzkyxUjCsBQQAAP//CfUCUQ=="

func TestEventSendToClient(t *testing.T) {
	e := Event{Message: message}
	c := client{events: make(chan payload)}
	go e.send([]client{c})
	p := <-c.events

	expecting := e.bytes()
	result := p.data

	if !bytes.Equal(expecting, result) {
		t.Errorf("expected:\n%s\ngot:\n%s\n", expecting, result)
	}
}

func TestEventBytesWithName(t *testing.T) {
	expecting := []byte("event: test\ndata: {id: 1}\n\n")
	e := Event{
		Name:    "test",
		Message: message,
	}
	result := e.bytes()
	if !bytes.Equal(expecting, result) {
		t.Errorf("expected:\n%s\ngot:\n%s\n", expecting, result)
	}
}

func TestEventBytesWithoutName(t *testing.T) {
	expecting := []byte("data: {id: 1}\n\n")
{'fraction_non_alphanumeric': 0.1963898916967509, 'fraction_numerical': 0.004332129963898917, 'mean_word_length': 4.544, 'pattern_counts': {'":': 0, '<': 4, '<?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': '1621350', 'n_tokens_mistral': 586, 'n_tokens_neox': 563, 'n_words': 112}