<commit_before>package rw

import (
	"bytes"
	"io"
	"runtime"
	"strings"
	"testing"
)

func TestNewLineWriter(t *testing.T) {
	cases := [...]struct {
		s string
		w string
		u string
	}{
		{"dd\n", "dd\r\n", "dd\n"},
		{"", "", ""},
		{"\r\ni", "\r\ni", "\ni"},
		{"\ndd\n", "\r\ndd\r\n", "\ndd\n"},
		{"\n", "\r\n", "\n"},
		{"\r", "\r", "\r"},
		{"a\r\n", "a\r\n", "a\n"},
	}
	for i, cas := range cases {
		var buf bytes.Buffer
		wr := NewLineWriter(&buf)
		n, err := io.Copy(wr, strings.NewReader(cas.s))
		if err != nil {
			t.Errorf("want err=nil; got %v (i=%d)", err, i)
			continue
		}
		var w string
		if runtime.GOOS == "windows" {
			w = cas.w
		} else {
			w = cas.u
		}
		if got := buf.String(); got != w {
			t.Errorf("want got=%q; got %q (i=%d)", w, got, i)
			continue
		}
		if want := len(cas.s); int(n) != want {
			t.Errorf("want n=%d; got %d (i=%d)", want, n, i)
		}
	}
}<commit_msg>newLineWriter: Run always windows & unix tests.<commit_after>package rw

import (
	"bytes"
	"io"
	"strings"
	"testing"
)

func TestNewLineWriterWindows(t *testing.T) {
	cases := [...]struct {
		s string
		r string
	}{
		{"dd\n", "dd\r\n"},
		{"", ""},
		{"\r\ni", "\r\ni"},
		{"\ndd\n", "\r\ndd\r\n"},
		{"\n", "\r\n"},
		{"\r", "\r"},
		{"a\r\n", "a\r\n"},
	}
	for i, cas := range cases {
		var buf bytes.Buffer
		wr := &newLineWriter{&buf, winNewLine}
		n, err := io.Copy(wr, strings.NewReader(cas.s))
		if err != nil {
			t.Errorf("want err=nil; got %v (i=%d)", err, i)
			continue
		}
		if got := buf.String(); got != cas.r {
			t.Errorf("want got=%q; got %q (i=%d)", cas.r, got, i)
			continue
		}
		if want := len(cas.s); int(n) != want {
			t.Errorf("want n=%d; got %d (i=%d)", want, n, i)
		}
	}
}

func TestNewLineWriterUnix(t *testing.T) {
	cases := [...]struct {
		s string
		r string
	}{
		{"dd\n", "dd\n"},
		{"", ""},
		{"\r\ni", "\ni"},
		{"\ndd\n", "\ndd\n"},
		{"\n", "\n"},
		{"\r", "\r"},
		{"a\r\n", "a\n"},
	}
	for i, cas := range cases {
		var buf bytes.Buffer
		wr := &newLineWriter{&buf, unixNewLine}
		n, err := io.Copy(wr, strings.NewReader(cas.s))
		if err != nil {
			t.Errorf("want err=nil; got %v (i=%d)", err, i)
			continue
		}
		if got := buf.String(); got != cas.r {
			t.Errorf("want got=%q; got %q (i=%d)", cas.r, got, i)
			continue
		}
		if want := len(cas.s); int(n) != want {
			t.Errorf("want n=%d; got %d (i=%d)", want, n, i)
		}
	}
}
{'fraction_non_alphanumeric': 0.2695542472666106, 'fraction_numerical': 0.0, 'mean_word_length': 2.6265243902439024, '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': '2525786', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1078, 'n_words': 260}