<commit_before>package template

import (
	"bytes"
	"os"
	"testing"
)

type templateTest struct {
	template string
	context  Context
	out      string
}

type testStruct struct {
	a int
	b float64
}

var templateTests = []templateTest{
	templateTest{"hello", nil, "hello"},
	templateTest{"hello{", nil, "hello{"},
	templateTest{"hello{i", nil, "hello{i"},
	//templateTest{"{# it's a comment #}", nil, ""},
	templateTest{"{{ 1 }}", nil, "1"},
	templateTest{"{{ 3.14 }}", nil, "3.14"},
	templateTest{"{{ 'hello' }}", nil, "hello"},
	templateTest{"{{ \"hello\" }}", nil, "hello"},
	templateTest{"{{ 1 }} {{ 2 }}", nil, "1 2"},
	templateTest{"{{ var }}", Context{"var": "hello"}, "hello"},
	templateTest{" {{ var }}", Context{"var": []int{1, 2, 3}}, " [1, 2, 3]"},
	templateTest{"{{ var }}", Context{"var": map[int]string{1: "one", 2: "two", 3: "three"}}, "{1: 'one', 2: 'two', 3: 'three'}"},
	templateTest{"{{ var.1 }}", Context{"var": "hello"}, "e"},
	templateTest{"{{ var.0 }}", Context{"var": []int{14}}, "14"},
	templateTest{"{{ var.13 }}", Context{"var": [14]int{13: 11}}, "11"},
	templateTest{"{{ var.test }}", Context{"var": map[string]string{"test": "hello"}}, "hello"},
	templateTest{"{{ var.42 }}", Context{"var": map[int]int{42: 67}}, "67"},
	templateTest{"{{ var.42 }}", Context{"var": map[int16]int16{42: 67}}, "67"},
	templateTest{"{{ var.a }}", Context{"var": testStruct{4, 3.14}}, "4"},
	templateTest{"{{ var.b }}", Context{"var": &testStruct{4, 3.14}}, "3.14"},
}

func testTemplates(t *testing.T, templates []templateTest) {
	for i, test := range templates {
		temp, err := Parse(test.template)
		if err != nil {
			t.Errorf("#%d failed to parse: %s", i, err.String())<commit_msg>Correct test with inconsistent behavior<commit_after>package template

import (
	"bytes"
	"os"
	"testing"
)

type templateTest struct {
	template string
	context  Context
	out      string
}

type testStruct struct {
	a int
	b float64
}

var templateTests = []templateTest{
	templateTest{"hello", nil, "hello"},
	templateTest{"hello{", nil, "hello{"},
	templateTest{"hello{i", nil, "hello{i"},
	//templateTest{"{# it's a comment #}", nil, ""},
	templateTest{"{{ 1 }}", nil, "1"},
	templateTest{"{{ 3.14 }}", nil, "3.14"},
	templateTest{"{{ 'hello' }}", nil, "hello"},
	templateTest{"{{ \"hello\" }}", nil, "hello"},
	templateTest{"{{ 1 }} {{ 2 }}", nil, "1 2"},
	templateTest{"{{ var }}", Context{"var": "hello"}, "hello"},
	templateTest{" {{ var }}", Context{"var": []int{1, 2, 3}}, " [1, 2, 3]"},
	templateTest{"{{ var }}", Context{"var": map[int]string{1: "one"}}, "{1: 'one'}"},
	templateTest{"{{ var.1 }}", Context{"var": "hello"}, "e"},
	templateTest{"{{ var.0 }}", Context{"var": []int{14}}, "14"},
	templateTest{"{{ var.13 }}", Context{"var": [14]int{13: 11}}, "11"},
	templateTest{"{{ var.test }}", Context{"var": map[string]string{"test": "hello"}}, "hello"},
	templateTest{"{{ var.42 }}", Context{"var": map[int]int{42: 67}}, "67"},
	templateTest{"{{ var.42 }}", Context{"var": map[int16]int16{42: 67}}, "67"},
	templateTest{"{{ var.a }}", Context{"var": testStruct{4, 3.14}}, "4"},
	templateTest{"{{ var.b }}", Context{"var": &testStruct{4, 3.14}}, "3.14"},
}

func testTemplates(t *testing.T, templates []templateTest) {
	for i, test := range templates {
		temp, err := Parse(test.template)
		if err != nil {
			t.Errorf("#%d failed to parse: %s", i, err.String())
{'fraction_non_alphanumeric': 0.2712166172106825, 'fraction_numerical': 0.042729970326409496, 'mean_word_length': 5.470249520153551, 'pattern_counts': {'":': 24, '<': 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': '5476619', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1210, 'n_words': 313}