<commit_before>// Copyright 2015 The Serulian Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package vcs

import (
	"fmt"
	"testing"
)

var _ = fmt.Printf

func TestVCSParsing(t *testing.T) {
	assertParses(t, "github.com/some/project", "github.com/some/project", "", "", "")
	assertParses(t, "github.com/some/project:somebranch", "github.com/some/project", "somebranch", "", "")
	assertParses(t, "github.com/some/project@sometag", "github.com/some/project", "", "sometag", "")
	assertParses(t, "github.com/some/project//somesubdir", "github.com/some/project", "", "", "somesubdir")
	assertParses(t, "github.com/some/project//somesubdir:somebranch", "github.com/some/project", "somebranch", "", "somesubdir")
	assertParses(t, "github.com/some/project//somesubdir@sometag", "github.com/some/project", "", "sometag", "somesubdir")

	assertParseError(t, "")
	assertParseError(t, "github.com/foo/bar@@blah")
	assertParseError(t, "github.com/foo/bar:@blah")
	assertParseError(t, "github.com/foo/../bar")
}

func assertParses(t *testing.T, path string, url string, branchOrCommit string, tag string, subpackage string) {
	result, err := parseVCSPath(path)
	if err != nil {
		t.Errorf("Expected no error, found: %v", err)
		return
	}

	if result.url != url {
		t.Errorf("Expected url %s, found: %s", url, result.url)
		return
	}

	if result.branchOrCommit != branchOrCommit {
		t.Errorf("Expected branchOrCommit %s, found: %s", branchOrCommit, result.branchOrCommit)
		return
	}

	if result.tag != tag {
		t.Errorf("Expected tag %s, found: %s", tag, result.tag)
		return
	}

	if result.subpackage != subpackage {
		t.Errorf("Expected subpackage %s, found: %s", subpackage, result.subpackage)
		return
	}
}

func assertParseError(t *testing.T, path string) {
	result, err := parseVCSPath(path)
	if err == nil {
		t.Errorf("Expected error, found: %v", result)
	}
}
<commit_msg>Change vcs path tests to be table-driven to ensure consistency<commit_after>// Copyright 2015 The Serulian Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package vcs

import (
	"fmt"
	"testing"
)

var _ = fmt.Printf

type pathSuccessTest struct {
	path           string
	url            string
	branchOrCommit string
	tag            string
	subpackage     string
}

var successTests = []pathSuccessTest{
	pathSuccessTest{"github.com/some/project", "github.com/some/project", "", "", ""},
	pathSuccessTest{"github.com/some/project:somebranch", "github.com/some/project", "somebranch", "", ""},
	pathSuccessTest{"github.com/some/project@sometag", "github.com/some/project", "", "sometag", ""},
	pathSuccessTest{"github.com/some/project//somesubdir", "github.com/some/project", "", "", "somesubdir"},
	pathSuccessTest{"github.com/some/project//somesubdir:somebranch", "github.com/some/project", "somebranch", "", "somesubdir"},
	pathSuccessTest{"github.com/some/project//somesubdir@sometag", "github.com/some/project", "", "sometag", "somesubdir"},
}

var failTests = []string{
	"",
	"github.com/foo/bar@@blah",
	"github.com/foo/bar:@blah",
	"github.com/foo/../bar",
}

func TestVCSParsingFailure(t *testing.T) {
	for _, test := range failTests {
		result, err := parseVCSPath(test)
		if err == nil {
			t.Errorf("Expected error, found: %v", result)
		}
	}
}

func TestVCSParsingSuccess(t *testing.T) {
	for _, test := range successTests {
		result, err := parseVCSPath(test.path)

		if err != nil {
			t.Errorf("Expected no error, found: %v", err)
			return
		}

		if result.url != test.url {
			t.Errorf("Expected url %s, found: %s", test.url, result.url)
			return
		}

		if result.branchOrCommit != test.branchOrCommit {
			t.Errorf("Expected branchOrCommit %s, found: %s", test.branchOrCommit, result.branchOrCommit)
			return
		}

		if result.tag != test.tag {
			t.Errorf("Expected tag %s, found: %s", test.tag, result.tag)
			return
		}

		if result.subpackage != test.subpackage {
			t.Errorf("Expected subpackage %s, found: %s", test.subpackage, result.subpackage)
			return
		}
	}
}

{'fraction_non_alphanumeric': 0.1640454875393177, 'fraction_numerical': 0.0019356399709654004, 'mean_word_length': 4.252858958068615, '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': '71622', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1446, 'n_words': 323}