2020-11-14 11:04:04 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-01-10 03:14:43 -08:00
|
|
|
universion = "1.3.307"
|
2020-11-14 11:04:04 -08:00
|
|
|
uni = "*.uni"
|
|
|
|
corn = "*.corn"
|
|
|
|
)
|
|
|
|
|
|
|
|
type languageArgs struct {
|
2020-12-27 23:33:58 -08:00
|
|
|
version string
|
|
|
|
extensions []string
|
|
|
|
enabledExtensions []string
|
2021-02-03 10:11:32 -08:00
|
|
|
commands []*cmd
|
2020-12-27 23:33:58 -08:00
|
|
|
enabledCommands []string
|
2021-02-03 10:11:32 -08:00
|
|
|
versionURLTemplate string
|
|
|
|
expectedError error
|
2021-02-06 22:06:24 -08:00
|
|
|
properties map[Property]interface{}
|
|
|
|
matchesVersionFile matchesVersionFile
|
2021-03-22 11:19:08 -07:00
|
|
|
inHome bool
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *languageArgs) hasvalue(value string, list []string) bool {
|
|
|
|
for _, element := range list {
|
|
|
|
if element == value {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func bootStrapLanguageTest(args *languageArgs) *language {
|
|
|
|
env := new(MockedEnvironment)
|
|
|
|
for _, command := range args.commands {
|
2021-02-03 10:11:32 -08:00
|
|
|
env.On("hasCommand", command.executable).Return(args.hasvalue(command.executable, args.enabledCommands))
|
|
|
|
env.On("runCommand", command.executable, command.args).Return(args.version, args.expectedError)
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
for _, extension := range args.extensions {
|
|
|
|
env.On("hasFiles", extension).Return(args.hasvalue(extension, args.enabledExtensions))
|
|
|
|
}
|
2021-03-22 11:19:08 -07:00
|
|
|
home := "/usr/home"
|
|
|
|
cwd := "/usr/home/project"
|
|
|
|
if args.inHome {
|
|
|
|
cwd = home
|
|
|
|
}
|
|
|
|
env.On("getcwd", nil).Return(cwd)
|
|
|
|
env.On("homeDir", nil).Return(home)
|
2020-11-14 11:04:04 -08:00
|
|
|
l := &language{
|
2021-11-26 01:37:33 -08:00
|
|
|
props: args.properties,
|
2021-02-03 10:11:32 -08:00
|
|
|
env: env,
|
|
|
|
extensions: args.extensions,
|
|
|
|
commands: args.commands,
|
|
|
|
versionURLTemplate: args.versionURLTemplate,
|
2021-02-06 22:06:24 -08:00
|
|
|
matchesVersionFile: args.matchesVersionFile,
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
return l
|
|
|
|
}
|
|
|
|
|
2020-12-27 23:33:58 -08:00
|
|
|
func TestLanguageFilesFoundButNoCommandAndVersionAndDisplayVersion(t *testing.T) {
|
2020-11-14 11:04:04 -08:00
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
},
|
|
|
|
},
|
2020-11-14 11:04:04 -08:00
|
|
|
extensions: []string{uni},
|
|
|
|
enabledExtensions: []string{uni},
|
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
2021-01-14 23:08:56 -08:00
|
|
|
assert.True(t, lang.enabled())
|
2021-02-06 09:13:20 -08:00
|
|
|
assert.Equal(t, "", lang.string(), "unicorn is not available")
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
|
2020-12-27 23:33:58 -08:00
|
|
|
func TestLanguageFilesFoundButNoCommandAndVersionAndDontDisplayVersion(t *testing.T) {
|
2021-02-06 22:06:24 -08:00
|
|
|
props := map[Property]interface{}{
|
2021-12-04 04:06:05 -08:00
|
|
|
FetchVersion: false,
|
2021-02-06 22:06:24 -08:00
|
|
|
}
|
2020-12-27 23:33:58 -08:00
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
},
|
|
|
|
},
|
2020-12-27 23:33:58 -08:00
|
|
|
extensions: []string{uni},
|
|
|
|
enabledExtensions: []string{uni},
|
2021-02-06 22:06:24 -08:00
|
|
|
properties: props,
|
2020-12-27 23:33:58 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled(), "unicorn is not available")
|
|
|
|
}
|
|
|
|
|
2020-12-21 11:16:33 -08:00
|
|
|
func TestLanguageFilesFoundButNoCommandAndNoVersion(t *testing.T) {
|
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
},
|
|
|
|
},
|
2020-12-21 11:16:33 -08:00
|
|
|
extensions: []string{uni},
|
|
|
|
enabledExtensions: []string{uni},
|
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled(), "unicorn is not available")
|
|
|
|
}
|
|
|
|
|
2020-11-14 11:04:04 -08:00
|
|
|
func TestLanguageDisabledNoFiles(t *testing.T) {
|
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extensions: []string{uni},
|
|
|
|
enabledExtensions: []string{},
|
|
|
|
enabledCommands: []string{"unicorn"},
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.False(t, lang.enabled(), "no files in the current directory")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguageEnabledOneExtensionFound(t *testing.T) {
|
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: "(?P<version>.*)",
|
|
|
|
},
|
|
|
|
},
|
2020-11-14 11:04:04 -08:00
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{uni},
|
2021-02-03 10:11:32 -08:00
|
|
|
enabledCommands: []string{"unicorn"},
|
2020-11-14 11:04:04 -08:00
|
|
|
version: universion,
|
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, universion, lang.string(), "unicorn is available and uni files are found")
|
|
|
|
}
|
|
|
|
|
2021-03-22 11:19:08 -07:00
|
|
|
func TestLanguageDisabledInHome(t *testing.T) {
|
|
|
|
args := &languageArgs{
|
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: "(?P<version>.*)",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{uni},
|
|
|
|
enabledCommands: []string{"unicorn"},
|
|
|
|
version: universion,
|
|
|
|
inHome: true,
|
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.False(t, lang.enabled())
|
|
|
|
}
|
|
|
|
|
2020-11-14 11:04:04 -08:00
|
|
|
func TestLanguageEnabledSecondExtensionFound(t *testing.T) {
|
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: "(?P<version>.*)",
|
|
|
|
},
|
|
|
|
},
|
2020-11-14 11:04:04 -08:00
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{corn},
|
2021-02-03 10:11:32 -08:00
|
|
|
enabledCommands: []string{"unicorn"},
|
|
|
|
version: universion,
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, universion, lang.string(), "unicorn is available and corn files are found")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguageEnabledSecondCommand(t *testing.T) {
|
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "uni",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: "(?P<version>.*)",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
executable: "corn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: "(?P<version>.*)",
|
|
|
|
},
|
|
|
|
},
|
2020-11-14 11:04:04 -08:00
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{corn},
|
2021-02-03 10:11:32 -08:00
|
|
|
enabledCommands: []string{"corn"},
|
|
|
|
version: universion,
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, universion, lang.string(), "unicorn is available and corn files are found")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguageEnabledAllExtensionsFound(t *testing.T) {
|
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: "(?P<version>.*)",
|
|
|
|
},
|
|
|
|
},
|
2020-11-14 11:04:04 -08:00
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{uni, corn},
|
2021-02-03 10:11:32 -08:00
|
|
|
enabledCommands: []string{"unicorn"},
|
|
|
|
version: universion,
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, universion, lang.string(), "unicorn is available and uni and corn files are found")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguageEnabledNoVersion(t *testing.T) {
|
2021-02-06 22:06:24 -08:00
|
|
|
props := map[Property]interface{}{
|
2021-12-04 04:06:05 -08:00
|
|
|
FetchVersion: false,
|
2021-02-06 22:06:24 -08:00
|
|
|
}
|
2020-11-14 11:04:04 -08:00
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "unicorn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: "(?P<version>.*)",
|
|
|
|
},
|
|
|
|
},
|
2020-11-14 11:04:04 -08:00
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{uni, corn},
|
2021-02-03 10:11:32 -08:00
|
|
|
enabledCommands: []string{"unicorn"},
|
|
|
|
version: universion,
|
2021-02-06 22:06:24 -08:00
|
|
|
properties: props,
|
2020-11-14 11:04:04 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, "", lang.string(), "unicorn is available and uni and corn files are found")
|
|
|
|
}
|
2020-12-27 23:33:58 -08:00
|
|
|
|
|
|
|
func TestLanguageEnabledMissingCommand(t *testing.T) {
|
2021-02-06 22:06:24 -08:00
|
|
|
props := map[Property]interface{}{
|
2021-12-04 04:06:05 -08:00
|
|
|
FetchVersion: false,
|
2021-02-06 22:06:24 -08:00
|
|
|
}
|
2020-12-27 23:33:58 -08:00
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{},
|
2020-12-27 23:33:58 -08:00
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{uni, corn},
|
2021-02-03 10:11:32 -08:00
|
|
|
enabledCommands: []string{"unicorn"},
|
|
|
|
version: universion,
|
2021-02-06 22:06:24 -08:00
|
|
|
properties: props,
|
2020-12-27 23:33:58 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, "", lang.string(), "unicorn is available and uni and corn files are found")
|
|
|
|
}
|
|
|
|
|
2021-02-16 04:45:51 -08:00
|
|
|
func TestLanguageEnabledNoVersionData(t *testing.T) {
|
|
|
|
props := map[Property]interface{}{
|
2021-12-04 04:06:05 -08:00
|
|
|
FetchVersion: true,
|
2021-02-16 04:45:51 -08:00
|
|
|
}
|
|
|
|
args := &languageArgs{
|
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "uni",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?:Python (?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+))))`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{uni, corn},
|
|
|
|
enabledCommands: []string{"uni"},
|
|
|
|
version: "",
|
|
|
|
properties: props,
|
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, "", lang.string())
|
|
|
|
}
|
|
|
|
|
2020-12-27 23:33:58 -08:00
|
|
|
func TestLanguageEnabledMissingCommandCustomText(t *testing.T) {
|
2021-02-06 22:06:24 -08:00
|
|
|
expected := "missing"
|
|
|
|
props := map[Property]interface{}{
|
|
|
|
MissingCommandText: expected,
|
|
|
|
}
|
2020-12-27 23:33:58 -08:00
|
|
|
args := &languageArgs{
|
2021-02-06 22:06:24 -08:00
|
|
|
commands: []*cmd{},
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{uni, corn},
|
|
|
|
enabledCommands: []string{"unicorn"},
|
|
|
|
version: universion,
|
|
|
|
properties: props,
|
2020-12-27 23:33:58 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
2021-02-06 22:06:24 -08:00
|
|
|
assert.Equal(t, expected, lang.string(), "unicorn is available and uni and corn files are found")
|
2020-12-27 23:33:58 -08:00
|
|
|
}
|
2021-01-10 03:14:43 -08:00
|
|
|
|
2021-02-14 03:45:06 -08:00
|
|
|
func TestLanguageEnabledMissingCommandCustomTextHideError(t *testing.T) {
|
|
|
|
props := map[Property]interface{}{
|
|
|
|
MissingCommandText: "missing",
|
|
|
|
DisplayError: false,
|
|
|
|
}
|
|
|
|
args := &languageArgs{
|
|
|
|
commands: []*cmd{},
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{uni, corn},
|
|
|
|
enabledCommands: []string{"unicorn"},
|
|
|
|
version: universion,
|
|
|
|
properties: props,
|
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, "", lang.string())
|
|
|
|
}
|
|
|
|
|
2021-02-03 10:11:32 -08:00
|
|
|
func TestLanguageEnabledCommandExitCode(t *testing.T) {
|
|
|
|
expected := 200
|
2021-01-10 03:14:43 -08:00
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "uni",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
|
|
|
},
|
|
|
|
},
|
2021-01-10 03:14:43 -08:00
|
|
|
extensions: []string{uni, corn},
|
2021-02-03 10:11:32 -08:00
|
|
|
enabledExtensions: []string{uni, corn},
|
|
|
|
enabledCommands: []string{"uni"},
|
2021-01-10 03:14:43 -08:00
|
|
|
version: universion,
|
2021-02-03 10:11:32 -08:00
|
|
|
expectedError: &commandError{exitCode: expected},
|
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, "err executing uni with [--version]", lang.string())
|
|
|
|
assert.Equal(t, expected, lang.exitCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguageHyperlinkEnabled(t *testing.T) {
|
2021-02-06 22:06:24 -08:00
|
|
|
props := map[Property]interface{}{
|
|
|
|
EnableHyperlink: true,
|
|
|
|
}
|
2021-02-03 10:11:32 -08:00
|
|
|
args := &languageArgs{
|
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "uni",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
executable: "corn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
versionURLTemplate: "[%s](https://unicor.org/doc/%s.%s.%s)",
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{corn},
|
|
|
|
enabledCommands: []string{"corn"},
|
|
|
|
version: universion,
|
2021-02-06 22:06:24 -08:00
|
|
|
properties: props,
|
2021-01-10 03:14:43 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, "[1.3.307](https://unicor.org/doc/1.3.307)", lang.string())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
|
2021-02-06 22:06:24 -08:00
|
|
|
props := map[Property]interface{}{
|
|
|
|
EnableHyperlink: true,
|
|
|
|
}
|
2021-01-10 03:14:43 -08:00
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "uni",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `wrong`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
executable: "corn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `wrong`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
versionURLTemplate: "[%s](https://unicor.org/doc/%s.%s.%s)",
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{corn},
|
|
|
|
enabledCommands: []string{"corn"},
|
|
|
|
version: universion,
|
2021-02-06 22:06:24 -08:00
|
|
|
properties: props,
|
2021-01-10 03:14:43 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
2021-02-03 10:11:32 -08:00
|
|
|
assert.Equal(t, "err parsing info from corn with 1.3.307", lang.string())
|
2021-01-10 03:14:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) {
|
2021-02-06 22:06:24 -08:00
|
|
|
props := map[Property]interface{}{
|
|
|
|
EnableHyperlink: true,
|
|
|
|
}
|
2021-01-10 03:14:43 -08:00
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "uni",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
executable: "corn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
versionURLTemplate: "[%s](https://unicor.org/doc/%s)",
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{corn},
|
|
|
|
enabledCommands: []string{"corn"},
|
|
|
|
version: universion,
|
2021-02-06 22:06:24 -08:00
|
|
|
properties: props,
|
2021-01-10 03:14:43 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, "[1.3.307](https://unicor.org/doc/1)", lang.string())
|
|
|
|
}
|
|
|
|
|
2021-04-17 04:28:06 -07:00
|
|
|
func TestLanguageEnabledInHome(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Case string
|
2021-07-31 07:54:25 -07:00
|
|
|
HomeEnabled bool
|
2021-04-17 04:28:06 -07:00
|
|
|
ExpectedEnabled bool
|
|
|
|
}{
|
2021-07-31 07:54:25 -07:00
|
|
|
{Case: "Always enabled", HomeEnabled: true, ExpectedEnabled: true},
|
|
|
|
{Case: "Context disabled", HomeEnabled: false, ExpectedEnabled: false},
|
2021-04-17 04:28:06 -07:00
|
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
|
|
props := map[Property]interface{}{
|
2021-07-31 07:54:25 -07:00
|
|
|
HomeEnabled: tc.HomeEnabled,
|
2021-04-17 04:28:06 -07:00
|
|
|
}
|
|
|
|
args := &languageArgs{
|
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "uni",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{corn},
|
|
|
|
enabledCommands: []string{"corn"},
|
|
|
|
version: universion,
|
|
|
|
properties: props,
|
|
|
|
inHome: true,
|
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.Equal(t, tc.ExpectedEnabled, lang.enabled(), tc.Case)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-10 03:14:43 -08:00
|
|
|
func TestLanguageHyperlinkEnabledMoreParamInTemplate(t *testing.T) {
|
2021-02-06 22:06:24 -08:00
|
|
|
props := map[Property]interface{}{
|
|
|
|
EnableHyperlink: true,
|
|
|
|
}
|
2021-01-10 03:14:43 -08:00
|
|
|
args := &languageArgs{
|
2021-02-03 10:11:32 -08:00
|
|
|
commands: []*cmd{
|
|
|
|
{
|
|
|
|
executable: "uni",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
executable: "corn",
|
|
|
|
args: []string{"--version"},
|
|
|
|
regex: `(?P<version>((?P<major>[0-9]+).(?P<minor>[0-9]+).(?P<patch>[0-9]+)))`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
versionURLTemplate: "[%s](https://unicor.org/doc/%s.%s.%s.%s)",
|
|
|
|
extensions: []string{uni, corn},
|
|
|
|
enabledExtensions: []string{corn},
|
|
|
|
enabledCommands: []string{"corn"},
|
|
|
|
version: universion,
|
2021-02-06 22:06:24 -08:00
|
|
|
properties: props,
|
2021-01-10 03:14:43 -08:00
|
|
|
}
|
|
|
|
lang := bootStrapLanguageTest(args)
|
|
|
|
assert.True(t, lang.enabled())
|
|
|
|
assert.Equal(t, "1.3.307", lang.string())
|
|
|
|
}
|