File: file_test.go

package info (click to toggle)
golang-github-dave-jennifer 1.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: makefile: 4
file content (51 lines) | stat: -rw-r--r-- 1,160 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package jen

import (
	"fmt"
	"testing"
)

func TestGuessAlias(t *testing.T) {

	data := map[string]string{
		"A":             "a",
		"a":             "a",
		"a$":            "a",
		"a/b":           "b",
		"a/b/c":         "c",
		"a/b/c-d":       "cd",
		"a/b/c-d/":      "cd",
		"a.b":           "ab",
		"a/b.c":         "bc",
		"a/b-c.d":       "bcd",
		"a/bb-ccc.dddd": "bbcccdddd",
		"a/foo-go":      "foogo",
		"123a":          "a",
		"a/321a.b":      "ab",
		"a/123":         "pkg",
	}
	for path, expected := range data {
		if guessAlias(path) != expected {
			fmt.Printf("guessAlias test failed %s should return %s but got %s\n", path, expected, guessAlias(path))
			t.Fail()
		}
	}
}

func TestValidAlias(t *testing.T) {
	data := map[string]bool{
		"a":   true,  // ok
		"b":   false, // already registered
		"go":  false, // keyword
		"int": false, // predeclared
		"err": false, // common name
	}
	f := NewFile("test")
	f.register("b")
	for alias, expected := range data {
		if f.isValidAlias(alias) != expected {
			fmt.Printf("isValidAlias test failed %s should return %t but got %t\n", alias, expected, f.isValidAlias(alias))
			t.Fail()
		}
	}
}