<commit_before>package cask

import (
	"testing"

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

func createTokenTestParser() *Parser {
	// preparations
	p := &Parser{
		lexer: NewLexer("five = 5"),
	}

	p.nextToken()
	p.nextToken()

	return p
}

func TestNewParser(t *testing.T) {
	// preparations
	l := NewLexer("cask 'example' do\nend\n")
	p := NewParser(l)

	// test
	assert.IsType(t, Parser{}, *p)
	assert.Equal(t, l, p.lexer)
	assert.Len(t, p.errors, 0)
}

func TestParseVersion(t *testing.T) {
	// test (successful)
	testCases := map[string]string{
		`version "1.0.0"`: "1.0.0",
		"version '1.0.0'": "1.0.0",
		"version :latest": "latest",
	}

	for testCase, expected := range testCases {
		// preparations
		l := NewLexer(testCase)
		p := NewParser(l)

		// test
		actual, err := p.parseVersion()
		assert.Nil(t, err)
		assert.Equal(t, expected, actual)
	}

	// test (error)
	testCasesErrors := map[string]string{
		"invalid":       "Parse version: not found",
		"version 1.0.0": "Parse version: not found",
	}

	for testCase, expected := range testCasesErrors {
		// preparations
		l := NewLexer(testCase)
		p := NewParser(l)

		// test
		actual, err := p.parseVersion()
		assert.Empty(t, actual)
		assert.Error(t, err)
		assert.Equal(t, expected, err.Error())
	}
}

func TestParseAppcast(t *testing.T) {
	// test (successful)
	testCases := map[string]Appcast{
		`appcast "https://example.com/appcast.xml"`: Appcast{
			URL:        "https://example.com/appcast.xml",
			Checkpoint: "",
		},
		"appcast 'https://example.com/appcast.xml'": Appcast{
			URL:        "https://example.com/appcast.xml",
			Checkpoint: "",
		},
		"appcast 'https://example.com/appcast.xml', checkpoint: '2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1'": Appcast{
			URL:        "https://example.com/appcast.xml",
			Checkpoint: "2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1",
		},
		`appcast 'https://example.com/appcast.xml',
            checkpoint: '2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1'
    `: Appcast{
			URL:        "https://example.com/appcast.xml",
			Checkpoint: "2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1",
		},
	}

	for testCase, expected := range testCases {
		// preparations
		l := NewLexer(testCase)
		p := NewParser(l)

		// test
		actual, err := p.parseAppcast()<commit_msg>Run "gofmt -s" on parser_test.go<commit_after>package cask

import (
	"testing"

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

func createTokenTestParser() *Parser {
	// preparations
	p := &Parser{
		lexer: NewLexer("five = 5"),
	}

	p.nextToken()
	p.nextToken()

	return p
}

func TestNewParser(t *testing.T) {
	// preparations
	l := NewLexer("cask 'example' do\nend\n")
	p := NewParser(l)

	// test
	assert.IsType(t, Parser{}, *p)
	assert.Equal(t, l, p.lexer)
	assert.Len(t, p.errors, 0)
}

func TestParseVersion(t *testing.T) {
	// test (successful)
	testCases := map[string]string{
		`version "1.0.0"`: "1.0.0",
		"version '1.0.0'": "1.0.0",
		"version :latest": "latest",
	}

	for testCase, expected := range testCases {
		// preparations
		l := NewLexer(testCase)
		p := NewParser(l)

		// test
		actual, err := p.parseVersion()
		assert.Nil(t, err)
		assert.Equal(t, expected, actual)
	}

	// test (error)
	testCasesErrors := map[string]string{
		"invalid":       "Parse version: not found",
		"version 1.0.0": "Parse version: not found",
	}

	for testCase, expected := range testCasesErrors {
		// preparations
		l := NewLexer(testCase)
		p := NewParser(l)

		// test
		actual, err := p.parseVersion()
		assert.Empty(t, actual)
		assert.Error(t, err)
		assert.Equal(t, expected, err.Error())
	}
}

func TestParseAppcast(t *testing.T) {
	// test (successful)
	testCases := map[string]Appcast{
		`appcast "https://example.com/appcast.xml"`: {
			URL:        "https://example.com/appcast.xml",
			Checkpoint: "",
		},
		"appcast 'https://example.com/appcast.xml'": {
			URL:        "https://example.com/appcast.xml",
			Checkpoint: "",
		},
		"appcast 'https://example.com/appcast.xml', checkpoint: '2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1'": {
			URL:        "https://example.com/appcast.xml",
			Checkpoint: "2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1",
		},
		`appcast 'https://example.com/appcast.xml',
            checkpoint: '2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1'
    `: {
			URL:        "https://example.com/appcast.xml",
			Checkpoint: "2ffedc4898df88e05a6e8f5519e11159d967153f75f8d4e8c9a0286d347ea1e1",
		},
	}

	for testCase, expected := range testCases {
		// preparations
		l := NewLexer(testCase)
		p := NewParser(l)

		// test
		actual, err := p.parseAppcast()
{'fraction_non_alphanumeric': 0.16358614828978119, 'fraction_numerical': 0.0769067346505205, 'mean_word_length': 3.6660059464816652, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 16, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, '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': '3460840', 'n_tokens_mistral': 2222, 'n_tokens_neox': 1931, 'n_words': 319}