oh-my-posh/src/properties_test.go

113 lines
3.2 KiB
Go
Raw Normal View History

2019-03-13 04:14:30 -07:00
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
const (
expected = "expected"
expectedColor = "#768954"
)
2019-03-13 04:14:30 -07:00
func TestGetString(t *testing.T) {
2022-01-01 11:08:08 -08:00
var properties properties = properties{TextProperty: expected}
2019-03-13 04:14:30 -07:00
value := properties.getString(TextProperty, "err")
assert.Equal(t, expected, value)
2019-03-13 04:14:30 -07:00
}
func TestGetStringNoEntry(t *testing.T) {
2022-01-01 11:08:08 -08:00
var properties properties = properties{}
2019-03-13 04:14:30 -07:00
value := properties.getString(TextProperty, expected)
assert.Equal(t, expected, value)
2019-03-13 04:14:30 -07:00
}
func TestGetStringNoTextEntry(t *testing.T) {
2022-01-01 11:08:08 -08:00
var properties properties = properties{TextProperty: true}
2019-03-13 04:14:30 -07:00
value := properties.getString(TextProperty, expected)
assert.Equal(t, expected, value)
2019-03-13 04:14:30 -07:00
}
func TestGetHexColor(t *testing.T) {
expected := expectedColor
2022-01-01 11:08:08 -08:00
var properties properties = properties{UserColor: expected}
2019-03-13 04:14:30 -07:00
value := properties.getColor(UserColor, "#789123")
assert.Equal(t, expected, value)
}
func TestGetColor(t *testing.T) {
expected := "yellow"
2022-01-01 11:08:08 -08:00
var properties properties = properties{UserColor: expected}
value := properties.getColor(UserColor, "#789123")
assert.Equal(t, expected, value)
2019-03-13 04:14:30 -07:00
}
func TestDefaultColorWithInvalidColorCode(t *testing.T) {
expected := expectedColor
2022-01-01 11:08:08 -08:00
var properties properties = properties{UserColor: "invalid"}
2019-03-13 04:14:30 -07:00
value := properties.getColor(UserColor, expected)
assert.Equal(t, expected, value)
2019-03-13 04:14:30 -07:00
}
func TestDefaultColorWithUnavailableProperty(t *testing.T) {
expected := expectedColor
2022-01-01 11:08:08 -08:00
var properties properties = properties{}
2019-03-13 04:14:30 -07:00
value := properties.getColor(UserColor, expected)
assert.Equal(t, expected, value)
2019-03-13 04:14:30 -07:00
}
func TestGetPaletteColor(t *testing.T) {
expected := "p:red"
2022-01-01 11:08:08 -08:00
var properties properties = properties{Background: expected}
value := properties.getColor(Background, "white")
assert.Equal(t, expected, value)
}
2019-03-13 04:14:30 -07:00
func TestGetBool(t *testing.T) {
expected := true
2022-01-01 11:08:08 -08:00
var properties properties = properties{DisplayHost: expected}
value := properties.getBool(DisplayHost, false)
2019-03-13 04:14:30 -07:00
assert.True(t, value)
}
func TestGetBoolPropertyNotInMap(t *testing.T) {
2022-01-01 11:08:08 -08:00
var properties properties = properties{}
value := properties.getBool(DisplayHost, false)
2019-03-13 04:14:30 -07:00
assert.False(t, value)
}
func TestGetBoolInvalidProperty(t *testing.T) {
2022-01-01 11:08:08 -08:00
var properties properties = properties{DisplayHost: "borked"}
value := properties.getBool(DisplayHost, false)
2019-03-13 04:14:30 -07:00
assert.False(t, value)
}
2020-12-06 13:03:40 -08:00
func TestGetFloat64(t *testing.T) {
expected := float64(1337)
2022-01-01 11:08:08 -08:00
var properties properties = properties{"myfloat": expected}
2020-12-06 13:03:40 -08:00
value := properties.getFloat64("myfloat", 9001)
assert.Equal(t, expected, value)
}
func TestGetFloat64PropertyNotInMap(t *testing.T) {
expected := float64(1337)
2022-01-01 11:08:08 -08:00
var properties properties = properties{}
2020-12-06 13:03:40 -08:00
value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value)
}
func TestGetFloat64InvalidStringProperty(t *testing.T) {
expected := float64(1337)
2022-01-01 11:08:08 -08:00
var properties properties = properties{ThresholdProperty: "invalid"}
2020-12-06 13:03:40 -08:00
value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value)
}
func TestGetFloat64InvalidBoolProperty(t *testing.T) {
expected := float64(1337)
2022-01-01 11:08:08 -08:00
var properties properties = properties{ThresholdProperty: true}
2020-12-06 13:03:40 -08:00
value := properties.getFloat64(ThresholdProperty, expected)
assert.Equal(t, expected, value)
}